org.broadleafcommerce.common.util
Class BLCMapUtils

java.lang.Object
  extended by org.broadleafcommerce.common.util.BLCMapUtils

public class BLCMapUtils
extends Object

Convenience methods for interacting with maps

Author:
Andre Azzolini (apazzolini)

Constructor Summary
BLCMapUtils()
           
 
Method Summary
static
<K,CV extends Iterable<V>,V>
Map<K,List<V>>
keyedListMap(CV values, TypedClosure<K,V> closure)
          Given a collection of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to a list of values that map to that key.
static
<K,CV extends Iterable<V>,V>
Map<K,V>
keyedMap(CV values, TypedClosure<K,V> closure)
          Given a collection of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to the value.
static
<K,V> Map<K,V>
keyedMap(V[] values, TypedClosure<K,V> closure)
          Given an array of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to the value.
static
<K,V> Map<K,V>
valueSortedMap(Map<K,V> map, Comparator<Map.Entry<K,V>> comparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BLCMapUtils

public BLCMapUtils()
Method Detail

keyedMap

public static <K,CV extends Iterable<V>,V> Map<K,V> keyedMap(CV values,
                                                             TypedClosure<K,V> closure)
Given a collection of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to the value. Note: If two values share the same key, the later one will override the previous one in the returned map

Parameters:
values -
closure -
Returns:
the map
See Also:
List --> Map

keyedMap

public static <K,V> Map<K,V> keyedMap(V[] values,
                                      TypedClosure<K,V> closure)
Given an array of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to the value. Note: If two values share the same key, the later one will override the previous one in the returned map

Parameters:
values -
closure -
Returns:
the map
See Also:
V[] --> Map

keyedListMap

public static <K,CV extends Iterable<V>,V> Map<K,List<V>> keyedListMap(CV values,
                                                                       TypedClosure<K,V> closure)
Given a collection of values and a TypedClosure that maps an appropriate key for a given value, returns a HashMap of the key to a list of values that map to that key.

Parameters:
values -
closure -
Returns:
the map
See Also:
List --> Map>

valueSortedMap

public static <K,V> Map<K,V> valueSortedMap(Map<K,V> map,
                                            Comparator<Map.Entry<K,V>> comparator)


Copyright © 2013. All Rights Reserved.