Class LazyValueMap

All Implemented Interfaces:
java.util.Map<java.lang.String,​java.lang.Object>, ValueMap<java.lang.String,​java.lang.Object>

public class LazyValueMap
extends java.util.AbstractMap<java.lang.String,​java.lang.Object>
implements ValueMap<java.lang.String,​java.lang.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

    java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>

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

    java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
  • Constructor Summary

    Constructor Description
    LazyValueMap​(boolean lazyChop)  
    LazyValueMap​(boolean lazyChop, int initialSize)  
  • Method Summary

    Modifier and Type Method Description
    void add​(MapItemValue miv)
    Adds a new MapItemValue to the mapping.
    void chopMap()
    Chop this map.
    java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()  
    java.lang.Object get​(java.lang.Object key)
    Gets the item by key from the mapping.
    boolean hydrated()
    Has the map been hydrated.
    java.util.Map.Entry<java.lang.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​(java.lang.String key, java.lang.Object value)  
    int size()  
    java.lang.String toString()  
    java.util.Collection<java.lang.Object> values()  

    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)
    • LazyValueMap

      public LazyValueMap​(boolean lazyChop, int initialSize)
  • Method Details

    • add

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

      public final java.lang.Object get​(java.lang.Object key)
      Gets the item by key from the mapping.
      Specified by:
      get in interface java.util.Map<java.lang.String,​java.lang.Object>
      get in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
      key - to lookup
      the item for the given key
    • chopMap

      public final void chopMap()
      Chop this map.
    • put

      public Value put​(java.lang.String key, java.lang.Object value)
      Specified by:
      put in interface java.util.Map<java.lang.String,​java.lang.Object>
      put in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
    • entrySet

      public java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()
      Specified by:
      entrySet in interface java.util.Map<java.lang.String,​java.lang.Object>
      Specified by:
      entrySet in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
    • values

      public java.util.Collection<java.lang.Object> values()
      Specified by:
      values in interface java.util.Map<java.lang.String,​java.lang.Object>
      values in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
    • size

      public int size()
      Specified by:
      size in interface java.util.Map<java.lang.String,​java.lang.Object>
      size in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
    • toString

      public java.lang.String toString()
      toString in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
    • len

      public int len()
      Description copied from interface: ValueMap
      Return size w/o hydrating the map.
      Specified by:
      len in interface ValueMap<java.lang.String,​java.lang.Object>
    • hydrated

      public boolean hydrated()
      Description copied from interface: ValueMap
      Has the map been hydrated.
      Specified by:
      hydrated in interface ValueMap<java.lang.String,​java.lang.Object>
    • items

      public java.util.Map.Entry<java.lang.String,​Value>[] items()
      Description copied from interface: ValueMap
      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<java.lang.String,​java.lang.Object>