Package org.apache.groovy.json.internal

# Class LazyValueMap

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

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

public class LazyValueMap extends AbstractMap<String,Object> implements ValueMap<String,Object>
This class is important to the performance of the parser. It stores Value objects in a map where they are evaluated lazily. This is great for JSONPath types of application, and Object Serialization but not for maps that are going to be stored in a cache.

This is because the Value construct is a type of index overlay that merely tracks where the token is located in the buffer, and what if any thing we noted about it (like can be converted to a decimal number, etc.).

To mitigate memory leaks this class along with CharSequenceValue implement two constructs, namely, chop, and lazyChop.

A chop is when we convert backing buffer of a Value object into a smaller buffer. A lazyChop is when we do a chop but only when a get operation is called.

The lazyChop is performed on the tree that is touched by the JSONPath expression or its ilk.

The chop operation can be done during parsing or lazily by storing the values in this construct.

- ## 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
  `LazyValueMap(boolean lazyChop)`
  Creates a lazy map with the default item buffer size.
  `LazyValueMap(boolean lazyChop, int initialSize)`
  Creates a lazy map with a caller-supplied item buffer size.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `add(MapItemValue miv)`
  Adds a new MapItemValue to the mapping.
  `final void`
  `chopMap()`
  Chop this map.
  `Set<Map.Entry<String,Object>>`
  `entrySet()`
  Returns the hydrated entry set, building the backing map if necessary.
  `final Object`
  `get(Object key)`
  Gets the item by key from the mapping.
  `boolean`
  `hydrated()`
  Has the map been hydrated.
  `Map.Entry<String,Value>[]`
  `items()`
  Give me the items in the map without hydrating the map.
  `int`
  `len()`
  Return size w/o hydrating the map.
  `Value`
  `put(String key, Object value)`
  Unsupported because parser-created entries are appended through `add(MapItemValue)`.
  `int`
  `size()`
  Returns the hydrated map size, building the backing map if necessary.
  `String`
  `toString()`
  Returns the hydrated map string form, building the backing map if necessary.
  `Collection<Object>`
  `values()`
  Returns the hydrated values collection, building the backing map if necessary.

  ### Methods inherited from class java.util.AbstractMap

  `clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, remove`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Map

  `clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll`

- ## Constructor Details

  - ### LazyValueMap

    public LazyValueMap(boolean lazyChop)
    Creates a lazy map with the default item buffer size.
    Parameters:
      `lazyChop` - whether touched branches should be chopped on access

  - ### LazyValueMap

    public LazyValueMap(boolean lazyChop, int initialSize)
    Creates a lazy map with a caller-supplied item buffer size.
    Parameters:
      `lazyChop` - whether touched branches should be chopped on access
      `initialSize` - initial item buffer size

- ## Method Details

  - ### add

    public final void add(MapItemValue miv)
    Adds a new MapItemValue to the mapping.
    Specified by:
      `add` in interface `ValueMap<String,Object>`
    Parameters:
      `miv` - miv we are adding.

  - ### get

    public final Object get(Object key)
    Gets the item by key from the mapping.
    Specified by:
      `get` in interface `Map<String,Object>`
    Overrides:
      `get` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - to lookup
    Returns:
      the item for the given key

  - ### chopMap

    public final void chopMap()
    Chop this map.

  - ### put

    public Value put(String key, Object value)
    Unsupported because parser-created entries are appended through `add(MapItemValue)`.
    Specified by:
      `put` in interface `Map<String,Object>`
    Overrides:
      `put` in class `AbstractMap<String,Object>`
    Parameters:
      `key` - ignored
      `value` - ignored
    Returns:
      never returns normally

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

  - ### values

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

  - ### size

    public int size()
    Returns the hydrated map size, building the backing map if necessary.
    Specified by:
      `size` in interface `Map<String,Object>`
    Overrides:
      `size` in class `AbstractMap<String,Object>`
    Returns:
      hydrated size

  - ### toString

    public String toString()
    Returns the hydrated map string form, building the backing map if necessary.
    Overrides:
      `toString` in class `AbstractMap<String,Object>`
    Returns:
      hydrated map text

  - ### len

    public int len()
    Return size w/o hydrating the map.
    Specified by:
      `len` in interface `ValueMap<String,Object>`

  - ### hydrated

    public boolean hydrated()
    Has the map been hydrated.
    Specified by:
      `hydrated` in interface `ValueMap<String,Object>`

  - ### items

    public Map.Entry<String,Value>[] items()
    Give me the items in the map without hydrating the map. Realize that the array is likely larger than the length so array items can be null.
    Specified by:
      `items` in interface `ValueMap<String,Object>`