You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Michael Heuer (JIRA)" <ji...@apache.org> on 2007/06/15 23:18:26 UTC

[jira] Commented: (COLLECTIONS-244) Proposal to support generic multi-key maps with keys of different types

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

Michael Heuer commented on COLLECTIONS-244:
-------------------------------------------

Fair enough, what you describe is unwieldy.  Implementing these interfaces using the decorator pattern as done previously might not necessarily make the most sense.

Most often in my use cases I am working with large sparse n-dimensional matrices, where keys come from different objects.  Providing an API for these matrices as multi-maps with ...MapIterator and get(key..)/put(key...) methods allows clients to access the values without creating new composite key and/or entry objects with each call.

> Proposal to support generic multi-key maps with keys of different types
> -----------------------------------------------------------------------
>
>                 Key: COLLECTIONS-244
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-244
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Map
>    Affects Versions: Generics
>            Reporter: Michael Heuer
>            Priority: Minor
>         Attachments: multi-map.tar.gz
>
>
> MultiKeyMap as designed can only accept keys of the same type, if made to support generics, i.e.
> MultiKeyMap<MultiKey<String>,Integer> map = ...;
> map.put("foo", "bar", 10);
> // not possible
> //MultiKeyMap<MultiKey<String,Integer>,Double> map = ...;
> Attached is a proposal that may support multi-key maps with keys of different types.  I do not believe varying numbers of typed keys can be supported in a single interface, thus this proposal includes
> BinaryKey<K1,K2>
> BinaryKeyMap<K1,K2,V> extends Map<BinaryKey<K1,K2>,V>
> TertiaryKey<K1,K2,K3>
> TertiaryKeyMap<K1,K2,K3,V> extends Map<TertiaryKey<K1,K2,K3>,V>
> QuaternaryKey<K1,K2,K3,K4>
> QuaternaryKeyMap<K1,K2,K3,K4,V> extends Map<QuaternaryKey<K1,K2,K3,K4>,V>
> To prevent unnecessary object creation, I also propose to support MapIterator-style iterators:
> BinaryKeyMapIterator<K1,K2,V> extends Iterator<V>
> TertiaryKeyMapIterator<K1,K2,K3,V> extends Iterator<V>
> QuaternaryKeyMapIterator<K1,K2,K3,K4,V> extends Iterator<V>
> Current multi-map MapIterator support is implemented as Iterator<K1> but I find that Iterator<V> makes more sense here.  It is not possible to support MapIterator<K,V> without object creation, e.g. MapIterator<BinaryKey<K1,K2>,V> must create BinaryKey objects for each call to next().

-- 
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