edu.stanford.nlp.util
Class Maps

java.lang.Object
  extended by edu.stanford.nlp.util.Maps

public class Maps
extends Object

Utilities for Maps, including inverting, composing, and support for list/set values.

Author:
Dan Klein (klein@cs.stanford.edu) Date: Oct 22, 2003 Time: 8:56:16 PM

Constructor Summary
Maps()
           
 
Method Summary
static
<X,Y,Z> Map<X,Z>
compose(Map<X,Y> map1, Map<Y,Z> map2)
          Compose two maps map1:x->y and map2:y->z to get a map x->z
static
<X,Y> Map<Y,X>
invert(Map<X,Y> map)
          Inverts a map x->y to a map y->x assuming unique preimages.
static
<X,Y> Map<Y,Set<X>>
invertSet(Map<X,Y> map)
          Inverts a map x->y to a map y->pow(x) not assuming unique preimages.
static void main(String[] args)
           
static
<K,V> void
putIntoValueArrayList(Map<K,List<V>> map, K key, V value)
          Adds the value to the ArrayList given by map.get(key), creating a new ArrayList if needed.
static
<K,V,C extends Collection<V>>
void
putIntoValueCollection(Map<K,C> map, K key, V value, CollectionFactory<V> cf)
          Adds the value to the collection given by map.get(key).
static
<K,V> void
putIntoValueHashSet(Map<K,Set<V>> map, K key, V value)
          Adds the value to the HashSet given by map.get(key), creating a new HashMap if needed.
 
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

putIntoValueHashSet

public static <K,V> void putIntoValueHashSet(Map<K,Set<V>> map,
                                             K key,
                                             V value)
Adds the value to the HashSet given by map.get(key), creating a new HashMap if needed.


putIntoValueArrayList

public static <K,V> void putIntoValueArrayList(Map<K,List<V>> map,
                                               K key,
                                               V value)
Adds the value to the ArrayList given by map.get(key), creating a new ArrayList if needed.


putIntoValueCollection

public static <K,V,C extends Collection<V>> void putIntoValueCollection(Map<K,C> map,
                                                                        K key,
                                                                        V value,
                                                                        CollectionFactory<V> cf)
Adds the value to the collection given by map.get(key). A new collection is created using the supplied CollectionFactory.


compose

public static <X,Y,Z> Map<X,Z> compose(Map<X,Y> map1,
                                       Map<Y,Z> map2)
Compose two maps map1:x->y and map2:y->z to get a map x->z

Returns:
The composed map

invert

public static <X,Y> Map<Y,X> invert(Map<X,Y> map)
Inverts a map x->y to a map y->x assuming unique preimages. If they are not unique, you get an arbitrary ones as the values in the inverted map.

Returns:
The inverted map

invertSet

public static <X,Y> Map<Y,Set<X>> invertSet(Map<X,Y> map)
Inverts a map x->y to a map y->pow(x) not assuming unique preimages.

Returns:
The inverted set

main

public static void main(String[] args)


Stanford NLP Group