edu.cmu.cs.crystal.util
Class CollectionMethods

java.lang.Object
  extended by edu.cmu.cs.crystal.util.CollectionMethods

public class CollectionMethods
extends Object


Nested Class Summary
static interface CollectionMethods.Mapping<I,O>
          Interface used for the method in a map call.
 
Constructor Summary
CollectionMethods()
           
 
Method Summary
static
<K,V> void
addToMultiMap(K key, V val, Map<K,List<V>> map)
          Add an element to a 'multi-map.' Modifies the map in place.
static
<T> List<T>
concat(List<? extends T> l1, List<? extends T> l2)
          Concatenates two lists.
static
<T> Set<T>
createSetWithoutElement(Set<T> s, T element)
           
static
<I,O> List<O>
map(List<? extends I> list, CollectionMethods.Mapping<I,O> fun)
          Functional map, returns a new list.
static
<T> Set<T>
mutableSet(T... elements)
          Creates a set from an array of elements (i.e., duplicate elements will be dropped).
static
<K,V> Map<K,V>
union(Map<? extends K,? extends V> m1, Map<? extends K,? extends V> m2)
          Return the union of two maps without modifying either one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionMethods

public CollectionMethods()
Method Detail

map

public static <I,O> List<O> map(List<? extends I> list,
                                CollectionMethods.Mapping<I,O> fun)
Functional map, returns a new list.


concat

public static <T> List<T> concat(List<? extends T> l1,
                                 List<? extends T> l2)
Concatenates two lists. Returns a brand new list and does not modify the original lists.


union

public static <K,V> Map<K,V> union(Map<? extends K,? extends V> m1,
                                   Map<? extends K,? extends V> m2)
Return the union of two maps without modifying either one.


addToMultiMap

public static <K,V> void addToMultiMap(K key,
                                       V val,
                                       Map<K,List<V>> map)
Add an element to a 'multi-map.' Modifies the map in place.


createSetWithoutElement

public static <T> Set<T> createSetWithoutElement(Set<T> s,
                                                 T element)

mutableSet

public static <T> Set<T> mutableSet(T... elements)
Creates a set from an array of elements (i.e., duplicate elements will be dropped).