[utilities COMMIT] in /java-support/trunk: doc/RELEASE-NOTES.txt src/main/java/net/shibboleth/utilities/java/support/...

noreply at shibboleth.net noreply at shibboleth.net
Tue Aug 20 21:27:40 EDT 2013


Author: putmanb
Date: Tue Aug 20 21:27:40 2013
New Revision: 427

URL: http://svn.shibboleth.net/view/utilities?rev=427&view=rev
Log:
JSPT-26: ClassToInstanceMultiMap should ideally support remove() ops rather than being append-only.

Modified:
    java-support/trunk/doc/RELEASE-NOTES.txt
    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/doc/RELEASE-NOTES.txt
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/doc/RELEASE-NOTES.txt?rev=427&r1=426&r2=427&view=diff
==============================================================================
--- java-support/trunk/doc/RELEASE-NOTES.txt (original)
+++ java-support/trunk/doc/RELEASE-NOTES.txt Tue Aug 20 21:27:40 2013
@@ -4,5 +4,6 @@
 [JSPT-16] - Add a ServletListener that configures logback with a specified configuration file
 [JSPT-23] - SerializeSupport prettyPrintXML has reverted impl to diverge from writeNode and nodeToString
 [JSPT-24] - Type4UuidIdentifier and RandomIdentifier generation strategies do not generate a valid XML ID
+[JSPT-26] - ClassToInstanceMultiMap should ideally support remove() ops rather than being append-only.
 [JSPT-27] - ClassToInstanceMultiMap get() returns duplicate values
 [JSPT-29] - ClassToInstanceMultiMap contains duplicates in value list on multiple insertions of same value

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=427&r1=426&r2=427&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 Tue Aug 20 21:27:40 2013
@@ -208,6 +208,64 @@
             put(value);
         }
     }
+    
+    /**
+     * Remove the specified value from the map and from the value list of all indexes.
+     * 
+     * <p>
+     * If the value list for a type index becomes empty due to the value removal, the entire type 
+     * index will be removed and {@link #containsKey(Class)} for that type will then return <code>false</code>.
+     * </p>
+     * 
+     * @param value the value to remove
+     */
+    public void remove(final B value) {
+        if (value == null) {
+            return;
+        }
+        
+        values.remove(value);
+        
+        List<B> indexValues;
+        for (Class<?> indexKey : getIndexTypes(value)) {
+            indexValues = backingMap.get(indexKey);
+            if (indexValues != null) {
+                indexValues.remove(value);
+                if (indexValues.isEmpty()) {
+                    backingMap.remove(indexKey);
+                }
+            }
+        }
+    }
+    
+    /**
+     * Remove from the map all values which have the specified type.
+     * 
+     * <p>
+     * Note that when a value was indexed by multiple superclass and/or interface types,
+     * it will be removed from all those type indexes, not just the specified one.  
+     * </p>
+     * 
+     * <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 type the type of values to remove
+     */
+    public void remove(final Class<?> type) {
+        if (type == null) {
+            return;
+        }
+        
+        List<B> indexValues = backingMap.remove(type);
+        
+        if (indexValues != null) {
+            for (B value : indexValues) {
+                remove(value);
+            }
+        }
+    }
 
     /**
      * The collection of values currently present in the map. This collection is backed by the map so changeds to the

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=427&r1=426&r2=427&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 Tue Aug 20 21:27:40 2013
@@ -146,7 +146,108 @@
         Assert.assertEquals(map.get(AbstractFooBar.class).size(), 1);
         Assert.assertEquals(map.get(FooBarImpl.class).size(), 1);
     }
-
+    
+    @Test public void testRemoveValue() {

[... 104 lines stripped ...]


More information about the commits mailing list