Package org.apache.groovy.json.internal

# Class LazyMap

java.lang.Object
java.util.AbstractMap<String,Object>
org.apache.groovy.json.internal.LazyMap

All Implemented Interfaces:
  `Map<String,Object>`

public class LazyMap extends AbstractMap<String,Object>
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>`

  ## Nested classes/interfaces inherited from interface java.util.Map

  `Map.Entry<K extends Object,V extends Object>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LazyMap()`
  Creates a lazy map with the default key and value buffer size.
  `LazyMap(int initialSize)`
  Creates a lazy map with a caller-supplied key and value buffer size.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Clears the compact buffers or hydrated map, depending on the current state.
  `LazyMap`
  `clearAndCopy()`
  Copies the compact entries into a new `LazyMap` and clears this instance.
  `protected Object`
  `clone()`
  Clones the hydrated backing map when one already exists.
  `boolean`
  `containsKey(Object key)`
  Hydrates the backing map if needed and tests whether the key is present.
  `boolean`
  `containsValue(Object value)`
  Hydrates the backing map if needed and tests whether the value is present.
  `Set<Map.Entry<String,Object>>`
  `entrySet()`
  Returns the hydrated entry set, building the backing map if necessary.
  `boolean`
  `equals(Object o)`
  Hydrates the backing map if needed and compares it with another object.
  `Object`
  `get(Object key)`
  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.
  `int`
  `hashCode()`
  Hydrates the backing map if needed and returns its hash code.
  `boolean`
  `isEmpty()`
  Returns whether the map currently contains any entries.
  `Set<String>`
  `keySet()`
  Hydrates the backing map if needed and returns its key set.
  `Object`
  `put(String key, Object value)`
  Stores a mapping while keeping the compact array-backed representation until hydration is needed.
  `void`
  `putAll(Map m)`
  Hydrates the backing map if needed and copies all supplied entries into it.
  `Object`
  `remove(Object key)`
  Hydrates the backing map if needed and removes the supplied key.
  `int`
  `size()`
  Returns the current size without hydrating when the compact representation is still active.
  `String`
  `toString()`
  Hydrates the backing map if needed and returns its string form.
  `Collection<Object>`
  `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, wait`

  ### Methods 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

    public Object put(String key, Object value)
    Stores a mapping while keeping the compact array-backed representation until hydration is needed.
    Specified by:
      `put` in interface `Map<String,Object>`
    Overrides:
      `put` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - entry key
      `value` - entry value
    Returns:
      previous value for `key`, or `null`

  - ### entrySet

    public Set<Map.Entry<String,Object>> entrySet()
    Returns the hydrated entry set, building the backing map if necessary.
    Specified by:
      `entrySet` in interface `Map<String,Object>`
    Specified by:
      `entrySet` in class `AbstractMap<String,Object>`
    Returns:
      hydrated entry set

  - ### size

    public int size()
    Returns the current size without hydrating when the compact representation is still active.
    Specified by:
      `size` in interface `Map<String,Object>`
    Overrides:
      `size` in class `AbstractMap<String,Object>`
    Returns:
      map size

  - ### isEmpty

    public boolean isEmpty()
    Returns whether the map currently contains any entries.
    Specified by:
      `isEmpty` in interface `Map<String,Object>`
    Overrides:
      `isEmpty` in class `AbstractMap<String,Object>`
    Returns:
      `true` when no entries are stored

  - ### containsValue

    public boolean containsValue(Object value)
    Hydrates the backing map if needed and tests whether the value is present.
    Specified by:
      `containsValue` in interface `Map<String,Object>`
    Overrides:
      `containsValue` in class `AbstractMap<String,Object>`
    Parameters:
      `value` - value to test
    Returns:
      `true` when the value is present

  - ### containsKey

    public boolean containsKey(Object key)
    Hydrates the backing map if needed and tests whether the key is present.
    Specified by:
      `containsKey` in interface `Map<String,Object>`
    Overrides:
      `containsKey` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - key to test
    Returns:
      `true` when the key is present

  - ### get

    public Object get(Object key)
    Hydrates the backing map if needed and returns the value for the supplied key.
    Specified by:
      `get` in interface `Map<String,Object>`
    Overrides:
      `get` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - key to look up
    Returns:
      mapped value, or `null`

  - ### remove

    public Object remove(Object key)
    Hydrates the backing map if needed and removes the supplied key.
    Specified by:
      `remove` in interface `Map<String,Object>`
    Overrides:
      `remove` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - key to remove
    Returns:
      removed value, or `null`

  - ### putAll

    public void putAll(Map m)
    Hydrates the backing map if needed and copies all supplied entries into it.
    Specified by:
      `putAll` in interface `Map<String,Object>`
    Overrides:
      `putAll` in class `AbstractMap<String,Object>`
    Parameters:
      `m` - entries to copy

  - ### clear

    public void clear()
    Clears the compact buffers or hydrated map, depending on the current state.
    Specified by:
      `clear` in interface `Map<String,Object>`
    Overrides:
      `clear` in class `AbstractMap<String,Object>`

  - ### keySet

    public Set<String> keySet()
    Hydrates the backing map if needed and returns its key set.
    Specified by:
      `keySet` in interface `Map<String,Object>`
    Overrides:
      `keySet` in class `AbstractMap<String,Object>`
    Returns:
      hydrated key set

  - ### values

    public Collection<Object> values()
    Hydrates the backing map if needed and returns its values collection.
    Specified by:
      `values` in interface `Map<String,Object>`
    Overrides:
      `values` in class `AbstractMap<String,Object>`
    Returns:
      hydrated values collection

  - ### equals

    public boolean equals(Object o)
    Hydrates the backing map if needed and compares it with another object.
    Specified by:
      `equals` in interface `Map<String,Object>`
    Overrides:
      `equals` in class `AbstractMap<String,Object>`
    Parameters:
      `o` - other object
    Returns:
      `true` when equal

  - ### hashCode

    public int hashCode()
    Hydrates the backing map if needed and returns its hash code.
    Specified by:
      `hashCode` in interface `Map<String,Object>`
    Overrides:
      `hashCode` in class `AbstractMap<String,Object>`
    Returns:
      hydrated hash code

  - ### toString

    public String toString()
    Hydrates the backing map if needed and returns its string form.
    Overrides:
      `toString` in class `AbstractMap<String,Object>`
    Returns:
      hydrated map text

  - ### clone

    protected Object clone() throws CloneNotSupportedException
    Clones the hydrated backing map when one already exists.
    Overrides:
      `clone` in class `AbstractMap<String,Object>`
    Returns:
      a clone of the hydrated backing map, or `null` when still compact
    Throws:
      `CloneNotSupportedException` - never thrown by the current implementation

  - ### clearAndCopy

    public LazyMap clearAndCopy()
    Copies the compact entries into a new `LazyMap` and 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