[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 20:27:10 EDT 2013


Author: putmanb
Date: Tue Aug 20 20:27:09 2013
New Revision: 426

URL: http://svn.shibboleth.net/view/utilities?rev=426&view=rev
Log:
JSPT-29: ClassToInstanceMultiMap contains duplicates in value list on multiple insertions of same value.
Also refactor how supertype indexes are computed to prepare for remove() support.

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=426&r1=425&r2=426&view=diff
==============================================================================
--- java-support/trunk/doc/RELEASE-NOTES.txt (original)
+++ java-support/trunk/doc/RELEASE-NOTES.txt Tue Aug 20 20:27:09 2013
@@ -1,7 +1,8 @@
-Changes in Release 1.1.0
+Changes in Release 2.0.0
 ===============================
 [JSPT-3] - Providers helpers for dealing with idle connections in HttpClient
 [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-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=426&r1=425&r2=426&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 20:27:09 2013
@@ -158,23 +158,18 @@
             values.add(value);
         }
 
-        final HashSet<Class<?>> valueTypes = new HashSet<Class<?>>();
-        valueTypes.add(value.getClass());
-
-        if (indexSupertypes) {
-            getSuperTypes(value.getClass(), valueTypes);
-        }
-
         List<B> indexValues;
-        for (Class<?> valueType : valueTypes) {
-            indexValues = backingMap.get(valueType);
+        for (Class<?> indexKey : getIndexTypes(value)) {
+            indexValues = backingMap.get(indexKey);
 
             if (indexValues == null) {
                 indexValues = new ArrayList<B>();
-                backingMap.put(valueType, indexValues);
+                backingMap.put(indexKey, indexValues);
             }
 
-            indexValues.add(value);
+            if (!indexValues.contains(value)) {
+                indexValues.add(value);
+            }
         }
     }
 
@@ -223,6 +218,24 @@
      */
     public Collection<? extends B> values() {
         return Collections.unmodifiableList(values);
+    }
+    
+    /**
+     * Get the effective set of all class types via which the specified value
+     * should be indexed.
+     * 
+     * @param value the value to index
+     * @return the set of classes by which to index the value
+     */
+    private Set<Class<?>> getIndexTypes(final B value) {
+        final HashSet<Class<?>> indexTypes = new HashSet<>();
+        indexTypes.add(value.getClass());
+
+        if (indexSupertypes) {
+            getSuperTypes(value.getClass(), indexTypes);
+        }
+        
+        return indexTypes;
     }
 
     /**

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=426&r1=425&r2=426&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 20:27:09 2013
@@ -129,6 +129,23 @@
         Assert.assertEquals(map.get(AbstractFooBar.class).size(), 1);
         Assert.assertEquals(map.get(FooBarImpl.class).size(), 1);
     }
+    
+    @Test public void testDuplicateInsertions() {
+        ClassToInstanceMultiMap<Object> map = new ClassToInstanceMultiMap<Object>(true);
+        
+        FooBarImpl fb = new FooBarImpl();
+        
+        map.put(fb);
+        map.put(fb);
+        
+        Assert.assertEquals(map.values().size(), 1);
+        

[... 10 lines stripped ...]


More information about the commits mailing list