[COLLECTIONS-495] Fix UnmodifiableTrie.unmodifiableTrie, add tests.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1540763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15ee56bd0f
commit
72784c46f6
|
@ -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.
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -51,7 +51,12 @@ public class UnmodifiableTrie<K, V> implements Trie<K, V>, Serializable, Unmodif
|
|||
* @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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -49,6 +49,8 @@ public class TrieUtilsTest extends BulkTest {
|
|||
} catch (final IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
assertSame("UnmodifiableTrie shall not be decorated", trie, TrieUtils.unmodifiableTrie(trie));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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> extends AbstractSortedMapTest<String, V> {
|
|||
//-------------------------------------------------------------------
|
||||
|
||||
@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> extends AbstractSortedMapTest<String, V> {
|
|||
}
|
||||
|
||||
@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";
|
||||
|
|
Loading…
Reference in New Issue