[ 
https://issues.apache.org/jira/browse/COLLECTIONS-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12492649
 ] 

Nikhil G. Daddikar commented on COLLECTIONS-250:
------------------------------------------------

It's not changed, my mistake. 

Just as in a regular map that containsKey(key) is not equivalent to 
getValue(key) != null, i.e. after doing a put(key, null), containsKey(key), 
still returns true, I am expecting something similar. I find it wierd that 
after doing a putAll(key, LIST), containsKey(key) returns FALSE, it should 
return an empty list. 

My problem is this (maybe this is not to be discussed here, but I think it is 
appropriate at least to put the problem forward): I use MultiHashMap (MHM) for 
caching database results of 1-to-many relationships. Let's say its is a PERSON 
borrowed BOOKS relation. So, I do one SQL query to fetch all the books for many 
(not all) persons and then populate the MHM cache (SELECT book_id from 
BorrowedBooks where person_id in (id1, id2, id3...)). After populating, the MHM 
has person1->books borrowed by person1, person2->books borrwed by person2 etc. 
Now, a query comes asking for books borrowed by personX. Since there is no way 
of asking the MHM whether "this key has no entries", if I don't find the 
personX's key in the MHM, it is unclear if the caching query had fetched 
personX's id in the original query. If there was a way, of maintaining empty 
collections in the MHM, then this problem can be solved. 

Also there is no way to put an empty list for a key which I could have used as  
workaround.

> containsKey on MultiHashMap seems incorrect
> -------------------------------------------
>
>                 Key: COLLECTIONS-250
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-250
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 3.1, 3.2
>            Reporter: Nikhil G. Daddikar
>            Priority: Critical
>
> MultiHashMap m = new MultiHashMap();
> m.putAll("key", Collections.EMPTY_LIST);
> System.out.println(m.containsKey("key")) 
> It says false, when it should have printed true. 
> The problem is that the code in MultiHashMap and even MultiValueMap has in 
> putAll():
> if (values == null || values.size() == 0) 
> {
>             return false;
> }
> This means that they key is never being entered into the Map. This is causing 
> a huge problem because the behaviour has changed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to