Package: org.apache.groovy.json.internal

## [Java] Class LazyMap

- org.apache.groovy.json.internal.LazyMap

-     public class LazyMap
      extends AbstractMap

  A map that defers creating its backing map, so the small objects that dominate JSON documents do not incur that overhead. Entries are held in parallel key/value arrays until the first lookup, or until the entry count passes the linear-scan threshold, whichever comes first.

- - ### Constructor Summary

    Constructors
    Constructor and 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.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `clear()` Clears the compact buffers or hydrated map, depending on the current state.
    `` | `public 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.
    `` | `public boolean` | `containsKey(Object key)` Hydrates the backing map if needed and tests whether the key is present.
    `` | `public boolean` | `containsValue(Object value)` Hydrates the backing map if needed and tests whether the value is present.
    `` | `public Set<Entry<String, Object>>` | `entrySet()` Returns the hydrated entry set, building the backing map if necessary.
    `` | `public boolean` | `equals(Object o)` Hydrates the backing map if needed and compares it with another object.
    `` | `public Object` | `get(Object key)` Hydrates the backing map if needed and returns the value for the supplied key.
    `<V>` | `public static V[]` | `grow(V[] array)` Doubles the capacity of the supplied array while preserving its component type.
    `` | `public int` | `hashCode()` Hydrates the backing map if needed and returns its hash code.
    `` | `public boolean` | `isEmpty()` Returns whether the map currently contains any entries.
    `` | `public Set<String>` | `keySet()` Hydrates the backing map if needed and returns its key set.
    `` | `public Object` | `put(String key, Object value)` Stores a mapping while keeping the compact array-backed representation until hydration is needed.
    `` | `public void` | `putAll(Map m)` Hydrates the backing map if needed and copies all supplied entries into it.
    `` | `public Object` | `remove(Object key)` Hydrates the backing map if needed and removes the supplied key.
    `` | `public int` | `size()` Returns the current size without hydrating when the compact representation is still active.
    `` | `public String` | `toString()` Hydrates the backing map if needed and returns its string form.
    `` | `public Collection<Object>` | `values()` Hydrates the backing map if needed and returns its values collection.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class AbstractMap` | `clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getClass, getOrDefault, hashCode, isEmpty, keySet, merge, notify, notifyAll, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, toString, values, wait, wait, wait`

- - ### Constructor Detail

    - #### public LazyMap()

      Creates a lazy map with the default key and value buffer size.

    - #### public LazyMap(int initialSize)

      Creates a lazy map with a caller-supplied key and value buffer size.

      Parameters:
        `initialSize` - initial buffer size

  - ### Method Detail

    - #### public void clear()

      Clears the compact buffers or hydrated map, depending on the current state.

    - #### public LazyMap clearAndCopy()

      Copies the compact entries into a new `LazyMap` and clears this instance.

      Returns:
        a copy containing the current compact entries

    - #### protected Object clone()

      Clones the hydrated backing map when one already exists.

      throws:
        CloneNotSupportedException never thrown by the current implementation
      Returns:
        a clone of the hydrated backing map, or `null` when still compact

    - #### public boolean containsKey(Object key)

      Hydrates the backing map if needed and tests whether the key is present.

      Parameters:
        `key` - key to test
      Returns:
        `true` when the key is present

    - #### public boolean containsValue(Object value)

      Hydrates the backing map if needed and tests whether the value is present.

      Parameters:
        `value` - value to test
      Returns:
        `true` when the value is present

    - #### public Set<Entry<String, Object>> entrySet()

      Returns the hydrated entry set, building the backing map if necessary.

      Returns:
        hydrated entry set

    - #### public boolean equals(Object o)

      Hydrates the backing map if needed and compares it with another object.

      Parameters:
        `o` - other object
      Returns:
        `true` when equal

    - #### public Object get(Object key)

      Hydrates the backing map if needed and returns the value for the supplied key.

      Parameters:
        `key` - key to look up
      Returns:
        mapped value, or `null`

    - #### <V> public static V[] grow(V[] array)

      Doubles the capacity of the supplied array while preserving its component type.

      Parameters:
        `array` - array to grow
      Type Parameters:
        `V` - component type
      Returns:
        the expanded array

    - #### public int hashCode()

      Hydrates the backing map if needed and returns its hash code.

      Returns:
        hydrated hash code

    - #### public boolean isEmpty()

      Returns whether the map currently contains any entries.

      Returns:
        `true` when no entries are stored

    - #### public Set<String> keySet()

      Hydrates the backing map if needed and returns its key set.

      Returns:
        hydrated key set

    - #### public Object put(String key, Object value)

      Stores a mapping while keeping the compact array-backed representation until hydration is needed. Once the entry count passes the linear-scan threshold, the backing map is built and delegated to, keeping insertion amortized constant-time for wide objects.

      Parameters:
        `key` - entry key
        `value` - entry value
      Returns:
        previous value for `key`, or `null`

    - #### public void putAll(Map m)

      Hydrates the backing map if needed and copies all supplied entries into it.

      Parameters:
        `m` - entries to copy

    - #### public Object remove(Object key)

      Hydrates the backing map if needed and removes the supplied key.

      Parameters:
        `key` - key to remove
      Returns:
        removed value, or `null`

    - #### public int size()

      Returns the current size without hydrating when the compact representation is still active.

      Returns:
        map size

    - #### public String toString()

      Hydrates the backing map if needed and returns its string form.

      Returns:
        hydrated map text

    - #### public Collection<Object> values()

      Hydrates the backing map if needed and returns its values collection.

      Returns:
        hydrated values collection