Class Compound

java.lang.Object
eu.bandm.tools.format.Format
eu.bandm.tools.format.Compound
All Implemented Interfaces:
Formattable, Serializable, Cloneable
Direct Known Subclasses:
Append, Beneath, Beside, Block, Comment, Line, Tabular

public abstract class Compound extends Format
The base class for all formats which combine subformats.
See Also:
  • Constructor Details

    • Compound

      protected Compound(List<Format> f)
      A constructor with some field values explicit, some calculated from the subformats. In contrast to the factory methods, denormalized instances may be constructed.

      Minimal and maximal widths, whether always multiline and whether variables are contained, is all calculated from the subformats. Indentation is not set.

      Parameters:
      f - list of sub-formats, should not be empty
    • Compound

      protected Compound(int i, int a, List<Format> f)
      A constructor with some field values explicit, some calculated from the subformats. In contrast to the factory methods, denormalized instances may be constructed.

      Whether always multiline and whether variables are contained, is calculated from the subformats. Indentation is not set.

      Parameters:
      i - minwidth
      a - maxnwidth
      f - list of sub-formats, should not be empty
    • Compound

      protected Compound(int i, int a, boolean m, List<Format> f)
      A constructor with some field values explicit, some calculated from the subformats. In contrast to the factory methods, denormalized instances may be constructed.

      Whether ariables are contained, is calculated from the subformats. Indentation is not set.

      Parameters:
      i - minwidth
      a - maxnwidth
      m - isMultiLine
      f - list of sub-formats, should not be empty
    • Compound

      protected Compound(int i, int a, boolean m, boolean g, int indent, List<Format> f)
      The constructor which sets all field values explicitly. Consistency of the attributes must be realized by the caller. In contrast to the factory methods, denormalized instances may be constructed.
      Parameters:
      i - minimal width
      a - maximal width
      m - is always multiLine
      g - is ground
      indent - indentation
      f - list of sub-formats, should not be empty
      Throws:
      IllegalArgumentException - if ident value not valid, see Format.checkValidIndent(int)
  • Method Details

    • getSubs

      public List<Format> getSubs()
      Return all subformats. This list is unmodifiable.
      Returns:
      all subformats. This list is unmodifiable.
    • constructor

      public abstract CompoundConstructor constructor()
      Returns the reification of the constructor of this instance. That enum type has "apply()" methods which generate a corresponding instance.
      Returns:
      the reification of the constructor of this instance.
    • indent

      public Compound 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.
    • mutate

      public Format mutate(Consumer<List<Format>> mapSubs)
      Creates a new instance of the same class as this instance, or an optimized variant. which contains as subformats all formats in a modified list. The list is modified arbitrarily in an "imperative" way, i.e. it can be altered or extended or totally cleared.

      The resulting list is fed into a factory method; therefore optimization applies and the returned type can be the singleton contents or an instance of Empty.

      Parameters:
      mapSubs - the code to apply to the list of all subformats
      Returns:
      a new format which contains the all formats in the modified list
    • eval

      public Format eval(Context c, boolean partial)
      Description copied from class: Format
      Return the result of replacing all variables with the bindings in the given context.
      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
    • 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.