Class Context

java.lang.Object
eu.bandm.tools.format.Context
All Implemented Interfaces:
Serializable

public class Context extends Object implements Serializable
Realizes a map of bindings for a collection of BoundVariables and FreeVariables. When this is applied to a Format, the Variables contained in the format are replaced by the according definitions in this instance. This application is started and performed by the method Format.eval(Context,boolean).

This class is not a subclass of Format and its instances are mutable.xs

See Also:
  • Field Details

  • Constructor Details

    • Context

      public Context()
      Construct a new empty instance.
    • Context

      public Context(Formattable... args)
      Construct a new instance with the arguments as the bindings for the first positions of BoundVariables.
      Parameters:
      args - vaues bound to the numbered variables.
    • Context

      public Context(String name, Formattable value)
      Construct a new instance with one binding of a named BoundVariable.
      Parameters:
      name - of the variable to bind.
      value - to which to bind the variable
  • Method Details

    • getFreeValues

      public Map<String,Formattable> getFreeValues()
      Return the bindings for FreeVariables, by their name. Allows to change this context's data.
      Returns:
      the bindings for FreeVariables, by their name.
    • getArguments

      public List<Formattable> getArguments()
      Return the bindings for BoundVariables, by their position index. Allows to change this context's data.
      Returns:
      the bindings for BoundVariables, by their position index.
    • put

      public void put(String name, Formattable value)
      Change this instance: add or overwrite a binding for a FreeVariable.
      Parameters:
      name - of the variable to bind.
      value - to which to bind the variable
    • toString

      public String toString()
      Return a textual represenation of all variable bindings.
      Overrides:
      toString in class Object
    • eval

      public Context eval(Context outer, boolean partial)
      Evaluates all values bound in this Context against the outer context given as parameter. If partial==false, they must completely be resolvable or else an Exception is thrown. Only if partial==true, the bindings of the outer context are copied to the result, as far as not overridden by the innner context, and the positional bindings of the outer context are appened to those of the inner context. (Thus the numeric definitions of the outer context appear in the result with higher numbers.)
      Parameters:
      outer - the context against variables contained in the values of this context shall be resolved
      partial - whether unresolved variables may survive in the values of this context and bindings of the outer context are copied to the result.
      Returns:
      a new context object
      Throws:
      IllegalArgumentException - if a variable is not defined and partial is false.