Class LazyBindings

  • All Implemented Interfaces:, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Object>, javax.script.Bindings
    Direct Known Subclasses:

    public class LazyBindings
    extends java.util.HashMap<java.lang.String,​java.lang.Object>
    implements javax.script.Bindings

    The LazyBindings wraps another map and dynamically provides entries for the wrapped map through a map of LazyBindings.Suppliers.

    When get(Object) is called with a key that's not present in the wrapped map, then the LazyBindings.Suppliers map will be queried and, if an entry exists for that key, the LazyBindings.Supplier-generated value will be used to populate the wrapped map.

    While the keySet() and containsKey(Object) will also check the keys present in the LazyBindings.Suppliers map, all other methods (e.g. values(), HashMap.containsValue(Object)) will only deal with the contents of the wrapped map.

    entrySet() will however return a merged view of both the LazyBindings.Suppliers and the wrapped map, so that copies to other LazyBindings maps preserve the functionality of having lazily-evaluated bindings.

    This class does not provide any thread-safety guarantees. If this Bindings map needs to be used in a concurrent setup it's the responsibility of the caller to synchronize access. The simplest way would be to wrap it through Collections.synchronizedMap(Map).

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  LazyBindings.Supplier
      This marker interface should be used for suppliers which should be unwrapped when used as values stored in a LazyBindings map.
      • 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>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      @NotNull java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()  
      boolean equals​(java.lang.Object o)  
      java.lang.Object get​(java.lang.Object key)  
      java.lang.Object getOrDefault​(java.lang.Object key, java.lang.Object defaultValue)  
      int hashCode()  
      boolean isEmpty()  
      @NotNull java.util.Set<java.lang.String> keySet()  
      java.lang.Object put​(java.lang.String key, java.lang.Object value)  
      void putAll​(java.util.Map<? extends java.lang.String,​?> toMerge)  
      java.lang.Object remove​(java.lang.Object key)  
      int size()  
      @NotNull java.util.Collection<java.lang.Object> values()  
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
      • Methods inherited from class java.util.AbstractMap

      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • LazyBindings

        public LazyBindings()
      • LazyBindings

        public LazyBindings​(java.util.Map<java.lang.String,​LazyBindings.Supplier> suppliers)
      • LazyBindings

        public LazyBindings​(java.util.Map<java.lang.String,​LazyBindings.Supplier> suppliers,
                            java.util.Map<java.lang.String,​java.lang.Object> wrapped)
    • Method Detail

      • put

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.Object value)
        Specified by:
        put in interface javax.script.Bindings
        Specified by:
        put in interface java.util.Map<java.lang.String,​java.lang.Object>
        put in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​?> toMerge)
        Specified by:
        putAll in interface javax.script.Bindings
        Specified by:
        putAll in interface java.util.Map<java.lang.String,​java.lang.Object>
        putAll in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​java.lang.Object>
        clear in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • keySet

        public @NotNull java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​java.lang.Object>
        keySet in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • values

        public @NotNull 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.HashMap<java.lang.String,​java.lang.Object>
      • entrySet

        public @NotNull 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>
        entrySet in class java.util.HashMap<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.HashMap<java.lang.String,​java.lang.Object>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​java.lang.Object>
        isEmpty in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface javax.script.Bindings
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​java.lang.Object>
        containsKey in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • get

        public java.lang.Object get​(java.lang.Object key)
        Specified by:
        get in interface javax.script.Bindings
        Specified by:
        get in interface java.util.Map<java.lang.String,​java.lang.Object>
        get in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Specified by:
        remove in interface javax.script.Bindings
        Specified by:
        remove in interface java.util.Map<java.lang.String,​java.lang.Object>
        remove in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<java.lang.String,​java.lang.Object>
        equals in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
      • hashCode

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

        public java.lang.Object getOrDefault​(java.lang.Object key,
                                             java.lang.Object defaultValue)
        Specified by:
        getOrDefault in interface java.util.Map<java.lang.String,​java.lang.Object>
        getOrDefault in class java.util.HashMap<java.lang.String,​java.lang.Object>