Utils
Class MapUtils

java.lang.Object
  extended by Utils.MapUtils

public class MapUtils
extends java.lang.Object

Utility class for maps

Version:
1.0

Method Summary
static
<K,V extends java.lang.Comparable<V>>
java.util.List<K>
keySetSortedByValue(java.util.Map<K,V> map)
          Returns the key set sorted by the associated value
static
<K,V extends java.lang.Comparable<V>>
java.util.List<K>
keySetSortedByValueReverse(java.util.Map<K,V> map)
          Returns the key sey sorted by the associated value in reverse order
static
<K,V> K
reverseLookup(java.util.Map<K,V> map, V value)
          Reverse lookup in the map.
static
<K,V> java.util.Set<K>
reverseLookupMulti(java.util.Map<K,V> map, V value)
          Reverse lookup in the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

keySetSortedByValue

public static <K,V extends java.lang.Comparable<V>> java.util.List<K> keySetSortedByValue(java.util.Map<K,V> map)
Returns the key set sorted by the associated value

Type Parameters:
K - Type of the map's keys
V - Tyoe of the map's values
Parameters:
map - The map
Returns:
A list of the map's key sorted by associated value

keySetSortedByValueReverse

public static <K,V extends java.lang.Comparable<V>> java.util.List<K> keySetSortedByValueReverse(java.util.Map<K,V> map)
Returns the key sey sorted by the associated value in reverse order

Type Parameters:
K - Type of the map's keys
V - Type of the map's values
Parameters:
map - The map
Returns:
A list of the map's key sorted by asscoiated value in reverse order

reverseLookup

public static <K,V> K reverseLookup(java.util.Map<K,V> map,
                                    V value)
Reverse lookup in the map. Returns the first key with the associated value. Returns null if the value is not in the map

Type Parameters:
K - Type of the map's key
V - Type of the map's avlues
Parameters:
map - The map
value - The value to return a key for
Returns:
The key

reverseLookupMulti

public static <K,V> java.util.Set<K> reverseLookupMulti(java.util.Map<K,V> map,
                                                        V value)
Reverse lookup in the map. Returns all keys with the associated value. Returns an empty set if the value is not in the map.

Type Parameters:
K - The type of the map's keys
V - The type of the map's values
Parameters:
map - The map
value -
Returns:
The value to return the keys for