From 970921c2196d804d7c2d8203881cd340a4d0df3e Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 9 Apr 2012 18:40:36 +0000 Subject: [PATCH] [COLLECTIONS-380] Fixed infinte recursion when creating an unmodifiable bounded collection, added unit test, fixed additional javadoc, thanks to Dave Brosius for reporting. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1311366 13f79535-47bb-0310-9956-ffa450edef68 --- .../UnmodifiableBoundedCollection.java | 12 ++- .../TestUnmodifiableBoundedCollection.java | 85 +++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java diff --git a/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java b/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java index 63502336a..0f3c27cf4 100644 --- a/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java +++ b/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java @@ -52,10 +52,10 @@ public final class UnmodifiableBoundedCollection extends AbstractCollectionDe * * @param coll the BoundedCollection to decorate, must not be null * @return a new unmodifiable bounded collection - * @throws IllegalArgumentException if bag is null + * @throws IllegalArgumentException if {@code coll} is {@code null} */ public static BoundedCollection unmodifiableBoundedCollection(BoundedCollection coll) { - return unmodifiableBoundedCollection(coll); + return new UnmodifiableBoundedCollection(coll); } /** @@ -66,7 +66,7 @@ public final class UnmodifiableBoundedCollection extends AbstractCollectionDe * * @param coll the BoundedCollection to decorate, must not be null * @return a new unmodifiable bounded collection - * @throws IllegalArgumentException if bag is null + * @throws IllegalArgumentException if {@code coll} is {@code null} */ @SuppressWarnings("unchecked") public static BoundedCollection unmodifiableBoundedCollection(Collection coll) { @@ -139,10 +139,16 @@ public final class UnmodifiableBoundedCollection extends AbstractCollectionDe } //----------------------------------------------------------------------- + /** + * {@inheritDoc} + */ public boolean isFull() { return decorated().isFull(); } + /** + * {@inheritDoc} + */ public int maxSize() { return decorated().maxSize(); } diff --git a/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java b/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java new file mode 100644 index 000000000..262203f0d --- /dev/null +++ b/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.collections.collection; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.apache.commons.collections.ArrayStack; +import org.apache.commons.collections.Buffer; +import org.apache.commons.collections.BufferUtils; +import org.apache.commons.collections.buffer.BoundedBuffer; + +/** + * Extension of {@link AbstractTestCollection} for exercising the + * {@link UnmodifiableBoundedCollection} implementation. + */ +public class TestUnmodifiableBoundedCollection extends AbstractTestCollection { + + public TestUnmodifiableBoundedCollection(String testName) { + super(testName); + } + + //----------------------------------------------------------------------- + @Override + public Collection makeObject() { + BoundedBuffer buffer = BoundedBuffer.boundedBuffer(new ArrayStack(), 10); + return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer); + } + + @Override + public Collection makeFullCollection() { + E[] allElements = getFullElements(); + Buffer buffer = BufferUtils.boundedBuffer(new ArrayStack(), allElements.length); + buffer.addAll(Arrays.asList(allElements)); + return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer); + } + + @Override + public Collection makeConfirmedCollection() { + return new ArrayList(); + } + + @Override + public Collection makeConfirmedFullCollection() { + ArrayList list = new ArrayList(); + list.addAll(Arrays.asList(getFullElements())); + return list; + } + + @Override + public boolean isAddSupported() { + return false; + } + + @Override + public boolean isRemoveSupported() { + return false; + } + + @Override + protected boolean skipSerializedCanonicalTests() { + return true; + } + + @Override + public String getCompatibilityVersion() { + return "3.1"; + } +}