commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 13786] New: - Proposal for change in MultiHashMap
Date Sat, 19 Oct 2002 20:31:43 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13786>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13786

Proposal for change in MultiHashMap

           Summary: Proposal for change in MultiHashMap
           Product: Commons
           Version: Nightly Builds
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Collections
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: sye@mail.ru


Current implementation of  MultiHashMap has one problem with notion of equality.
Namely, when for some key some value is added, and then removed from MultiMap,
and this value was only value, that was put for this key
than multimap wouldn't be equal to other multimap 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
TestMultiHashMap.testMapEquals):

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
       if(valuesForKey.isEmpty()){
           remove(key);
       }
//end of change
       return item;
   }

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message