Class MapContext

  • All Implemented Interfaces:
    com.yahoo.tensor.evaluation.EvaluationContext<Reference>, com.yahoo.tensor.evaluation.TypeContext<Reference>

    public class MapContext
    extends Context
    A context backed by a Map
    Author:
    bratseth
    • Constructor Detail

      • MapContext

        public MapContext()
      • MapContext

        public MapContext​(Value missingValue)
      • MapContext

        public MapContext​(Map<String,​Value> bindings,
                          Value missingValue)
        Creates a map context from a map. All the Values of the map will be frozen.
    • Method Detail

      • freeze

        public MapContext freeze()
        Freezes this. Returns this for convenience.
      • getType

        public com.yahoo.tensor.TensorType getType​(Reference key)
        Returns the type of the given value key, or null if it is not bound.
      • get

        public Value get​(String key)
        Returns the value of a key. 0 is returned if the given key is not bound in this.
        Specified by:
        get in class Context
        Parameters:
        key - the name of the variable whose value to return.
        Returns:
        the value of the named variable.
      • put

        public void put​(String key,
                        Value value)
        Sets the value of a key. The value is frozen by this.
        Overrides:
        put in class Context
        Parameters:
        key - the name of the variable to set.
        value - the value to set. Ownership of this value is transferred to this - if it is mutable (not frozen) it may be modified during execution
      • bindings

        public Map<String,​Value> bindings()
        Returns an immutable view of the bindings of this.
      • thawedCopy

        public MapContext thawedCopy()
        Returns a new, modifiable context containing all the bindings of this
      • names

        public Set<String> names()
        Returns an unmodifiable map of the names of this
        Overrides:
        names in class Context
        Returns:
        the set of all variable names.
      • fromString

        public static MapContext fromString​(String contextString)
        A convenience constructor which returns a map context from a string on the form name1:value1, name2:value2 .... Extra spaces are allowed anywhere. Any other deviation from the syntax causes an exception to be thrown.