commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Yevtushenko <>
Subject [collections] suggestion for change in MultiHasMap
Date Sat, 19 Oct 2002 08:04:15 GMT
Current implementation of  MultiHashMap has one problem with notion of 
Namely, when for some key some value is added, and then removed from 
MultiMap, and this value was only one value, that was put for this key
than multimap wouldn't be equal to with same values of key/value pairs, 
in which this new value was not added.

This can be demonstrated by following test (can be added to 

 public void testMapEquals() {
        MultiHashMap one = new MultiHashMap();
        Integer value = new Integer(1);
        one.put("One", value);
        one.remove("One", value);

        MultiHashMap two = new MultiHashMap();
        assertEquals(two, one);

Suggested fix for this problem is the following change in code of 
MultiHashMap.remove(Object key, Object value).

public Object remove( Object key, Object item )
        ArrayList valuesForKey = (ArrayList) super.get( key );
        if ( valuesForKey == null )
            return null;
      valuesForKey.remove( item );
//start of change
//end of change
        return item;

Best Regards.

Sergey Yevtushenko

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message