From a4d444d9de192ddcb1e37922c5f213760ff3a24e Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 9 Sep 2013 20:10:39 +0000 Subject: [PATCH] [COLLECTIONS-480] Narrow return type of BidiMap.values to Set. Thanks to Hollis Waite. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1521272 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE-NOTES.txt | 2 ++ src/changes/changes.xml | 3 +++ .../apache/commons/collections4/BidiMap.java | 17 +++++++++++++++++ .../bidimap/AbstractBidiMapDecorator.java | 6 ++++++ .../bidimap/AbstractDualBidiMap.java | 4 ++-- .../collections4/bidimap/TreeBidiMap.java | 5 ++--- .../bidimap/UnmodifiableBidiMap.java | 8 +++----- .../bidimap/UnmodifiableOrderedBidiMap.java | 8 +++----- .../bidimap/UnmodifiableSortedBidiMap.java | 8 +++----- src/site/xdoc/release_4_0.xml | 1 + 10 files changed, 42 insertions(+), 20 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 1e79dfcfc..289ca392a 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -49,6 +49,7 @@ Changes since 4.0-alpha1 - [COLLECTIONS-481] No collision detection/resolution was performed when calling "CompositeSet#addComposited(...)" with more than one Set as argument. Also changed the the method with an array argument to use a varargs parameter. Thanks to Hollis Waite. + - [COLLECTIONS-480] Narrow return type of "BidiMap#values()" to Set as the values are required to be unique. Thanks to Hollis Waite. - [COLLECTIONS-468] Renamed CompliantBag to CollectionBag. - [COLLECTIONS-475] Fixed conversion of timeout parameters in "PassiveExpiringMap". @@ -150,6 +151,7 @@ New features Changed classes / methods ------------------------- + o [COLLECTIONS-480] Narrow return type of "BidiMap#values()" to Set as the values are required to be unique. Thanks to Hollis Waite. o [COLLECTIONS-473] Made field "collection" in class "AbstractCollectionDecorator" private and added setter "setCollection(Collection)" with scope protected to set the decorated collection during de-serialization. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 53fe36878..3b8ece296 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -27,6 +27,9 @@ with more than one Set as argument. Also changed the the method with an array argument to use a varargs parameter. + + Narrow return type of "BidiMap#values()" to Set as the values are required to be unique. + Fixed conversion of timeout parameters in "PassiveExpiringMap". diff --git a/src/main/java/org/apache/commons/collections4/BidiMap.java b/src/main/java/org/apache/commons/collections4/BidiMap.java index 889207008..e0aea2169 100644 --- a/src/main/java/org/apache/commons/collections4/BidiMap.java +++ b/src/main/java/org/apache/commons/collections4/BidiMap.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4; +import java.util.Set; + /** * Defines a map that allows bidirectional lookup between key and values. *

@@ -124,4 +126,19 @@ public interface BidiMap extends IterableMap { */ BidiMap inverseBidiMap(); + /** + * Returns a {@link Set} view of the values contained in this map. + * The set is backed by the map, so changes to the map are reflected + * in the set, and vice-versa. If the map is modified while an iteration + * over the set is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. + * The set supports element removal, which removes the corresponding + * mapping from the map, via the Iterator.remove, + * Collection.remove, removeAll, + * retainAll and clear operations. It does not + * support the add or addAll operations. + * + * @return a set view of the values contained in this map + */ + Set values(); } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/AbstractBidiMapDecorator.java b/src/main/java/org/apache/commons/collections4/bidimap/AbstractBidiMapDecorator.java index 60ceed945..5b0b50a3f 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/AbstractBidiMapDecorator.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/AbstractBidiMapDecorator.java @@ -16,6 +16,8 @@ */ package org.apache.commons.collections4.bidimap; +import java.util.Set; + import org.apache.commons.collections4.BidiMap; import org.apache.commons.collections4.MapIterator; import org.apache.commons.collections4.map.AbstractMapDecorator; @@ -76,4 +78,8 @@ public abstract class AbstractBidiMapDecorator return decorated().inverseBidiMap(); } + public Set values() { + return decorated().values(); + } + } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java index 193604e0e..3a8c3fbac 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java @@ -64,7 +64,7 @@ public abstract class AbstractDualBidiMap implements BidiMap { /** * View of the values. */ - transient Collection values = null; + transient Set values = null; /** * View of the entries. @@ -272,7 +272,7 @@ public abstract class AbstractDualBidiMap implements BidiMap { * * @return the values view */ - public Collection values() { + public Set values() { if (values == null) { values = new Values(this); } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java index fefca506c..28380555a 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java @@ -21,7 +21,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.AbstractSet; -import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; @@ -391,7 +390,7 @@ public class TreeBidiMap, V extends Comparable> * * @return a set view of the values contained in this map. */ - public Collection values() { + public Set values() { if (valuesSet == null) { valuesSet = new ValueView(KEY); } @@ -2128,7 +2127,7 @@ public class TreeBidiMap, V extends Comparable> return inverseKeySet; } - public Collection values() { + public Set values() { if (inverseValuesSet == null) { inverseValuesSet = new KeyView(VALUE); } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMap.java index e7855783a..ff3a92f31 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMap.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.bidimap; -import java.util.Collection; import java.util.Map; import java.util.Set; @@ -24,7 +23,6 @@ import org.apache.commons.collections4.set.UnmodifiableSet; import org.apache.commons.collections4.BidiMap; import org.apache.commons.collections4.MapIterator; import org.apache.commons.collections4.Unmodifiable; -import org.apache.commons.collections4.collection.UnmodifiableCollection; import org.apache.commons.collections4.iterators.UnmodifiableMapIterator; import org.apache.commons.collections4.map.UnmodifiableEntrySet; @@ -106,9 +104,9 @@ public final class UnmodifiableBidiMap } @Override - public Collection values() { - final Collection coll = super.values(); - return UnmodifiableCollection.unmodifiableCollection(coll); + public Set values() { + final Set set = super.values(); + return UnmodifiableSet.unmodifiableSet(set); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMap.java index 64e92fd8f..38c430847 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMap.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.bidimap; -import java.util.Collection; import java.util.Map; import java.util.Set; @@ -24,7 +23,6 @@ import org.apache.commons.collections4.set.UnmodifiableSet; import org.apache.commons.collections4.OrderedBidiMap; import org.apache.commons.collections4.OrderedMapIterator; import org.apache.commons.collections4.Unmodifiable; -import org.apache.commons.collections4.collection.UnmodifiableCollection; import org.apache.commons.collections4.iterators.UnmodifiableOrderedMapIterator; import org.apache.commons.collections4.map.UnmodifiableEntrySet; @@ -106,9 +104,9 @@ public final class UnmodifiableOrderedBidiMap } @Override - public Collection values() { - final Collection coll = super.values(); - return UnmodifiableCollection.unmodifiableCollection(coll); + public Set values() { + final Set set = super.values(); + return UnmodifiableSet.unmodifiableSet(set); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMap.java index 9d0353c96..6bcf35b7a 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMap.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.bidimap; -import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -25,7 +24,6 @@ import org.apache.commons.collections4.set.UnmodifiableSet; import org.apache.commons.collections4.OrderedMapIterator; import org.apache.commons.collections4.SortedBidiMap; import org.apache.commons.collections4.Unmodifiable; -import org.apache.commons.collections4.collection.UnmodifiableCollection; import org.apache.commons.collections4.iterators.UnmodifiableOrderedMapIterator; import org.apache.commons.collections4.map.UnmodifiableEntrySet; import org.apache.commons.collections4.map.UnmodifiableSortedMap; @@ -108,9 +106,9 @@ public final class UnmodifiableSortedBidiMap } @Override - public Collection values() { - final Collection coll = super.values(); - return UnmodifiableCollection.unmodifiableCollection(coll); + public Set values() { + final Set set = super.values(); + return UnmodifiableSet.unmodifiableSet(set); } //----------------------------------------------------------------------- diff --git a/src/site/xdoc/release_4_0.xml b/src/site/xdoc/release_4_0.xml index 618dbec1b..993ecd024 100644 --- a/src/site/xdoc/release_4_0.xml +++ b/src/site/xdoc/release_4_0.xml @@ -151,6 +151,7 @@ This release is not source or binary compatible with v3.x.

Changed classes / methods