[
https://issues.apache.org/jira/browse/COLLECTIONS-263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13604756#comment-13604756
]
Thomas Neidhart commented on COLLECTIONS-263:
---------------------------------------------
We could adapt the MapUtils.populateMap method to allow also MultiMap as an
input:
{noformat}
final MultiValueMap<Integer, X> map = MultiValueMap.multiValueMap(new
TreeMap<Integer, Collection<X>>());
Collection<X> coll = new ArrayList<X>();
coll.add(new X(10));
coll.add(new X(1));
coll.add(new X(5));
coll.add(new X(3));
MapUtils.populateMap(map, coll, new Transformer<X, Integer>() {
public Integer transform(X input) {
return input.i;
}
}, TransformerUtils.<X>nopTransformer());
{noformat}
That way you populate a MultiMap from a collection using two transformers for
key and value. To have a sorting of the keys, use a TreeMap.
> Extend the MultiHashMap to create an object filter by value of given field
> --------------------------------------------------------------------------
>
> Key: COLLECTIONS-263
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-263
> Project: Commons Collections
> Issue Type: New Feature
> Components: KeyValue, Map
> Affects Versions: 3.1, 3.2
> Reporter: John Hunsley
> Priority: Minor
> Attachments: CollectionFilter.java, CollectionFilterTest.java
>
>
> I purpose extending the MultiHashMap to create an object filter which will
> filter a given collection of objects by a given field value.
> For example:
> I have a collection of 5 objects of class X. X has an int field i as shown
> below:
> x1 i = 1
> x2 i = 2
> x3 i = 2
> x4 i = 5
> x5 i = 5
> The extended MultiHashMap will filter those objects by the field i and store
> each sorted object into the map using the value of the field, i, as the key,
> such that the resulting MultiHashMap looks as follows:
> key | values
> 1 | x1
> 2 | x2, x3
> 5 | x4, x5
> I have a class which does this and I find it invaluable in my day to day
> work. I don't Collections has a similar one.
> Kind regards,
> John.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira