public class ArrayCoreMap extends java.lang.Object implements CoreMap
CoreMap
backed 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.
TypesafeMap.Key<VALUE>
Modifier and Type | Field and Description |
---|---|
static java.util.function.Consumer<java.lang.Class<? extends TypesafeMap.Key<?>>> |
listener
A listener for when a key is retrieved by the CoreMap.
|
Constructor and Description |
---|
ArrayCoreMap()
Default constructor - initializes with default initial annotation
capacity of 4.
|
ArrayCoreMap(ArrayCoreMap other)
Copy constructor.
|
ArrayCoreMap(CoreMap other)
Copy constructor.
|
ArrayCoreMap(int capacity)
Initializes this ArrayCoreMap, pre-allocating arrays to hold
up to capacity key,value pairs.
|
Modifier and Type | Method and Description |
---|---|
void |
compact()
Reduces memory consumption to the minimum for representing the values
currently stored stored in this object.
|
<VALUE> boolean |
containsKey(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
Returns true if contains the given key.
|
boolean |
equals(java.lang.Object obj)
Two CoreMaps are equal iff all keys and values are .equal.
|
<VALUE> VALUE |
get(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
Returns the value associated with the given key or null if
none is provided.
|
int |
hashCode()
Returns a composite hashCode over all the keys and values currently
stored in the map.
|
java.util.Set<java.lang.Class<?>> |
keySet()
Collection of keys currently held in this map.
|
java.util.Set<java.lang.Class<?>> |
keySetNotNull()
Return a set of keys such that the value of that key is not null.
|
void |
prettyLog(Redwood.RedwoodChannels channels,
java.lang.String description)
Pretty logs the current object to specific Redwood channels.
|
<VALUE> VALUE |
remove(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
Removes the given key from the map, returning the value removed.
|
<VALUE> VALUE |
set(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key,
VALUE value)
Associates the given value with the given type for future calls
to get.
|
void |
setCapacity(int newSize) |
int |
size()
Returns the number of elements in this map.
|
java.lang.String |
toShorterString(java.lang.String... what)
Attempt to provide a briefer and more human readable String for the contents of
a CoreMap.
|
java.lang.String |
toShortString(char separator,
java.lang.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.
|
java.lang.String |
toShortString(java.lang.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.
|
java.lang.String |
toString()
Prints a full dump of a CoreMap.
|
public static java.util.function.Consumer<java.lang.Class<? extends TypesafeMap.Key<?>>> listener
public ArrayCoreMap()
public ArrayCoreMap(int capacity)
capacity
- Initial capacity of object in key,value pairspublic ArrayCoreMap(ArrayCoreMap other)
other
- The ArrayCoreMap to copy. It may not be null.public ArrayCoreMap(CoreMap other)
other
- The ArrayCoreMap to copy. It may not be null.public <VALUE> VALUE get(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
get
in interface TypesafeMap
public <VALUE> VALUE set(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key, VALUE value)
set
in interface TypesafeMap
public java.util.Set<java.lang.Class<?>> keySet()
keySet
in interface TypesafeMap
public java.util.Set<java.lang.Class<?>> keySetNotNull()
public <VALUE> VALUE remove(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
remove
in interface TypesafeMap
public <VALUE> boolean containsKey(java.lang.Class<? extends TypesafeMap.Key<VALUE>> key)
containsKey
in interface TypesafeMap
public void compact()
public void setCapacity(int newSize)
public int size()
size
in interface TypesafeMap
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toShorterString(java.lang.String... what)
toShorterString
in interface CoreMap
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.public java.lang.String toShortString(java.lang.String... what)
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.public java.lang.String toShortString(char separator, java.lang.String... what)
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.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void prettyLog(Redwood.RedwoodChannels channels, java.lang.String description)
prettyLog
in interface PrettyLoggable
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.