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:30:14 UTC

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

Author: tn
Date: Mon Nov 11 16:30:14 2013
New Revision: 1540763

URL: http://svn.apache.org/r1540763
Log:
[COLLECTIONS-495] Fix UnmodifiableTrie.unmodifiableTrie, add tests.

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/trie/UnmodifiableTrie.java
    commons/proper/collections/trunk/src/site/xdoc/release_4_0.xml
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java

Modified: commons/proper/collections/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/RELEASE-NOTES.txt?rev=1540763&r1=1540762&r2=1540763&view=diff
==============================================================================
--- commons/proper/collections/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/collections/trunk/RELEASE-NOTES.txt Mon Nov 11 16:30:14 2013
@@ -47,6 +47,8 @@ Major changes since 3.2.1
 Changes since 4.0-alpha1
 ------------------------
 
+ 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.
  o [COLLECTIONS-488] Added "CollectionsUtils#matchesAll(Iterable, Predicate)" to test if all elements
                      of a collection match a given predicate. Thanks to Josh Cain.
@@ -159,6 +161,8 @@ New features
 Changed classes / methods
 -------------------------
 
+ 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.
  o [COLLECTIONS-485] Accept wildcard input where possible, e.g. in copy-constructors, Unmodifiable* decorators
                      and iterators. Thanks to Hollis Waite.

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1540763&r1=1540762&r2=1540763&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Mon Nov 11 16:30:14 2013
@@ -38,6 +38,11 @@ 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-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
+     with other Unmodifiable decorators.
+    </action>
     <action issue="COLLECTIONS-494" dev="tn" type="update" due-to="Emmanuel Bourg">
      Moved "Equator" interface to base package for consistency.
     </action>

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java?rev=1540763&r1=1540762&r2=1540763&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java Mon Nov 11 16:30:14 2013
@@ -51,7 +51,12 @@ public class UnmodifiableTrie<K, V> impl
      * @return a new unmodifiable trie
      * @throws IllegalArgumentException if trie is null
      */
-    public static <K, V> UnmodifiableTrie<K, V> unmodifiableTrie(final Trie<K, ? extends V> trie) {
+    public static <K, V> Trie<K, V> unmodifiableTrie(final Trie<K, ? extends V> trie) {
+        if (trie instanceof Unmodifiable) {
+            @SuppressWarnings("unchecked") // safe to upcast
+            final Trie<K, V> tmpTrie = (Trie<K, V>) trie;
+            return tmpTrie;
+        }
         return new UnmodifiableTrie<K, V>(trie);
     }
 

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=1540763&r1=1540762&r2=1540763&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:30:14 2013
@@ -155,6 +155,8 @@ have changed.
 
 <center><h3>Changed classes / methods</h3></center>
 <ul>
+<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>
 <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/TrieUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java?rev=1540763&r1=1540762&r2=1540763&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java Mon Nov 11 16:30:14 2013
@@ -49,6 +49,8 @@ public class TrieUtilsTest extends BulkT
         } catch (final IllegalArgumentException ex) {
             // expected
         }
+        
+        assertSame("UnmodifiableTrie shall not be decorated", trie, TrieUtils.unmodifiableTrie(trie));
     }
 
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java?rev=1540763&r1=1540762&r2=1540763&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java Mon Nov 11 16:30:14 2013
@@ -16,14 +16,12 @@
  */
 package org.apache.commons.collections4.trie;
 
-import java.util.SortedMap;
-
 import junit.framework.Test;
 
 import org.apache.commons.collections4.BulkTest;
+import org.apache.commons.collections4.Trie;
 import org.apache.commons.collections4.Unmodifiable;
 import org.apache.commons.collections4.map.AbstractSortedMapTest;
-import org.apache.commons.collections4.map.UnmodifiableSortedMap;
 
 /**
  * Extension of {@link AbstractSortedMapTest} for exercising the
@@ -45,8 +43,8 @@ public class UnmodifiableTrieTest<V> ext
     //-------------------------------------------------------------------
 
     @Override
-    public SortedMap<String, V> makeObject() {
-        return UnmodifiableSortedMap.unmodifiableSortedMap(new PatriciaTrie<V>());
+    public Trie<String, V> makeObject() {
+        return UnmodifiableTrie.unmodifiableTrie(new PatriciaTrie<V>());
     }
 
     @Override
@@ -65,28 +63,31 @@ public class UnmodifiableTrieTest<V> ext
     }
 
     @Override
-    public SortedMap<String, V> makeFullMap() {
-        final SortedMap<String, V> m = new PatriciaTrie<V>();
+    public Trie<String, V> makeFullMap() {
+        final Trie<String, V> m = new PatriciaTrie<V>();
         addSampleMappings(m);
-        return UnmodifiableSortedMap.unmodifiableSortedMap(m);
+        return UnmodifiableTrie.unmodifiableTrie(m);
     }
 
     //-----------------------------------------------------------------------
+
     public void testUnmodifiable() {
         assertTrue(makeObject() instanceof Unmodifiable);
         assertTrue(makeFullMap() instanceof Unmodifiable);
     }
 
     public void testDecorateFactory() {
-        final SortedMap<String, V> map = makeFullMap();
-        assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map));
+        final Trie<String, V> trie = makeFullMap();
+        assertSame(trie, UnmodifiableTrie.unmodifiableTrie(trie));
 
         try {
-            UnmodifiableSortedMap.unmodifiableSortedMap(null);
+            UnmodifiableTrie.unmodifiableTrie(null);
             fail();
         } catch (final IllegalArgumentException ex) {}
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";