net.sf.staccatocommons.collections
Class Maps

java.lang.Object
  extended by net.sf.staccatocommons.collections.Maps

public class Maps
extends Object

Class methods for dealing with maps

Author:
flbulgarelli

Constructor Summary
Maps()
           
 
Method Summary
static
<K> Option<K>
anyKey(Map<K,?> map)
          Answers Some(key) from the given Map, or None, if it is empty.
static
<K> K
anyKeyOrNull(Map<K,?> map)
          Answers a key from the given Map, or null, if it is empty.
static
<V> Option<V>
anyValue(Map<?,V> map)
          Answers a Some(value) from the given Map, or None, if it is empty.
static
<V> V
anyValueOrNull(Map<?,V> map)
          Answers a value from the given Map, or null, if it is empty.
static
<K,V1,V2> Map<K,V2>
delayedMapKeys(Map<K,V1> map, Applicable<? super V1,? extends V2> function)
           
static
<K,V> Map<K,V>
from(Iterable<Tuple2<K,V>> entries)
          Answers a new Unmodifiable map with the given entries
static
<K,V> Map<K,V>
from(Tuple2<K,V>... entries)
          Answers a new Unmodifiable map with the given entries
static
<V> Option<V>
get(Map<?,V> map, Object key)
          Answers the optional value for the given key
static
<V> V
getExistent(Map<?,V> map, Object key)
          Answers the value for the given key.
static boolean isNullOrEmpty(Map<?,?> map)
          Answers if the given map is null or empty
static
<K,V1,V2> Map<K,V2>
mapKeys(Map<K,V1> map, Applicable<V1,V2> function)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maps

public Maps()
Method Detail

get

@NonNull
public static <V> Option<V> get(@NonNull
                                        Map<?,V> map,
                                        Object key)
Answers the optional value for the given key

Type Parameters:
V -
Parameters:
map -
key - the key to lookup
Returns:
Some(value) if the key exists, None, otherwise

getExistent

@NonNull
public static <V> V getExistent(@NonNull
                                        Map<?,V> map,
                                        Object key)
Answers the value for the given key. Throws a NoSuchElementException if there is no mapping for it

Type Parameters:
V -
Parameters:
map -
key - the key to lookup
Returns:
Some(value) if the key exists, None, otherwise

anyKey

@NonNull
public static <K> Option<K> anyKey(@NonNull
                                           Map<K,?> map)
Answers Some(key) from the given Map, or None, if it is empty. Notice that any does not mean random, it may return always the same key, as this method just guarantees that if Some(key) is returned, map.containsKey(key) will return true

Type Parameters:
K -
Parameters:
map -
Returns:
Some(key) if map is not empty, None otherwise

anyKeyOrNull

public static <K> K anyKeyOrNull(@NonNull
                                 Map<K,?> map)
Answers a key from the given Map, or null, if it is empty. Notice that any does not mean random, it may return always the same key, as this method just guarantees that if a non null key is returned, map.containsKey(key) will return true

Type Parameters:
K -
Parameters:
map -
Returns:
a key if map is not empty, null otherwise

anyValue

@NonNull
public static <V> Option<V> anyValue(@NonNull
                                             Map<?,V> map)
Answers a Some(value) from the given Map, or None, if it is empty. Notice that any does not mean random, it may return always the same value, this method just guarantees that if a Some(value) is returned, map.containsValue(value) will return true

Type Parameters:
V -
Parameters:
map -
Returns:
Some(value) if map is not empty, None otherwise

anyValueOrNull

public static <V> V anyValueOrNull(@NonNull
                                   Map<?,V> map)
Answers a value from the given Map, or null, if it is empty. Notice that any does not mean random, it may return always the same value, as this method just guarantees that if a value is returned, map.containsValue(value) will return true

Type Parameters:
V -
Parameters:
map -
Returns:
a value if map is not empty, null otherwise

isNullOrEmpty

public static boolean isNullOrEmpty(Map<?,?> map)
Answers if the given map is null or empty

Parameters:
map -
Returns:
map == null || map.isEmpty()

mapKeys

public static <K,V1,V2> Map<K,V2> mapKeys(Map<K,V1> map,
                                          Applicable<V1,V2> function)

delayedMapKeys

public static <K,V1,V2> Map<K,V2> delayedMapKeys(Map<K,V1> map,
                                                 Applicable<? super V1,? extends V2> function)

from

public static <K,V> Map<K,V> from(Iterable<Tuple2<K,V>> entries)
Answers a new Unmodifiable map with the given entries

Type Parameters:
K -
V -
Parameters:
entries - the new map entries
Returns:
a new unmodifiable map

from

public static <K,V> Map<K,V> from(Tuple2<K,V>... entries)
Answers a new Unmodifiable map with the given entries

Type Parameters:
K -
V -
Parameters:
entries - the new map entries
Returns:
a new unmodifiable map


Get Staccatocommons at SourceForge.net. Fast, secure and Free Open Source software downloads