Package com.ibm.wala.util.collections
Class MapUtil
- java.lang.Object
-
- com.ibm.wala.util.collections.MapUtil
-
public class MapUtil extends java.lang.Object
utilities for managingMap
s
-
-
Constructor Summary
Constructors Constructor Description MapUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,T>
java.util.Collection<T>findOrCreateCollection(java.util.Map<K,java.util.Collection<T>> M, K key)
static <K,T>
java.util.List<T>findOrCreateList(java.util.Map<K,java.util.List<T>> M, K key)
static <K,K2,V>
java.util.Map<K2,V>findOrCreateMap(java.util.Map<K,java.util.Map<K2,V>> M, K key)
static <K> MutableIntSet
findOrCreateMutableIntSet(java.util.Map<K,MutableIntSet> M, K key)
static <K,T>
java.util.Set<T>findOrCreateSet(java.util.Map<K,java.util.Set<T>> M, K key)
static <K,V>
VfindOrCreateValue(java.util.Map<K,V> M, K key, Factory<V> factory)
static <K,V>
java.util.WeakHashMap<K,V>findOrCreateWeakHashMap(java.util.Map<java.lang.Object,java.util.WeakHashMap<K,V>> M, java.lang.Object key)
static <K,V>
java.util.Map<java.util.Set<K>,V>groupKeysByValue(java.util.Map<K,V> m)
static <K,V>
java.util.Map<V,java.util.Set<K>>inverseMap(java.util.Map<K,java.util.Set<V>> m)
static <K,V>
java.util.Map<V,K>invertOneToOneMap(java.util.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> java.util.Set<T> findOrCreateSet(java.util.Map<K,java.util.Set<T>> M, K key)
- Parameters:
M
- a mapping from Object -> Set- Returns:
- the Set corresponding to key in M; create one if needed
- Throws:
java.lang.IllegalArgumentException
- if M is nulljava.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateMutableIntSet
public static <K> MutableIntSet findOrCreateMutableIntSet(java.util.Map<K,MutableIntSet> M, K key)
- Throws:
java.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateCollection
public static <K,T> java.util.Collection<T> findOrCreateCollection(java.util.Map<K,java.util.Collection<T>> M, K key)
- Returns:
- the Collection corresponding to key in M; create one if needed
- Throws:
java.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateList
public static <K,T> java.util.List<T> findOrCreateList(java.util.Map<K,java.util.List<T>> M, K key)
- Returns:
- the Set corresponding to key in M; create one if needed
- Throws:
java.lang.IllegalArgumentException
- if M is nulljava.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateMap
public static <K,K2,V> java.util.Map<K2,V> findOrCreateMap(java.util.Map<K,java.util.Map<K2,V>> M, K key)
- Parameters:
M
- a mapping from Object -> Map- Returns:
- the Map corresponding to key in M; create one if needed
- Throws:
java.lang.IllegalArgumentException
- if M is nulljava.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateValue
public static <K,V> V findOrCreateValue(java.util.Map<K,V> M, K key, Factory<V> factory)
- Throws:
java.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
findOrCreateWeakHashMap
public static <K,V> java.util.WeakHashMap<K,V> findOrCreateWeakHashMap(java.util.Map<java.lang.Object,java.util.WeakHashMap<K,V>> M, java.lang.Object key)
- Parameters:
M
- a mapping from Object -> WeakHashMap- Returns:
- the WeakHashMap corresponding to key in M; create one if needed
- Throws:
java.lang.IllegalArgumentException
- if M is nulljava.lang.ClassCastException
- if the key is of an inappropriate type for this map (optional)java.lang.NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
inverseMap
public static <K,V> java.util.Map<V,java.util.Set<K>> inverseMap(java.util.Map<K,java.util.Set<V>> m)
- Parameters:
m
- a map from key ->Set
<value>- Returns:
- inverted map, value ->
Set
<key> - Throws:
java.lang.IllegalArgumentException
- if m is null
-
invertOneToOneMap
public static <K,V> java.util.Map<V,K> invertOneToOneMap(java.util.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:
java.lang.IllegalArgumentException
- if m is nulljava.lang.IllegalArgumentException
- if m is not one-to-one
-
groupKeysByValue
public static <K,V> java.util.Map<java.util.Set<K>,V> groupKeysByValue(java.util.Map<K,V> m)
-
-