Class BLCMapUtils

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

public class BLCMapUtils extends Object
Convenience methods for interacting with maps
Author:
Andre Azzolini (apazzolini)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 Details

    • BLCMapUtils

      public BLCMapUtils()
  • Method Details

    • 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:
    • 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:
    • 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:
    • valueSortedMap

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