google collections ordering on map values

Posted by chris-gr on Stack Overflow See other posts from Stack Overflow or by chris-gr
Published on 2010-05-23T13:07:13Z Indexed on 2010/05/23 13:10 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

I would like to order a map based on the values.

Function<Map.Entry<A, Double>, Double> getSimFunction = new Function<Map.Entry<A, Double>, Double>() {
        public Double apply(Map.Entry<A, Double> entry) {
            return entry.getValue();
        }
    };

    final Ordering<Map.Entry<A, Double>> entryOrdering = Ordering.natural().onResultOf(getSimFunction);
    ImmutableSortedMap.orderedBy(entryOrdering).putAll(....).build();

How can I create a new sortedMap based on the ordering results or a sortedset based on the map.keyset()?

© Stack Overflow or respective owner

Related posts about google

Related posts about collections