Package com.ibm.wala.util.collections
Class MapUtil
- java.lang.Object
-
- com.ibm.wala.util.collections.MapUtil
-
-
Constructor Summary
Constructors Constructor Description MapUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,T>
Collection<T>findOrCreateCollection(Map<K,Collection<T>> M, K key)
static <K,T>
List<T>findOrCreateList(Map<K,List<T>> M, K key)
static <K,K2,V>
Map<K2,V>findOrCreateMap(Map<K,Map<K2,V>> M, K key)
static <K> MutableIntSet
findOrCreateMutableIntSet(Map<K,MutableIntSet> M, K key)
static <K,T>
Set<T>findOrCreateSet(Map<K,Set<T>> M, K key)
static <K,V>
VfindOrCreateValue(Map<K,V> M, K key, Factory<V> factory)
static <K,V>
WeakHashMap<K,V>findOrCreateWeakHashMap(Map<Object,WeakHashMap<K,V>> M, Object key)
static <K,V>
Map<Set<K>,V>groupKeysByValue(Map<K,V> m)
static <K,V>
Map<V,Set<K>>inverseMap(Map<K,Set<V>> m)
static <K,V>
Map<V,K>invertOneToOneMap(Map<K,V> m)
invert an input map that is one-to-one (i.e., it does not map two different keys to the same value)
-
-
-
Method Detail
-
findOrCreateSet
public static <K,T> Set<T> findOrCreateSet(Map<K,Set<T>> M, K key)
- Parameters:
M
- a mapping from Object -> Setkey
-- Returns:
- the Set corresponding to key in M; create one if needed
- Throws:
IllegalArgumentException
- if M is nullClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateMutableIntSet
public static <K> MutableIntSet findOrCreateMutableIntSet(Map<K,MutableIntSet> M, K key)
- Throws:
ClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateCollection
public static <K,T> Collection<T> findOrCreateCollection(Map<K,Collection<T>> M, K key)
- Returns:
- the Collection corresponding to key in M; create one if needed
- Throws:
ClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateList
public static <K,T> List<T> findOrCreateList(Map<K,List<T>> M, K key)
- Returns:
- the Set corresponding to key in M; create one if needed
- Throws:
IllegalArgumentException
- if M is nullClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateMap
public static <K,K2,V> Map<K2,V> findOrCreateMap(Map<K,Map<K2,V>> M, K key)
- Parameters:
M
- a mapping from Object -> Mapkey
-- Returns:
- the Map corresponding to key in M; create one if needed
- Throws:
IllegalArgumentException
- if M is nullClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateValue
public static <K,V> V findOrCreateValue(Map<K,V> M, K key, Factory<V> factory)
- Throws:
ClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateWeakHashMap
public static <K,V> WeakHashMap<K,V> findOrCreateWeakHashMap(Map<Object,WeakHashMap<K,V>> M, Object key)
- Parameters:
M
- a mapping from Object -> WeakHashMapkey
-- Returns:
- the WeakHashMap corresponding to key in M; create one if needed
- Throws:
IllegalArgumentException
- if M is nullClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
inverseMap
public static <K,V> Map<V,Set<K>> inverseMap(Map<K,Set<V>> m)
- Parameters:
m
- a map from key -> Set- Returns:
- inverted map, value -> Set
- Throws:
IllegalArgumentException
- if m is null
-
invertOneToOneMap
public static <K,V> Map<V,K> invertOneToOneMap(Map<K,V> m)
invert an input map that is one-to-one (i.e., it does not map two different keys to the same value)- Throws:
IllegalArgumentException
- if m is nullIllegalArgumentException
- if m is not one-to-one
-
-