ReadOnlyStringMap interface. Keys are held in a sorted array.
This is not a generic collection, but makes some trade-offs to optimize for the Log4j context data use case:
BiConsumer and TriConsumer.SortedArrayStringMap, the full thread context
data can be transferred with two array copies and two field updates.get and containsKey is O(log N),
worst-case performance of put and remove is O(N log N).
The expectation is that for the small values of N (less than 100) that are the vast majority of
ThreadContext use cases, the constants dominate performance more than the asymptotic performance of the
algorithms used.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | DEFAULT_INITIAL_CAPACITY
The default initial capacity. |
| private static final String[] | EMPTY
An empty array instance to share when the table is not inflated. |
| private static final String | |
| private static final int | |
| private boolean | |
| private transient boolean | |
| private transient String[] | |
| private static final TriConsumer | |
| private static final long | |
| private transient int | size
The number of key-value mappings contained in this map. |
| private int | threshold
The next size value at which to resize (capacity * load factor). |
| private transient Object[] |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private static int | Returns: The next power of 2 from x inclusiveValue to round up x)Calculate the next power of 2, greater than or equal to x. |
| public void | clear()
Implements org. Removes all key-value pairs from this collection. |
| public boolean | containsKey(final String
the key whose presence to check. May be key)null.Implements org. Returns |
| private void | |
| public boolean | equals(final Object
the reference object with which to compare. obj)Overrides java. Implements org. Indicates whether some other object is "equal to" this one. |
| public <V> void | forEach(final BiConsumer<String, ? super V>
The action to be performed for each key-value pair in this collection. action)Implements org. Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception. |
| public <V, T> void | forEach(final TriConsumer<String, ? super V, T>
The action to be performed for each key-value pair in this collection. action, final T the object to be passed as the third parameter to each invocation on the specified
triconsumer. state)Implements org. Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception. |
| public void | |
| public String | getKeyAt(final int
the index of the key to return index)Implements org. Viewing all key-value pairs as a sequence sorted by key, this method returns the key at the specified index,
or |
| public <V> V | getValue(final String
the key whose value to return. key)Implements org. Returns the value for the specified key, or |
| public <V> V | getValueAt(final int
the index of the value to return index)Implements org. Viewing all key-value pairs as a sequence sorted by key, this method returns the value at the specified index,
or |
| public int | hashCode()
Overrides java. Implements org. Returns a hash code value for the object. |
| private static int | |
| public int | indexOfKey(final String
the key whose index in the ordered sequence of keys to return key)Implements org. Viewing all key-value pairs as a sequence sorted by key, this method returns the index of the specified key in that sequence. |
| private void | |
| private void | |
| private void | |
| public boolean | isEmpty()
Implements org. Returns |
| public boolean | isFrozen()
Implements org. Returns |
| private void | |
| private int | |
| public void | putAll(final ReadOnlyStringMap
the source)ReadOnlyStringMap to copy key-value pairs fromImplements org. Copies all key-value pairs from the specified |
| public void | putValue(final String
the key to add or remove. Keys may be key, final Object null.the value to add. Values may be value)null.Implements org. Puts the specified key-value pair into the collection. |
| private void | readObject(final ObjectInputStream s)
Reconstitute the |
| public void | remove(final String
the key to remove. May be key)null.Implements org. Removes the key-value pair for the specified key from this data structure. |
| private void | |
| public int | size()
Implements org. Returns the number of key-value pairs in this collection. |
| public Map | toMap()
Implements org. Returns a non- |
| public String | |
| private void | writeObject(final ObjectOutputStream s)
Save the state of the |
| DEFAULT_INITIAL_CAPACITY | back to summary |
|---|---|
| private static final int DEFAULT_INITIAL_CAPACITY The default initial capacity. | |
| EMPTY | back to summary |
|---|---|
| private static final String[] EMPTY An empty array instance to share when the table is not inflated. | |
| FROZEN | back to summary |
|---|---|
| private static final String FROZEN | |
| HASHVAL | back to summary |
|---|---|
| private static final int HASHVAL | |
| immutable | back to summary |
|---|---|
| private boolean immutable | |
| iterating | back to summary |
|---|---|
| private transient boolean iterating | |
| keys | back to summary |
|---|---|
| private transient String[] keys | |
| PUT_ALL | back to summary |
|---|---|
| private static final TriConsumer<String, Object, StringMap> PUT_ALL | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| size | back to summary |
|---|---|
| private transient int size The number of key-value mappings contained in this map. | |
| threshold | back to summary |
|---|---|
| private int threshold The next size value at which to resize (capacity * load factor). | |
| values | back to summary |
|---|---|
| private transient Object[] values | |
| SortedArrayStringMap | back to summary |
|---|---|
| public SortedArrayStringMap() | |
| SortedArrayStringMap | back to summary |
|---|---|
| public SortedArrayStringMap(final int initialCapacity) | |
| SortedArrayStringMap | back to summary |
|---|---|
| public SortedArrayStringMap(final ReadOnlyStringMap other) | |
| SortedArrayStringMap | back to summary |
|---|---|
| public SortedArrayStringMap(final Map<String, ?> map) | |
| assertNoConcurrentModification | back to summary |
|---|---|
| private void assertNoConcurrentModification() | |
| assertNotFrozen | back to summary |
|---|---|
| private void assertNotFrozen() | |
| ceilingNextPowerOfTwo | back to summary |
|---|---|
| private static int ceilingNextPowerOfTwo(final int x) Calculate the next power of 2, greater than or equal to x. From Hacker's Delight, Chapter 3, Harry S. Warren Jr.
| |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Removes all key-value pairs from this collection.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(final String key) Implements org. Doc from org. Returns | |
| ensureCapacity | back to summary |
|---|---|
| private void ensureCapacity() | |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Implements org. Doc from org. Indicates whether some other object is "equal to" this one. | |
| forEach | back to summary |
|---|---|
| public <V> void forEach(final BiConsumer<String, ? super V> action) Implements org. Doc from org. Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
| |
| forEach | back to summary |
|---|---|
| public <V, T> void forEach(final TriConsumer<String, ? super V, T> action, final T state) Implements org. Doc from org. Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception. The third parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
| |
| freeze | back to summary |
|---|---|
| public void freeze() Implements org. Doc from org. Makes this collection immutable. Attempts to modify the collection after the
| |
| getKeyAt | back to summary |
|---|---|
| public String getKeyAt(final int index) Implements org. Doc from org. Viewing all key-value pairs as a sequence sorted by key, this method returns the key at the specified index,
or | |
| getValue | back to summary |
|---|---|
| public <V> V getValue(final String key) Implements org. Doc from org. Returns the value for the specified key, or
| |
| getValueAt | back to summary |
|---|---|
| public <V> V getValueAt(final int index) Implements org. Doc from org. Viewing all key-value pairs as a sequence sorted by key, this method returns the value at the specified index,
or
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements org. Doc from org. Returns a hash code value for the object.
| |
| hashCode | back to summary |
|---|---|
| private static int hashCode(final Object[] values, final int length) | |
| indexOfKey | back to summary |
|---|---|
| public int indexOfKey(final String key) Implements org. Doc from org. Viewing all key-value pairs as a sequence sorted by key, this method returns the index of the specified key in
that sequence. If the specified key is not found, this method returns
| |
| inflateTable | back to summary |
|---|---|
| private void inflateTable(final int toSize) Inflates the table. | |
| initFrom0 | back to summary |
|---|---|
| private void initFrom0(final SortedArrayStringMap other) | |
| insertAt | back to summary |
|---|---|
| private void insertAt(final int index, final String key, final Object value) | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements org. Doc from org. Returns
| |
| isFrozen | back to summary |
|---|---|
| public boolean isFrozen() Implements org. Doc from org. Returns | |
| merge | back to summary |
|---|---|
| private void merge(final SortedArrayStringMap other) | |
| nullKeyIndex | back to summary |
|---|---|
| private int nullKeyIndex() | |
| putAll | back to summary |
|---|---|
| public void putAll(final ReadOnlyStringMap source) Implements org. Doc from org. Copies all key-value pairs from the specified
| |
| putValue | back to summary |
|---|---|
| public void putValue(final String key, final Object value) Implements org. Doc from org. Puts the specified key-value pair into the collection. | |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException Reconstitute the | |
| remove | back to summary |
|---|---|
| public void remove(final String key) Implements org. Doc from org. Removes the key-value pair for the specified key from this data structure. | |
| resize | back to summary |
|---|---|
| private void resize(final int newCapacity) | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Returns the number of key-value pairs in this collection.
| |
| toMap | back to summary |
|---|---|
| public Map Implements org. Doc from org. Returns a non- | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream s) throws IOException Save the state of the
| |