edu.stanford.nlp.util
Class HashableCoreMap

java.lang.Object
  extended by edu.stanford.nlp.util.ArrayCoreMap
      extended by edu.stanford.nlp.util.HashableCoreMap
All Implemented Interfaces:
CoreMap, PrettyLoggable, TypesafeMap<CoreMap>, Serializable

public class HashableCoreMap
extends ArrayCoreMap

An extension of ArrayCoreMap with an immutable set of key,value pairs that is used for equality and hashcode comparisons.

Author:
dramage
See Also:
Serialized Form

Nested Class Summary
static class HashableCoreMap.HashableCoreMapException
          An exception thrown when attempting to change the value associated with an (immutable) hash key in a HashableCoreMap.
 
Nested classes/interfaces inherited from interface edu.stanford.nlp.util.TypesafeMap
TypesafeMap.Key<BASE,VALUE>
 
Constructor Summary
HashableCoreMap(ArrayCoreMap other, Set<Class<? extends TypesafeMap.Key<CoreMap,?>>> hashkey)
          Creates an instance by copying values from the given other CoreMap, using the values it associates with the given set of hashkeys for the immutable, hashable keys used by hashcode and equals.
HashableCoreMap(Map<Class<? extends TypesafeMap.Key<CoreMap,?>>,Object> hashkey)
          Creates an instance of HashableCoreMap with initial key,value pairs for the immutable, hashable keys as provided in the given map.
 
Method Summary
 boolean equals(Object o)
          If the provided object is a HashableCoreMap, equality is based only upon the values of the immutable hashkeys; otherwise, defaults to behavior of the superclass's equals method.
 int hashCode()
          Provides a hash code based on the immutable keys and values provided to the constructor.
<VALUEBASE,VALUE extends VALUEBASE,KEY extends TypesafeMap.Key<CoreMap,VALUEBASE>>
VALUE
set(Class<KEY> key, VALUE value)
          Sets the value associated with the given key; if the the key is one of the hashable keys, throws an exception.
 
Methods inherited from class edu.stanford.nlp.util.ArrayCoreMap
compact, containsKey, get, has, keySet, prettyLog, remove, setCapacity, size, toShorterString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HashableCoreMap

public HashableCoreMap(Map<Class<? extends TypesafeMap.Key<CoreMap,?>>,Object> hashkey)
Creates an instance of HashableCoreMap with initial key,value pairs for the immutable, hashable keys as provided in the given map.


HashableCoreMap

public HashableCoreMap(ArrayCoreMap other,
                       Set<Class<? extends TypesafeMap.Key<CoreMap,?>>> hashkey)
Creates an instance by copying values from the given other CoreMap, using the values it associates with the given set of hashkeys for the immutable, hashable keys used by hashcode and equals.

Method Detail

set

public <VALUEBASE,VALUE extends VALUEBASE,KEY extends TypesafeMap.Key<CoreMap,VALUEBASE>> VALUE set(Class<KEY> key,
                                                                                                    VALUE value)
Sets the value associated with the given key; if the the key is one of the hashable keys, throws an exception.

Specified by:
set in interface TypesafeMap<CoreMap>
Overrides:
set in class ArrayCoreMap
Throws:
HashableCoreMap.HashableCoreMapException - Attempting to set the value for an immutable, hashable key.

hashCode

public int hashCode()
Provides a hash code based on the immutable keys and values provided to the constructor.

Overrides:
hashCode in class ArrayCoreMap

equals

public boolean equals(Object o)
If the provided object is a HashableCoreMap, equality is based only upon the values of the immutable hashkeys; otherwise, defaults to behavior of the superclass's equals method.

Overrides:
equals in class ArrayCoreMap


Stanford NLP Group