diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index a2b107616..756c88f6d 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -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. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d2cff28eb..b7e7130c3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -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. "> + + "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. + Moved "Equator" interface to base package for consistency. diff --git a/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java b/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java index 3d78550c7..feb47d639 100644 --- a/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java +++ b/src/main/java/org/apache/commons/collections4/trie/UnmodifiableTrie.java @@ -51,7 +51,12 @@ public class UnmodifiableTrie implements Trie, Serializable, Unmodif * @return a new unmodifiable trie * @throws IllegalArgumentException if trie is null */ - public static UnmodifiableTrie unmodifiableTrie(final Trie trie) { + public static Trie unmodifiableTrie(final Trie trie) { + if (trie instanceof Unmodifiable) { + @SuppressWarnings("unchecked") // safe to upcast + final Trie tmpTrie = (Trie) trie; + return tmpTrie; + } return new UnmodifiableTrie(trie); } diff --git a/src/site/xdoc/release_4_0.xml b/src/site/xdoc/release_4_0.xml index 5f4bc4fa9..60e8b82bd 100644 --- a/src/site/xdoc/release_4_0.xml +++ b/src/site/xdoc/release_4_0.xml @@ -155,6 +155,8 @@ have changed.

Changed classes / methods

    +
  • "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.
  • Moved "Equator" interface to base package for consistency.
  • Accept wildcard input where possible, e.g. in copy-constructors, Unmodifiable* decorators and iterators.
  • Narrow return type of "BidiMap#values()" to Set as the values are required to be unique.
  • diff --git a/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java b/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java index c473fd0f9..36badbef5 100644 --- a/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/TrieUtilsTest.java @@ -49,6 +49,8 @@ public class TrieUtilsTest extends BulkTest { } catch (final IllegalArgumentException ex) { // expected } + + assertSame("UnmodifiableTrie shall not be decorated", trie, TrieUtils.unmodifiableTrie(trie)); } } diff --git a/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java b/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java index 28dd8630a..e4eb48be0 100644 --- a/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java +++ b/src/test/java/org/apache/commons/collections4/trie/UnmodifiableTrieTest.java @@ -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 extends AbstractSortedMapTest { //------------------------------------------------------------------- @Override - public SortedMap makeObject() { - return UnmodifiableSortedMap.unmodifiableSortedMap(new PatriciaTrie()); + public Trie makeObject() { + return UnmodifiableTrie.unmodifiableTrie(new PatriciaTrie()); } @Override @@ -65,28 +63,31 @@ public class UnmodifiableTrieTest extends AbstractSortedMapTest { } @Override - public SortedMap makeFullMap() { - final SortedMap m = new PatriciaTrie(); + public Trie makeFullMap() { + final Trie m = new PatriciaTrie(); 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 map = makeFullMap(); - assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map)); + final Trie 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";