com.emarsys.ecommon.collections
Class MapUtil<K,V>

java.lang.Object
  extended by com.emarsys.ecommon.collections.MapUtil<K,V>
Type Parameters:
K -
V -

public class MapUtil<K,V>
extends java.lang.Object

Some Utility methods for creating maps in a nonverbose way .. Creationdate: Aug 22, 2007

Author:
Matthias Marchart, Michael "kULO" Kulovits

Constructor Summary
MapUtil()
           
 
Method Summary
static
<V> void
fillAlternatingly(java.util.Map<V,V> map, V... vals)
          fills the passed map with the passed vals, alternatingly interpreted as key and value.
static
<K> int
getInt(java.util.Map<K,java.lang.Integer> map, K key)
          Convenience method to retrieve ints from a map.
static
<K> int
getInt(java.util.Map<K,java.lang.Integer> map, K key, int nullSubstitute)
          Convenience method to retrieve ints from a map.
 java.util.Map<K,V> getMap()
          creates a map with the keys/vals interpreted as keys[i]=vals[i].
static
<V> java.util.Map<V,V>
getMap(V... vals)
          creates a map with the vals interpreted as key, value, key, value, ...
static
<V> java.util.SortedMap<V,V>
getSortedMap(V... vals)
          creates a sorted map with the vals interpreted as key, value, key, value, ...
 MapUtil<K,V> setKeys(K... keys)
           
 MapUtil<K,V> setValues(V... vals)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapUtil

public MapUtil()
Method Detail

getMap

public static <V> java.util.Map<V,V> getMap(V... vals)
creates a map with the vals interpreted as key, value, key, value, ... If the number of parameters is not even, the least one will be ignored.

Type Parameters:
V -
Parameters:
vals -
Returns:
the created map

getSortedMap

public static <V> java.util.SortedMap<V,V> getSortedMap(V... vals)
creates a sorted map with the vals interpreted as key, value, key, value, ... If the number of parameters is not even, the least one will be ignored.

Type Parameters:
V -
Parameters:
vals -
Returns:
the created map

fillAlternatingly

public static <V> void fillAlternatingly(java.util.Map<V,V> map,
                                         V... vals)
fills the passed map with the passed vals, alternatingly interpreted as key and value.

Type Parameters:
V -
Parameters:
map -
vals -

setKeys

public MapUtil<K,V> setKeys(K... keys)

setValues

public MapUtil<K,V> setValues(V... vals)

getMap

public java.util.Map<K,V> getMap()
creates a map with the keys/vals interpreted as keys[i]=vals[i]. If the number of K and V is not equal the minimum length of mappings will be interpreted.

Returns:
the created map
See Also:
setKeys(Object[]), setValues(Object[])

getInt

public static <K> int getInt(java.util.Map<K,java.lang.Integer> map,
                             K key)
Convenience method to retrieve ints from a map. If the key was not found in the map 0 is retuned.

Type Parameters:
K - the key type of the map.
Parameters:
map - - a Map with key type K and value type Integer.
key - - the key.
Returns:
an int value. 0 if the key was not found in the map.

getInt

public static <K> int getInt(java.util.Map<K,java.lang.Integer> map,
                             K key,
                             int nullSubstitute)
Convenience method to retrieve ints from a map. If the key was not found in the map nullSubstitute is retuned.

Type Parameters:
K - the key type of the map.
Parameters:
map - - a Map with key type K and value type Integer.
key - - the key.
nullSubstitute - - the int-value for null
Returns:
an int value. nullSubstitute if the key was not found in the map.


Copyright © 2010 emarsys AG. All Rights Reserved.