Package eu.bandm.tools.format
Class Context
java.lang.Object
eu.bandm.tools.format.Context
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionfinal List<Formattable> The bindings forBoundVariables, by their position index. -
Constructor Summary
ConstructorsConstructorDescriptionContext()Construct a new empty instance.Context(Formattable... args) Construct a new instance with the arguments as the bindings for the first positions ofBoundVariables.Context(String name, Formattable value) Construct a new instance with one binding of a namedBoundVariable. -
Method Summary
Modifier and TypeMethodDescriptionEvaluates all values bound in this Context against the outer context given as parameter.Return the bindings forBoundVariables, by their position index.Return the bindings forFreeVariables, by their name.voidput(String name, Formattable value) Change this instance: add or overwrite a binding for aFreeVariable.toString()Return a textual represenation of all variable bindings.
-
Field Details
-
arguments
The bindings forBoundVariables, by their position index.
-
-
Constructor Details
-
Context
public Context()Construct a new empty instance. -
Context
Construct a new instance with the arguments as the bindings for the first positions ofBoundVariables.- Parameters:
args- vaues bound to the numbered variables.
-
Context
Construct a new instance with one binding of a namedBoundVariable.- Parameters:
name- of the variable to bind.value- to which to bind the variable
-
-
Method Details
-
getFreeValues
Return the bindings forFreeVariables, by their name. Allows to change this context's data.- Returns:
- the bindings for
FreeVariables, by their name.
-
getArguments
Return the bindings forBoundVariables, by their position index. Allows to change this context's data.- Returns:
- the bindings for
BoundVariables, by their position index.
-
put
Change this instance: add or overwrite a binding for aFreeVariable.- Parameters:
name- of the variable to bind.value- to which to bind the variable
-
toString
Return a textual represenation of all variable bindings. -
eval
Evaluates all values bound in this Context against the outer context given as parameter. Ifpartial==false, they must completely be resolvable or else an Exception is thrown. Only ifpartial==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 resolvedpartial- 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 andpartialis false.
-