Class Subst

java.lang.Object
eu.bandm.tools.format.Format
eu.bandm.tools.format.Subst
All Implemented Interfaces:
Formattable, Serializable, Cloneable

public class Subst extends Format
Allows to store a context as a scope in a format tree. Such a Context maps variable names and numbers to format values. The evaluation of this scope happens in course of the recursive descend of the Format.eval(eu.bandm.tools.format.Context, boolean) method.
See Also:
  • Constructor Details

    • Subst

      public Subst(Format body, Context context, boolean partial)
      Constructor which sets most object fields explicitly, except indent which is unset.
      Parameters:
      body - the format subtree for which this instance sets a scope.
      context - the variable definitions valid in this scope
      partial - whether variables are allowed which are not defined in the local context, but in some higher scope.
    • Subst

      public Subst(Format body, Context context, boolean partial, int indent)
      Constructor which sets all object fields explicitly.
      Parameters:
      body - the format subtree for which this instance sets a scope.
      context - the variable definitions valid in this scope
      partial - whether variables are allowed which are not defined in the local context, but in some higher scope.
      indent - the indentation value for printing of the subtree.
      Throws:
      IllegalArgumentException - if ident value not valid, see Format.checkValidIndent(int)
  • Method Details

    • getBody

      public final Format getBody()
      Return the format for which this scope is defined.
      Returns:
      the format for which this scope is defined.
    • getContext

      public final Context getContext()
      Return the definitions which are valid in this scope.
      Returns:
      the definitions which are valid in this scope.
    • getPartial

      public final boolean getPartial()
      Return whether the context defined here is intentionally partial.
      Returns:
      whether the context defined here is intentionally partial.
    • indent

      public Subst indent(int i)
      Description copied from class: Format
      Returns a clone of this with the new value of Format.indent.
      Specified by:
      indent in class Format
      Parameters:
      i - the new value for indent.
      Returns:
      an new format with identical values but i, or this, if i is its indent value.
    • doprint

      protected void doprint(FormatPrinter v)
      Description copied from class: Format
      Over-ridden by all sub-classes of Format, for performing the print operations.
      Specified by:
      doprint in class Format
      Parameters:
      v - realizes the dynamic context for printing
    • eval

      public Format eval(Context c, boolean partial)
      Return the result of replacing all variables with the bindings in the given context.. First the local context is evaluated against the current context, and then the execution descends with that evaluation result.
      Overrides:
      eval in class Format
      Parameters:
      c - defines the replacement for variables by name and number.
      partial - decides when a Variable not defined in the context is found: if true the Variable stays aunaltered; if false an IllegalArgumentException is thrown.
      Returns:
      a format with all or some variables replaced
      See Also:
    • debugPrefix

      public String debugPrefix(int n)
      Description copied from class: Format
      Deliver the concatenation of the text contents, limited by the given number of characters, approximately. Useful for debugging purpose.
      Specified by:
      debugPrefix in class Format
      Parameters:
      n - the maximal number of characters which can be generated per tree node.
      Returns:
      the concatenated, unformatted text contents.