Package edu.stanford.nlp.util
Class ArrayCoreMap
- java.lang.Object
-
- edu.stanford.nlp.util.ArrayCoreMap
-
- All Implemented Interfaces:
CoreMap,PrettyLoggable,TypesafeMap,Serializable
- Direct Known Subclasses:
Annotation,CoreLabel,HashableCoreMap
public class ArrayCoreMap extends Object implements CoreMap
Base implementation ofCoreMapbacked by two Java arrays.Reasonable care has been put into ensuring that this class is both fast and has a light memory footprint.
Note that like the base classes in the Collections API, this implementation is not thread-safe. For speed reasons, these methods are not synchronized. A synchronized wrapper could be developed by anyone so inclined.
Equality is defined over the complete set of keys and values currently stored in the map. Because this class is mutable, it should not be used as a key in a Map.
- Author:
- dramage, rafferty
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface edu.stanford.nlp.util.TypesafeMap
TypesafeMap.Key<VALUE>
-
-
Field Summary
Fields Modifier and Type Field Description static Consumer<Class<? extends TypesafeMap.Key<?>>>listenerA listener for when a key is retrieved by the CoreMap.
-
Constructor Summary
Constructors Constructor Description ArrayCoreMap()Default constructor - initializes with default initial annotation capacity of 4.ArrayCoreMap(int capacity)Initializes this ArrayCoreMap, pre-allocating arrays to hold up to capacity key,value pairs.ArrayCoreMap(ArrayCoreMap other)Copy constructor.ArrayCoreMap(CoreMap other)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcompact()Reduces memory consumption to the minimum for representing the values currently stored stored in this object.<VALUE> booleancontainsKey(Class<? extends TypesafeMap.Key<VALUE>> key)Returns true if contains the given key.booleanequals(Object obj)Two CoreMaps are equal iff all keys and values are .equal.<VALUE> VALUEget(Class<? extends TypesafeMap.Key<VALUE>> key)Returns the value associated with the given key or null if none is provided.inthashCode()Returns a composite hashCode over all the keys and values currently stored in the map.Set<Class<?>>keySet()Collection of keys currently held in this map.Set<Class<?>>keySetNotNull()Return a set of keys such that the value of that key is not null.voidprettyLog(Redwood.RedwoodChannels channels, String description)Pretty logs the current object to specific Redwood channels.<VALUE> VALUEremove(Class<? extends TypesafeMap.Key<VALUE>> key)Removes the given key from the map, returning the value removed.<VALUE> VALUEset(Class<? extends TypesafeMap.Key<VALUE>> key, VALUE value)Associates the given value with the given type for future calls to get.voidsetCapacity(int newSize)intsize()Returns the number of elements in this map.StringtoShorterString(String... what)Attempt to provide a briefer and more human readable String for the contents of a CoreMap.StringtoShortString(char separator, String... what)This gives a very short String representation of a CoreMap by leaving it to the content to reveal what field is being printed.StringtoShortString(String... what)This gives a very short String representation of a CoreMap by leaving it to the content to reveal what field is being printed.StringtoString()Prints a full dump of a CoreMap.
-
-
-
Field Detail
-
listener
public static Consumer<Class<? extends TypesafeMap.Key<?>>> listener
A listener for when a key is retrieved by the CoreMap. This should only be used for testing.
-
-
Constructor Detail
-
ArrayCoreMap
public ArrayCoreMap()
Default constructor - initializes with default initial annotation capacity of 4.
-
ArrayCoreMap
public ArrayCoreMap(int capacity)
Initializes this ArrayCoreMap, pre-allocating arrays to hold up to capacity key,value pairs. This array will grow if necessary.- Parameters:
capacity- Initial capacity of object in key,value pairs
-
ArrayCoreMap
public ArrayCoreMap(ArrayCoreMap other)
Copy constructor.- Parameters:
other- The ArrayCoreMap to copy. It may not be null.
-
ArrayCoreMap
public ArrayCoreMap(CoreMap other)
Copy constructor.- Parameters:
other- The ArrayCoreMap to copy. It may not be null.
-
-
Method Detail
-
get
public <VALUE> VALUE get(Class<? extends TypesafeMap.Key<VALUE>> key)
Returns the value associated with the given key or null if none is provided.- Specified by:
getin interfaceTypesafeMap
-
set
public <VALUE> VALUE set(Class<? extends TypesafeMap.Key<VALUE>> key, VALUE value)
Associates the given value with the given type for future calls to get. Returns the value removed or null if no value was present.- Specified by:
setin interfaceTypesafeMap
-
keySet
public Set<Class<?>> keySet()
Collection of keys currently held in this map. Some implementations may have the returned set be immutable.- Specified by:
keySetin interfaceTypesafeMap
-
keySetNotNull
public Set<Class<?>> keySetNotNull()
Return a set of keys such that the value of that key is not null.- Returns:
- A hash set such that each element of the set is a key in this CoreMap that has a non-null value.
-
remove
public <VALUE> VALUE remove(Class<? extends TypesafeMap.Key<VALUE>> key)
Removes the given key from the map, returning the value removed.- Specified by:
removein interfaceTypesafeMap
-
containsKey
public <VALUE> boolean containsKey(Class<? extends TypesafeMap.Key<VALUE>> key)
Returns true if contains the given key.- Specified by:
containsKeyin interfaceTypesafeMap
-
compact
public void compact()
Reduces memory consumption to the minimum for representing the values currently stored stored in this object.
-
setCapacity
public void setCapacity(int newSize)
-
size
public int size()
Returns the number of elements in this map.- Specified by:
sizein interfaceTypesafeMap- Returns:
- The number of elements in this map.
-
toString
public String toString()
Prints a full dump of a CoreMap. This method is robust to circularity in the CoreMap.
-
toShorterString
public String toShorterString(String... what)
Attempt to provide a briefer and more human readable String for the contents of a CoreMap. The method may not be capable of printing circular dependencies in CoreMaps.- Specified by:
toShorterStringin interfaceCoreMap- Parameters:
what- An array (varargs) of Strings that say what annotation keys to print. These need to be provided in a shortened form where you are just giving the part of the class name without package and up to "Annotation". That is, edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation ➔ PartOfSpeech . As a special case, an empty array means to print everything, not nothing.- Returns:
- A more human readable String giving possibly partial contents of a CoreMap.
-
toShortString
public String toShortString(String... what)
This gives a very short String representation of a CoreMap by leaving it to the content to reveal what field is being printed.- Parameters:
what- An array (varargs) of Strings that say what annotation keys to print. These need to be provided in a shortened form where you are just giving the part of the class name without package and up to "Annotation". That is, edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation ➔ PartOfSpeech . As a special case, an empty array means to print everything, not nothing.- Returns:
- Brief string where the field values are just separated by a character. If the string contains spaces, it is wrapped in "{...}".
-
toShortString
public String toShortString(char separator, String... what)
This gives a very short String representation of a CoreMap by leaving it to the content to reveal what field is being printed.- Parameters:
separator- Character placed between fields in outputwhat- An array (varargs) of Strings that say what annotation keys to print. These need to be provided in a shortened form where you are just giving the part of the class name without package and up to "Annotation". That is, edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation ➔ PartOfSpeech . As a special case, an empty array means to print everything, not nothing.- Returns:
- Brief string where the field values are just separated by a character. If the string contains spaces, it is wrapped in "{...}".
-
equals
public boolean equals(Object obj)
Two CoreMaps are equal iff all keys and values are .equal.
-
hashCode
public int hashCode()
Returns a composite hashCode over all the keys and values currently stored in the map. Because they may change over time, this class is not appropriate for use as map keys.
-
prettyLog
public void prettyLog(Redwood.RedwoodChannels channels, String description)
Pretty logs the current object to specific Redwood channels.- Specified by:
prettyLogin interfacePrettyLoggable- Parameters:
channels- the channels which should be logged to -- all logging calls should use logging methods on the channels (e.g. channels.log(), etc.)description- The description of the object. It will potentially identify the object's functional role or (failing that) its class. This is typically used as a track name surrounding the contents of this object.
-
-