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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​Value> bindings()
      Returns an immutable view of the bindings of this.
      MapContext freeze()
      Freezes this.
      static MapContext fromString​(java.lang.String contextString)
      A convenience constructor which returns a map context from a string on the form name1:value1, name2:value2 ....
      Value get​(java.lang.String key)
      Returns the value of a key.
      com.yahoo.tensor.TensorType getType​(Reference key)
      Returns the type of the given value key, or null if it is not bound.
      java.util.Set<java.lang.String> names()
      Returns an unmodifiable map of the names of this
      void put​(java.lang.String key, Value value)
      Sets the value of a key.
      MapContext thawedCopy()
      Returns a new, modifiable context containing all the bindings of this
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MapContext

        public MapContext()
      • MapContext

        public MapContext​(Value missingValue)
      • MapContext

        public MapContext​(java.util.Map<java.lang.String,​Value> bindings)
      • MapContext

        public MapContext​(java.util.Map<java.lang.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​(java.lang.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​(java.lang.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 java.util.Map<java.lang.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 java.util.Set<java.lang.String> names()
        Returns an unmodifiable map of the names of this
        Overrides:
        names in class Context
        Returns:
        the set of all variable names.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromString

        public static MapContext fromString​(java.lang.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.