org.jclouds.util
Class Maps2

java.lang.Object
  extended by org.jclouds.util.Maps2

public class Maps2
extends Object

General utilities used in jclouds code for Maps.

Author:
Adrian Cole

Constructor Summary
Maps2()
           
 
Method Summary
static
<K,V> com.google.common.base.Supplier<Map<K,V>>
composeMapSupplier(Iterable<com.google.common.base.Supplier<Map<K,V>>> suppliers)
           
static
<K,V> Map<K,V>
convertUnsafe(com.google.common.collect.Multimap<K,V> in)
           
static
<K,V> Map<K,V>
fromKeys(Set<K> keys, com.google.common.base.Function<? super K,V> valueFunction)
          Constructs a map with the given keys where values are generated by the given function.
static
<V> Map<String,V>
renameKey(Map<String,V> in, String k1, String k2)
          If the supplied map contains the key k1, its value will be assigned to the key k2.
static
<K1,K2,V> Map<K2,V>
transformKeys(Map<K1,V> in, com.google.common.base.Function<K1,K2> fn)
          change the keys but keep the values in-tact.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maps2

public Maps2()
Method Detail

convertUnsafe

public static <K,V> Map<K,V> convertUnsafe(com.google.common.collect.Multimap<K,V> in)

renameKey

public static <V> Map<String,V> renameKey(Map<String,V> in,
                                          String k1,
                                          String k2)
If the supplied map contains the key k1, its value will be assigned to the key k2. Note that this doesn't modify the input map.

Type Parameters:
V - type of value the map holds
Parameters:
in - the map you wish to make a copy of
k1 - old key
k2 - new key
Returns:
copy of the map with the value of the key re-routed, or the original, if it k1 wasn't present.

transformKeys

public static <K1,K2,V> Map<K2,V> transformKeys(Map<K1,V> in,
                                                com.google.common.base.Function<K1,K2> fn)
change the keys but keep the values in-tact.

Type Parameters:
K1 - input key type
K2 - output key type
V - value type
Parameters:
in - input map to transform
fn - how to transform the values
Returns:
immutableMap with the new keys.

composeMapSupplier

public static <K,V> com.google.common.base.Supplier<Map<K,V>> composeMapSupplier(Iterable<com.google.common.base.Supplier<Map<K,V>>> suppliers)

fromKeys

public static <K,V> Map<K,V> fromKeys(Set<K> keys,
                                      com.google.common.base.Function<? super K,V> valueFunction)
Constructs a map with the given keys where values are generated by the given function. Supports duplicate and null values, but null keys are not allowed.

Type Parameters:
K - the type of the keys
V - the type of the values
Parameters:
keys - the keys to be included in the map. Keys must be non-null
valueFunction - the function that produces values for the keys
Returns:
a map containing the keys from the given set with values which are generated from the keys
See Also:
Maps.uniqueIndex(Iterable, Function)


Copyright © 2009-2011 jclouds. All Rights Reserved.