org.omnaest.utils.structure.map
Class MapUtils

java.lang.Object
  extended by org.omnaest.utils.structure.map.MapUtils

public class MapUtils
extends Object

Helper class for Map operations.

Author:
Omnaest

Nested Class Summary
static interface MapUtils.MapElementMergeOperation<K,V>
          A MapUtils.MapElementMergeOperation defines a MapUtils.MapElementMergeOperation.merge(Object, Object, Map) operation to merge Map elements into a merged Map instance.
 
Constructor Summary
MapUtils()
           
 
Method Summary
static
<KeyFrom,KeyTo,ValueFrom,ValueTo>
Map<KeyTo,ValueTo>
convertMap(Map<KeyFrom,ValueFrom> map, CollectionUtils.ElementConverter<KeyFrom,KeyTo> keyElementConverter, CollectionUtils.ElementConverter<ValueFrom,ValueTo> valueElementConverter)
          Converts a given map into a new map with new types.
static
<KeyFrom,KeyTo,Value>
Map<KeyTo,Value>
convertMapKey(Map<KeyFrom,Value> map, CollectionUtils.ElementConverter<KeyFrom,KeyTo> keyElementConverter)
          Converts the key of a map into another key.
static
<K,VA,VB> List<TupleDuad<VA,VB>>
innerJoinMapByKey(Map<K,VA> mapA, Map<K,VB> mapB)
          Returns a list of TupleDuad instances which have always the value of the first map and the value of the second map which share the same key over both maps.
static
<K,V> Map<K,V>
mergeAll(Collection<Map<K,V>> mapCollection)
          Merges all given Map instances into a single LinkedHashMap.
static
<K,V> Map<K,V>
mergeAll(Collection<Map<K,V>> mapCollection, MapUtils.MapElementMergeOperation<K,V> mapElementMergeOperation)
          Merges all given Map instances into a single LinkedHashMap using the given MapUtils.MapElementMergeOperation.
static
<K,V> Map<K,V>
mergeAll(Map<K,V>... maps)
          Merges all given Map instances into a single LinkedHashMap.
static
<K,V> Map<K,V>
mergeAll(MapUtils.MapElementMergeOperation<K,V> mapElementMergeOperation, Map<K,V>... maps)
          Merges all given Map instances into a single LinkedHashMap using the given MapUtils.MapElementMergeOperation.
static
<K,V> String
toString(Map<K,V> map)
          Returns a String representation for a Map
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapUtils

public MapUtils()
Method Detail

mergeAll

public static <K,V> Map<K,V> mergeAll(MapUtils.MapElementMergeOperation<K,V> mapElementMergeOperation,
                                      Map<K,V>... maps)
Merges all given Map instances into a single LinkedHashMap using the given MapUtils.MapElementMergeOperation.

Type Parameters:
K -
V -
Parameters:
mapElementMergeOperation -
maps -
Returns:
See Also:
mergeAll(Map...), mergeAll(Collection, MapElementMergeOperation)

mergeAll

public static <K,V> Map<K,V> mergeAll(Collection<Map<K,V>> mapCollection,
                                      MapUtils.MapElementMergeOperation<K,V> mapElementMergeOperation)
Merges all given Map instances into a single LinkedHashMap using the given MapUtils.MapElementMergeOperation.

Type Parameters:
K -
V -
Parameters:
mapCollection -
mapElementMergeOperation -
Returns:
See Also:
mergeAll(Map...)

mergeAll

public static <K,V> Map<K,V> mergeAll(Collection<Map<K,V>> mapCollection)
Merges all given Map instances into a single LinkedHashMap.

Type Parameters:
K -
V -
Parameters:
mapCollection -
Returns:
See Also:
mergeAll(Map...)

mergeAll

public static <K,V> Map<K,V> mergeAll(Map<K,V>... maps)
Merges all given Map instances into a single LinkedHashMap.

Type Parameters:
K -
V -
Parameters:
maps -
Returns:
See Also:
mergeAll(Collection), mergeAll(Collection, MapElementMergeOperation)

innerJoinMapByKey

public static <K,VA,VB> List<TupleDuad<VA,VB>> innerJoinMapByKey(Map<K,VA> mapA,
                                                                 Map<K,VB> mapB)
Returns a list of TupleDuad instances which have always the value of the first map and the value of the second map which share the same key over both maps.

Type Parameters:
K -
VA -
VB -
Parameters:
mapA -
mapB -
Returns:

convertMapKey

public static <KeyFrom,KeyTo,Value> Map<KeyTo,Value> convertMapKey(Map<KeyFrom,Value> map,
                                                                   CollectionUtils.ElementConverter<KeyFrom,KeyTo> keyElementConverter)
Converts the key of a map into another key.

Type Parameters:
KeyFrom -
KeyTo -
Value -
Parameters:
map -
keyElementConverter -
Returns:

convertMap

public static <KeyFrom,KeyTo,ValueFrom,ValueTo> Map<KeyTo,ValueTo> convertMap(Map<KeyFrom,ValueFrom> map,
                                                                              CollectionUtils.ElementConverter<KeyFrom,KeyTo> keyElementConverter,
                                                                              CollectionUtils.ElementConverter<ValueFrom,ValueTo> valueElementConverter)
Converts a given map into a new map with new types. Makes use of element converters.

Parameters:
map -
keyElementConverter -
valueElementConverter -
Returns:
See Also:
CollectionUtils.ElementConverter

toString

public static <K,V> String toString(Map<K,V> map)
Returns a String representation for a Map

Parameters:
map -
Returns:


Copyright © 2011. All Rights Reserved.