I have a flattened multi-map (a list) of objects which I would like to convert to a list where a 'key' attribute / field (e.g. name below) is unique amongst all entries.
In the case where multiple entries have the same key (name) the entry with the largest creationDate field should be picked.
Example:
List<Object> myList =
[
{name="abc", age=23, creationDate = 1234L},
{name="abc", age=12, creationDate = 2345L},
{name="ddd", age=99, creationDate = 9999L}
]
Should be converted to:
List<Object> =
[
{name="abc", age=12, creationDate = 2345L},
{name="ddd", age=99, creationDate = 9999L}
]
Is there an elegant way (possibly using Guava libraries?) to solve this in Java? I realize I can just try and use a HashMap with name as the key to find all unique entries, but I get the feeling there is a better way to solve this.
Thanks!