You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Nikhil G. Daddikar (JIRA)" <ji...@apache.org> on 2007/04/27 12:26:15 UTC
[jira] Created: (COLLECTIONS-250) containsKey on MultiHashMap seems
incorrect
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.2, 3.1
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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [jira] Created: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by Stephen Smith <st...@stephen-smith.co.uk>.
Nikhil,
Do you have a test case to prove this behaviour? What would like to see
as a solution - an update to the JavaDoc to explicitly indicate that
inserting a key with null value(s) into a MultiMap returns false, or a
code change?
Steve.
---
Stephen Smith, MEng (Wales).
http://www.stephen-smith.co.uk/
Nikhil G. Daddikar (JIRA) wrote:
> 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.2, 3.1
> 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.
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by "James Carman (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COLLECTIONS-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12492652 ]
James Carman commented on COLLECTIONS-250:
------------------------------------------
Just use a set along side the map to keep track of which persons have had their books cached.
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COLLECTIONS-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12492595 ]
Henri Yandell commented on COLLECTIONS-250:
-------------------------------------------
It seems very correct to me - putAll(key, EMPTY_LIST) is a no-op. I'm not sure what behaviour has changed here - these methods haven't changed since they were added in r131607.
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Resolved: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by "James Carman (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COLLECTIONS-250?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James Carman resolved COLLECTIONS-250.
--------------------------------------
Resolution: Invalid
Assignee: James Carman
I believe we have established that this is the desired functionality. Changing it now would break other code which relies upon the existing behavior.
> 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
> Assigned To: James Carman
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by "Nikhil G. Daddikar (JIRA)" <ji...@apache.org>.
[ 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[jira] Commented: (COLLECTIONS-250) containsKey on MultiHashMap
seems incorrect
Posted by "James Carman (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COLLECTIONS-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12492379 ]
James Carman commented on COLLECTIONS-250:
------------------------------------------
The behavior has changed from what? The Map API?
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org