You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/04/09 20:40:36 UTC

svn commit: r1311366 - in /commons/proper/collections/trunk/src: main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java

Author: tn
Date: Mon Apr  9 18:40:36 2012
New Revision: 1311366

URL: http://svn.apache.org/viewvc?rev=1311366&view=rev
Log:
[COLLECTIONS-380] Fixed infinte recursion when creating an unmodifiable bounded collection, added unit test, fixed additional javadoc, thanks to Dave Brosius for reporting.

Added:
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java   (with props)
Modified:
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java?rev=1311366&r1=1311365&r2=1311366&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java Mon Apr  9 18:40:36 2012
@@ -52,10 +52,10 @@ public final class UnmodifiableBoundedCo
      *
      * @param coll  the <code>BoundedCollection</code> 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 <E> BoundedCollection<E> unmodifiableBoundedCollection(BoundedCollection<E> coll) {
-        return unmodifiableBoundedCollection(coll);
+        return new UnmodifiableBoundedCollection<E>(coll);
     }
 
     /**
@@ -66,7 +66,7 @@ public final class UnmodifiableBoundedCo
      *
      * @param coll  the <code>BoundedCollection</code> 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 <E> BoundedCollection<E> unmodifiableBoundedCollection(Collection<? extends E> coll) {
@@ -139,10 +139,16 @@ public final class UnmodifiableBoundedCo
     }
 
     //-----------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
     public boolean isFull() {
         return decorated().isFull();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public int maxSize() {
         return decorated().maxSize();
     }

Added: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java?rev=1311366&view=auto
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java (added)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java Mon Apr  9 18:40:36 2012
@@ -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<E> extends AbstractTestCollection<E> {
+
+    public TestUnmodifiableBoundedCollection(String testName) {
+        super(testName);
+    }
+
+    //-----------------------------------------------------------------------
+    @Override
+    public Collection<E> makeObject() {
+        BoundedBuffer<E> buffer = BoundedBuffer.<E>boundedBuffer(new ArrayStack<E>(), 10);
+        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+    }
+
+    @Override
+    public Collection<E> makeFullCollection() {
+        E[] allElements = getFullElements();
+        Buffer<E> buffer = BufferUtils.boundedBuffer(new ArrayStack<E>(), allElements.length);
+        buffer.addAll(Arrays.asList(allElements));
+        return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(buffer);
+    }
+
+    @Override
+    public Collection<E> makeConfirmedCollection() {
+        return new ArrayList<E>();
+    }
+
+    @Override
+    public Collection<E> makeConfirmedFullCollection() {
+        ArrayList<E> list = new ArrayList<E>();
+        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";
+    }
+}

Propchange: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL

Propchange: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/collection/TestUnmodifiableBoundedCollection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain