[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/collection/ClassToInst...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Aug 21 19:12:49 EDT 2013
Author: putmanb
Date: Wed Aug 21 19:12:49 2013
New Revision: 428
URL: http://svn.shibboleth.net/view/utilities?rev=428&view=rev
Log:
Finish JSPT-26: ClassToInstanceMultiMap should ideally support remove() ops rather than being append-only.
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMapTest.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java?rev=428&r1=427&r2=428&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java Wed Aug 21 19:12:49 2013
@@ -195,18 +195,16 @@
* regardless of the given map's policy on indexing by value supertypes, this map will index values based on its
* policy.
*
- * @param newValues values to be added
+ * @param map map containing values to be added
*
* @see ClassToInstanceMultiMap#put(Object)
*/
- public void putAll(final ClassToInstanceMultiMap<? extends B> newValues) {
- if (newValues == null) {
- return;
- }
-
- for (B value : newValues.values()) {
- put(value);
- }
+ public void putAll(final ClassToInstanceMultiMap<? extends B> map) {
+ if (map == null) {
+ return;
+ }
+
+ putAll(map.values);
}
/**
@@ -239,6 +237,44 @@
}
/**
+ * Remove the specified values from the map and from the value list of all indexes.
+ *
+ * <p>
+ * If the value list for a type index becomes empty due to a value removal, the entire type
+ * index will be removed and {@link #containsKey(Class)} for that type will then return <code>false</code>.
+ * </p>
+ *
+ * @param removeValues the values to remove
+ */
+ public void removeAll(final Iterable<? extends B> removeValues) {
+ if (removeValues == null) {
+ return;
+ }
+
+ for (B value : removeValues) {
+ remove(value);
+ }
+ }
+
+ /**
+ * Remove the values contained in the specified map from this map and from the value list of all indexes.
+ *
+ * <p>
+ * If the value list for a type index becomes empty due to a value removal, the entire type
+ * index will be removed and {@link #containsKey(Class)} for that type will then return <code>false</code>.
+ * </p>
+ *
+ * @param map the map containing the values to remove
+ */
+ public void removeAll(final ClassToInstanceMultiMap<? extends B> map) {
+ if (values == null) {
+ return;
+ }
+
+ removeAll(map.values);
+ }
+
+ /**
* Remove from the map all values which have the specified type.
*
* <p>
Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMapTest.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMapTest.java?rev=428&r1=427&r2=428&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMapTest.java (original)
+++ java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMapTest.java Wed Aug 21 19:12:49 2013
@@ -18,6 +18,7 @@
package net.shibboleth.utilities.java.support.collection;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.List;
import org.joda.time.Chronology;
@@ -248,6 +249,51 @@
}
+ @Test public void testRemoveAll() {
+ ClassToInstanceMultiMap<Object> map = new ClassToInstanceMultiMap<Object>(true);
+
+ FooImpl f1 = new FooImpl();
+ FooImpl f2 = new FooImpl();
+ FooImpl f3 = new FooImpl();
+
+ FooBarImpl fb1 = new FooBarImpl();
+ FooBarImpl fb2 = new FooBarImpl();
+ FooBarImpl fb3 = new FooBarImpl();
+
+ map.put(f1);
+ map.put(f2);
+ map.put(f3);
+ map.put(fb1);
+ map.put(fb2);
+ map.put(fb3);
+
+ Assert.assertEquals(map.values().size(), 6);
+ Assert.assertEquals(map.get(Foo.class).size(), 6);
+ Assert.assertEquals(map.get(Bar.class).size(), 3);
+
+ map.removeAll(Arrays.asList(f1,f2,fb1));
+
+ Assert.assertEquals(map.values().size(), 3);
[... 24 lines stripped ...]
More information about the commits
mailing list