edu.stanford.nlp.util
Class MapFactory<K,V>

java.lang.Object
  extended by edu.stanford.nlp.util.MapFactory<K,V>
All Implemented Interfaces:
java.io.Serializable

public abstract class MapFactory<K,V>
extends java.lang.Object
implements java.io.Serializable

A factory class for vending different sorts of Maps.

Author:
Dan Klein (klein@cs.stanford.edu), Kayur Patel (kdpatel@cs)
See Also:
Serialized Form

Field Summary
static MapFactory HASH_MAP_FACTORY
           
static MapFactory IDENTITY_HASH_MAP_FACTORY
           
 
Constructor Summary
protected MapFactory()
           
 
Method Summary
static
<K,V> MapFactory<K,V>
arrayMapFactory()
          Return a MapFactory that returns an ArrayMap.
static
<K,V> MapFactory<K,V>
hashMapFactory()
          Return a MapFactory that returns a HashMap.
static
<K,V> MapFactory<K,V>
identityHashMapFactory()
          Return a MapFactory that returns an IdentityHashMap.
static
<K,V> MapFactory<K,V>
linkedHashMapFactory()
          Return a MapFactory that returns an LinkedHashMap.
abstract  java.util.Map<K,V> newMap()
          Returns a new non-parameterized map of a particular sort.
abstract  java.util.Map<K,V> newMap(int initCapacity)
          Returns a new non-parameterized map of a particular sort with an initial capacity.
abstract
<K1,V1> java.util.Map<K1,V1>
setMap(java.util.Map<K1,V1> map)
          A method to get a parameterized (genericized) map out.
abstract
<K1,V1> java.util.Map<K1,V1>
setMap(java.util.Map<K1,V1> map, int initCapacity)
           
static
<K,V> MapFactory<K,V>
treeMapFactory()
          Return a MapFactory that returns an TreeMap.
static
<K,V> MapFactory<K,V>
weakHashMapFactory()
          Return a MapFactory that returns a WeakHashMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_MAP_FACTORY

public static final MapFactory HASH_MAP_FACTORY

IDENTITY_HASH_MAP_FACTORY

public static final MapFactory IDENTITY_HASH_MAP_FACTORY
Constructor Detail

MapFactory

protected MapFactory()
Method Detail

hashMapFactory

public static <K,V> MapFactory<K,V> hashMapFactory()
Return a MapFactory that returns a HashMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes a HashMap.

identityHashMapFactory

public static <K,V> MapFactory<K,V> identityHashMapFactory()
Return a MapFactory that returns an IdentityHashMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes a HashMap.

weakHashMapFactory

public static <K,V> MapFactory<K,V> weakHashMapFactory()
Return a MapFactory that returns a WeakHashMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes a WeakHashMap.

treeMapFactory

public static <K,V> MapFactory<K,V> treeMapFactory()
Return a MapFactory that returns an TreeMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes an TreeMap.

linkedHashMapFactory

public static <K,V> MapFactory<K,V> linkedHashMapFactory()
Return a MapFactory that returns an LinkedHashMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes an LinkedHashMap.

arrayMapFactory

public static <K,V> MapFactory<K,V> arrayMapFactory()
Return a MapFactory that returns an ArrayMap. Implementation note: This method uses the same trick as the methods like emptyMap() introduced in the Collections class in JDK1.5 where callers can call this method with apparent type safety because this method takes the hit for the cast.

Returns:
A MapFactory that makes an ArrayMap.

newMap

public abstract java.util.Map<K,V> newMap()
Returns a new non-parameterized map of a particular sort.

Returns:
A new non-parameterized map of a particular sort

newMap

public abstract java.util.Map<K,V> newMap(int initCapacity)
Returns a new non-parameterized map of a particular sort with an initial capacity.

Parameters:
initCapacity - initial capacity of the map
Returns:
A new non-parameterized map of a particular sort with an initial capacity

setMap

public abstract <K1,V1> java.util.Map<K1,V1> setMap(java.util.Map<K1,V1> map)
A method to get a parameterized (genericized) map out.

Parameters:
map - A type-parameterized Map argument
Returns:
A Map with type-parameterization identical to that of the argument.

setMap

public abstract <K1,V1> java.util.Map<K1,V1> setMap(java.util.Map<K1,V1> map,
                                                    int initCapacity)


Stanford NLP Group