From 539be680cd2b1a8f6833b28ee0cca22a88161466 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 11 Nov 2013 16:47:20 +0000 Subject: [PATCH] [COLLECTIONS-496] UnmodifiableBoundedCollection does now also implement the Unmodifiable marker interface. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1540766 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE-NOTES.txt | 4 ++++ src/changes/changes.xml | 4 ++++ .../UnmodifiableBoundedCollection.java | 8 ++++++- src/site/xdoc/release_4_0.xml | 4 +++- .../UnmodifiableBoundedCollectionTest.java | 21 ++++++++++++++++++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 756c88f6d..4524f7e86 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-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. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b7e7130c3..aa90ff0b7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -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. "> + + "UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable" + similar as all other unmodifiable decorators. + "UnmodifiableTrie#unmodifiableTrie(Trie)" will not decorate again an already unmodifiable Trie. Also the return type has been changed to "Trie" to be consistent diff --git a/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java b/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java index 5a9a9a508..52e5b8138 100644 --- a/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java @@ -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.iterators.UnmodifiableIterator; * @version $Id$ */ public final class UnmodifiableBoundedCollection extends AbstractCollectionDecorator - implements BoundedCollection { + implements BoundedCollection, Unmodifiable { /** Serialization version */ private static final long serialVersionUID = -7112672385450340330L; @@ -55,6 +56,11 @@ public final class UnmodifiableBoundedCollection extends AbstractCollectionDe * @since 4.0 */ public static BoundedCollection unmodifiableBoundedCollection(final BoundedCollection coll) { + if (coll instanceof Unmodifiable) { + @SuppressWarnings("unchecked") // safe to upcast + final BoundedCollection tmpColl = (BoundedCollection) coll; + return tmpColl; + } return new UnmodifiableBoundedCollection(coll); } diff --git a/src/site/xdoc/release_4_0.xml b/src/site/xdoc/release_4_0.xml index 60e8b82bd..4246f61ba 100644 --- a/src/site/xdoc/release_4_0.xml +++ b/src/site/xdoc/release_4_0.xml @@ -155,8 +155,10 @@ have changed.

Changed classes / methods

    +
  • "UnmodifiableBoundedCollection" does now also implement the marker interface "Unmodifiable" + similar as all other unmodifiable decorators.
  • "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.
  • + 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/collection/UnmodifiableBoundedCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java index 90fe17367..483534dc6 100644 --- a/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollectionTest.java @@ -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 UnmodifiableBoundedCollectionTest extends AbstractCollectionTest } @Override - public Collection makeFullCollection() { + public BoundedCollection makeFullCollection() { final E[] allElements = getFullElements(); final BoundedCollection coll = FixedSizeList.fixedSizeList(new ArrayList(Arrays.asList(allElements))); return UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll); @@ -80,4 +81,22 @@ public class UnmodifiableBoundedCollectionTest extends AbstractCollectionTest public String getCompatibilityVersion() { return "4"; } + + //----------------------------------------------------------------------- + + public void testUnmodifiable() { + assertTrue(makeObject() instanceof Unmodifiable); + assertTrue(makeFullCollection() instanceof Unmodifiable); + } + + public void testDecorateFactory() { + final BoundedCollection coll = makeFullCollection(); + assertSame(coll, UnmodifiableBoundedCollection.unmodifiableBoundedCollection(coll)); + + try { + UnmodifiableBoundedCollection.unmodifiableBoundedCollection(null); + fail(); + } catch (final IllegalArgumentException ex) {} + } + }