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 2013/11/11 17:47:20 UTC

svn commit: r1540766 - in /commons/proper/collections/trunk: ./ src/changes/ src/main/java/org/apache/commons/collections4/collection/ src/site/xdoc/ src/test/java/org/apache/commons/collections4/collection/

Author: tn
Date: Mon Nov 11 16:47:20 2013
New Revision: 1540766

URL: http://svn.apache.org/r1540766
Log:
[COLLECTIONS-496] UnmodifiableBoundedCollection does now also implement the Unmodifiable marker interface.

Modified:
    commons/proper/collections/trunk/RELEASE-NOTES.txt
    commons/proper/collections/trunk/src/changes/changes.xml
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java
    commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java

Modified: commons/proper/collections/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/RELEASE-NOTES.txt?rev=1540766&r1=1540765&r2=1540766&view=diff
==============================================================================
--- commons/proper/collections/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/collections/trunk/RELEASE-NOTES.txt Mon Nov 11 16:47:20 2013
@@ -47,6 +47,8 @@ Major changes since 3.2.1
 Changes since 4.0-alpha1
 ------------------------
 
+ o [COLLECTIONS-496] "UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
+                     similar as all other unmodifiable decorators.
  o [COLLECTIONS-495] "UnmodifiableTrie#unmodifiableTrie(Trie)" will not decorate again an already unmodifiable Trie.
                      Also the return type has been changed to "Trie" to be consistent with other Unmodifiable decorators.
  o [COLLECTIONS-494] Moved "Equator" interface to base package for consistency. Thanks to Emmanuel Bourg.
@@ -161,6 +163,8 @@ New features
 Changed classes / methods
 -------------------------
 
+ o [COLLECTIONS-496] "UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
+                     similar as all other unmodifiable decorators.
  o [COLLECTIONS-495] "UnmodifiableTrie#unmodifiableTrie(Trie)" will not decorate again an already unmodifiable Trie.
                      Also the return type has been changed to "Trie" to be consistent with other Unmodifiable decorators.
  o [COLLECTIONS-494] Moved "Equator" interface to base package for consistency. Thanks to Emmanuel Bourg.

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1540766&r1=1540765&r2=1540766&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Mon Nov 11 16:47:20 2013
@@ -38,6 +38,10 @@ Commons Collections is Java 5.
 Users are encouraged to upgrade to this version as, in addition to new
 features, this release includes numerous bug fixes.
   ">
+    <action issue="COLLECTIONS-496" dev="tn" type="update">
+     "UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
+     similar as all other unmodifiable decorators.
+    </action>
     <action issue="COLLECTIONS-495" dev="tn" type="fix">
      "UnmodifiableTrie#unmodifiableTrie(Trie)" will not decorate again an already
      unmodifiable Trie. Also the return type has been changed to "Trie" to be consistent

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java?rev=1540766&r1=1540765&r2=1540766&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java Mon Nov 11 16:47:20 2013
@@ -20,6 +20,7 @@ import java.util.Collection;
 import java.util.Iterator;
 
 import org.apache.commons.collections4.BoundedCollection;
+import org.apache.commons.collections4.Unmodifiable;
 import org.apache.commons.collections4.iterators.UnmodifiableIterator;
 
 /**
@@ -40,7 +41,7 @@ import org.apache.commons.collections4.i
  * @version $Id$
  */
 public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDecorator<E>
-        implements BoundedCollection<E> {
+        implements BoundedCollection<E>, Unmodifiable {
 
     /** Serialization version */
     private static final long serialVersionUID = -7112672385450340330L;
@@ -55,6 +56,11 @@ public final class UnmodifiableBoundedCo
      * @since 4.0
      */
     public static <E> BoundedCollection<E> unmodifiableBoundedCollection(final BoundedCollection<? extends E> coll) {
+        if (coll instanceof Unmodifiable) {
+            @SuppressWarnings("unchecked") // safe to upcast
+            final BoundedCollection<E> tmpColl = (BoundedCollection<E>) coll;
+            return tmpColl;
+        }
         return new UnmodifiableBoundedCollection<E>(coll);
     }
 

Modified: commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml?rev=1540766&r1=1540765&r2=1540766&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml (original)
+++ commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml Mon Nov 11 16:47:20 2013
@@ -155,8 +155,10 @@ have changed.
 
 <center><h3>Changed classes / methods</h3></center>
 <ul>
+<li>"UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable"
+    similar as all other unmodifiable decorators.</li>
 <li>"UnmodifiableTrie#unmodifiableTrie(Trie)" will not decorate again an already unmodifiable Trie.
-     Also the return type has been changed to "Trie" to be consistent with other Unmodifiable decorators.</li>
+    Also the return type has been changed to "Trie" to be consistent with other Unmodifiable decorators.</li>
 <li>Moved "Equator" interface to base package for consistency.</li>
 <li>Accept wildcard input where possible, e.g. in copy-constructors, Unmodifiable* decorators and iterators.</li>
 <li>Narrow return type of "BidiMap#values()" to Set as the values are required to be unique.</li>

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java?rev=1540766&r1=1540765&r2=1540766&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java Mon Nov 11 16:47:20 2013
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import org.apache.commons.collections4.BoundedCollection;
+import org.apache.commons.collections4.Unmodifiable;
 import org.apache.commons.collections4.list.FixedSizeList;
 
 /**
@@ -43,7 +44,7 @@ public class UnmodifiableBoundedCollecti
     }
 
     @Override
-    public Collection<E> makeFullCollection() {
+    public BoundedCollection<E> makeFullCollection() {
         final E[] allElements = getFullElements();
         final BoundedCollection<E> coll = FixedSizeList.<E>fixedSizeList(new ArrayList<E>(Arrays.asList(allElements)));
         return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll);
@@ -80,4 +81,22 @@ public class UnmodifiableBoundedCollecti
     public String getCompatibilityVersion() {
         return "4";
     }
+    
+    //-----------------------------------------------------------------------
+
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullCollection() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final BoundedCollection<E> coll = makeFullCollection();
+        assertSame(coll, UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll));
+
+        try {
+            UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+    
 }