Package org.apache.groovy.json.internal
Class LazyMap
This maps only builds once you ask for a key for the first time.
It is designed to not incur the overhead of creating a map unless needed.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the compact buffers or hydrated map, depending on the current state.Copies the compact entries into a newLazyMapand clears this instance.protected Objectclone()Clones the hydrated backing map when one already exists.booleancontainsKey(Object key) Hydrates the backing map if needed and tests whether the key is present.booleancontainsValue(Object value) Hydrates the backing map if needed and tests whether the value is present.entrySet()Returns the hydrated entry set, building the backing map if necessary.booleanHydrates the backing map if needed and compares it with another object.Hydrates the backing map if needed and returns the value for the supplied key.static <V> V[]grow(V[] array) Doubles the capacity of the supplied array while preserving its component type.inthashCode()Hydrates the backing map if needed and returns its hash code.booleanisEmpty()Returns whether the map currently contains any entries.keySet()Hydrates the backing map if needed and returns its key set.Stores a mapping while keeping the compact array-backed representation until hydration is needed.voidHydrates the backing map if needed and copies all supplied entries into it.Hydrates the backing map if needed and removes the supplied key.intsize()Returns the current size without hydrating when the compact representation is still active.toString()Hydrates the backing map if needed and returns its string form.values()Hydrates the backing map if needed and returns its values collection.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
LazyMap
public LazyMap()Creates a lazy map with the default key and value buffer size. -
LazyMap
public LazyMap(int initialSize) Creates a lazy map with a caller-supplied key and value buffer size.- Parameters:
initialSize- initial buffer size
-
-
Method Details
-
put
Stores a mapping while keeping the compact array-backed representation until hydration is needed. -
entrySet
Returns the hydrated entry set, building the backing map if necessary. -
size
public int size()Returns the current size without hydrating when the compact representation is still active. -
isEmpty
public boolean isEmpty()Returns whether the map currently contains any entries. -
containsValue
Hydrates the backing map if needed and tests whether the value is present.- Specified by:
containsValuein interfaceMap<String,Object> - Overrides:
containsValuein classAbstractMap<String,Object> - Parameters:
value- value to test- Returns:
truewhen the value is present
-
containsKey
Hydrates the backing map if needed and tests whether the key is present.- Specified by:
containsKeyin interfaceMap<String,Object> - Overrides:
containsKeyin classAbstractMap<String,Object> - Parameters:
key- key to test- Returns:
truewhen the key is present
-
get
Hydrates the backing map if needed and returns the value for the supplied key. -
remove
Hydrates the backing map if needed and removes the supplied key. -
putAll
Hydrates the backing map if needed and copies all supplied entries into it. -
clear
public void clear()Clears the compact buffers or hydrated map, depending on the current state. -
keySet
Hydrates the backing map if needed and returns its key set. -
values
Hydrates the backing map if needed and returns its values collection. -
equals
Hydrates the backing map if needed and compares it with another object. -
hashCode
public int hashCode()Hydrates the backing map if needed and returns its hash code. -
toString
Hydrates the backing map if needed and returns its string form.- Overrides:
toStringin classAbstractMap<String,Object> - Returns:
- hydrated map text
-
clone
Clones the hydrated backing map when one already exists.- Overrides:
clonein classAbstractMap<String,Object> - Returns:
- a clone of the hydrated backing map, or
nullwhen still compact - Throws:
CloneNotSupportedException- never thrown by the current implementation
-
clearAndCopy
Copies the compact entries into a newLazyMapand clears this instance.- Returns:
- a copy containing the current compact entries
-
grow
public static <V> V[] grow(V[] array) Doubles the capacity of the supplied array while preserving its component type.- Type Parameters:
V- component type- Parameters:
array- array to grow- Returns:
- the expanded array
-