Class Format

java.lang.Object
eu.bandm.tools.format.Format
All Implemented Interfaces:
Formattable, Serializable, Cloneable
Direct Known Subclasses:
Annotated, Compound, Empty, Literal, Markup, Prior, Space, Subst, Variable

public abstract class Format extends Object implements Cloneable, Serializable, Formattable
Base class for all kinds of format objects, and their factory class.

For a detailed description of the concepts see the user documentation.

Format objects have algebraic semantics, they are implemented immutable. They are created by invoking the static factory methods contained in this class. Once created, they cannot be modified. Therefore complicated structures can be shared and reused.

The attributes of a format object are calculated once at creation time and never need update. They are implemented as public final fields. If modifications are necessary, they are done by cloning, i.e. creating new instances. The subclass Compound is superclass of all Formats which combine several formats (horizontally, vertically, etc.) It provides methods for cloning and re-calculating of the internal attributes. The static factory methods contained herein (like append(List), append(Format[]), block(List), block(Format[]), line(List), beside(List), beneath(List), tabular(List), comment(String,String,String,List), etc.) will all create only compounds with non-denormalized contents, i.e. with more than one contained Format. But also denormalized instances of compound subclasses (with zero or one component) will be displayed correctly.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Format
    A literal format containing a comma »,«.
    static final int
    Default page width used by printFormat(PrintWriter)
    static final Format
    A literal format containing a dot ».«.
    static final Format
    A constant reference to an empty format.
    final int
    The indentation value explicitly assigned by the user.
    static final int
    Default value for indentation, meaning no explicit specification.
    protected static final int
    Length of common class name prefix, which can be suppressed in debug output.
    static final Format
    A space of one(1) column or line.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Format(int i, int a, boolean mult, boolean ground)
    Protected constructor, setting all fields of the Format definition, but leaving the indentation unset.
    protected
    Format(int i, int a, boolean mult, boolean ground, int indent)
    Protected constructor, setting all fields of the Format definition.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A> Format
    annotated(Format format, A annotation)
    Creates an annotated format.
    static Format
    append(Format... f)
    Returns (in most cases) a new append format with the given contents.
    static Format
    append(List<@Opt ? extends Format> f)
    Returns (in most cases) a new append format with the given contents.
    static Format
    apply(Format body, Context c, boolean partial)
    Returns the format which results from replacing all Variables by their binding defined in context c, if any.
    static Format
    apply(Format body, Format... args)
    Returns the format which results from replacing all bound (=numeric) variables by the argument on the position given by their number.
    static Format
    apply(Format body, Formattable... args)
    Returns the format which results from replacing all bound (=numeric) variables by the argument on the position given by their number.
    static Format
    apply(Format body, String name, Format value)
    Returns the format which results from replacing all FreeVariable with the given name by the given value.
    final Format
    Resolve all bound (=numbered) variables in this format against the list of arguments.
    final Format
    applyTo(Format... args)
    Resolve all bound (=numbered) variables in this format against the list of arguments.
    final Format
    Resolve all bound (=numbered) variables in this format against the list of arguments.
    static Format
    Returns (in most cases) a new beneath format with the given contents.
    static Format
    beneath(List<@Opt ? extends Format> f)
    Returns (in most cases) a new beneath format with the given contents.
    static Format
    beside(Format... f)
    Returns (in most cases) a new beside format with the given contents.
    static Format
    beside(List<@Opt ? extends Format> f)
    Returns (in most cases) a new beside format with the given contents.
    static Format
    block(Format... f)
    Returns (in most cases) a new block format with the given contents.
    static Format
    block(List<@Opt ? extends Format> f)
    Returns (in most cases) a new block format with the given contents.
    static void
     
    static Format
    comment(@Opt String prefix, String linePrefix, @Opt String suffix, Format... f)
    Creates an comment format.
    static Format
    comment(@Opt String prefix, String linePrefix, @Opt String suffix, List<@Opt ? extends Format> f)
    Creates a comment format.
    static Format
    comment(String linePrefix, Format... f)
    Creates an comment format.
    static Format
    comment(String linePrefix, List<? extends Format> f)
    Creates an comment format.
    abstract String
    debugPrefix(int n)
    Deliver the concatenation of the text contents, limited by the given number of characters, approximately.
    protected abstract void
    Over-ridden by all sub-classes of Format, for performing the print operations.
    eval(Context c, boolean partial)
    Return the result of replacing all variables with the bindings in the given context.
    final Format
    Any instance of Format is its own formatting result.
    int
    Returns the indentation value explicitly assigned by the user.
    boolean
    Returns whether this format does not contain variables.
    abstract Format
    indent(int i)
    Returns a clone of this with the new value of indent.
    protected boolean
    Whether this indentation value is a specific one.
    boolean
    Returns whether this format contains any Beneath format.
    protected boolean
    Whether this format is a space.
    static Format
    line(Format... f)
    Returns (in most cases) a new line format with the given contents.
    static Format
    line(List<@Opt ? extends Format> f)
    Returns (in most cases) a new line format with the given contents.
    static Format
    Create a literal or return an already cached one.
    static Format
    Creates a mark-up format.
    static Format
    Creates a mark-up format.
    static Format
    Creates a mark-up format.
    protected static int
    Calculate the maximum of the minWidth fields of all Formats in subs.
    int
    Return the maximal width, ie reflects the printing situation where no single contained optional line-break contained in (the sub-formats of) this format is realized.
    int
    Return the minimal width if not directly at start of line, ie respecting blanks and not including indentation.
    static Format
    of(Object thing)
    Returns a format which represents the argument as a textual representation.
    void
    Service point: print this format.
    void
    printFormat(PrintWriter pw, int width)
    Service point: print this format with the given line width.
    void
    Service point: print this format without any formatting.
    static Format
    prior(int level, int alternative, Format noparens, Format parens)
    Creates a priority-controlled format, which is rendered differently, according to its relative positions to ancestor formats of this class.
    static Format
    prior(int level, Format noparens, Format parens)
    Creates a priority-controlled format, which is rendered differently, according to its relative positions to ancestor formats of this class.
    Returns a text representation of the attributes of a format.
     
    showLn(int depth)
    Creates a debugging representation of a Format term, restricted to show only the top "depth" levels.
    static Format
    space(int i)
    Creates a space format.
    static Format
    subst(Format body, Context c, boolean partial)
    Creates a scope which imposes the given variable substitutions on a subtree of formats.
    static Format
    subst(Format body, Format... args)
    Creates a scope which imposes the given variable substitutions on a subtree of formats.
    static Format
    subst(Format body, String name, Format value)
    Creates a new scope in which the variable with the given name is bound to the given Format value.
    static Format
    Calls makeTabular(java.util.List<eu.bandm.tools.format.Format>) while ignoring all empty formats and null pointers contained in the argument list.
    static Format
    tabular(List<@Opt ? extends Format> f)
    Calls makeTabular(java.util.List<eu.bandm.tools.format.Format>) while ignoring all empty formats and null pointers contained in the argument list.
    Call toString from the Object superclass, for debugging only.
    Convert a format without any formatting.
    toString(int width)
    Print the format in a formatted way to a string (include linefeeds), with the specified maximal column width.
    static Format
    variable(int index)
    Creates a new BoundVariable with the given number.
    static Format
    Creates a new FreeVariable with the given name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • comma

      public static final Format comma
      A literal format containing a comma »,«.
    • dot

      public static final Format dot
      A literal format containing a dot ».«.
    • space

      public static final Format space
      A space of one(1) column or line.
    • empty

      public static final Format empty
      A constant reference to an empty format.
    • LENGTH_PREFIX

      protected static final int LENGTH_PREFIX
      Length of common class name prefix, which can be suppressed in debug output.
    • INDENT_NOT_SET

      public static final int INDENT_NOT_SET
      Default value for indentation, meaning no explicit specification.
      See Also:
    • indent

      public final int indent
      The indentation value explicitly assigned by the user. This will determine the number of spaces the format will begin further to the right then the beginning of its immediate container, iff the format is the first in an output line. Allowed values are greater or equal zero.
    • DEFAULT_WIDTH

      public static final int DEFAULT_WIDTH
      Default page width used by printFormat(PrintWriter)
      See Also:
  • Constructor Details

    • Format

      protected Format(int i, int a, boolean mult, boolean ground, int indent)
      Protected constructor, setting all fields of the Format definition. This should not be called spontaneously by the user, because the caller is responsible for the consistency of all parameters.
      Parameters:
      i - the minimal width of the format
      a - the maximal width of the format
      mult - whether the format will print to multiple lines anyhow
      ground - whether the format does not contain any variable
      indent - the indentation value of this format
      Throws:
      IllegalArgumentException - if ident value not valid, see checkValidIndent(int)
    • Format

      protected Format(int i, int a, boolean mult, boolean ground)
      Protected constructor, setting all fields of the Format definition, but leaving the indentation unset.
      Parameters:
      i - the minimal width of the format
      a - the maximal width of the format
      mult - whether the format will print to multiple lines anyhow
      ground - whether the format does not contain any variable
      See Also:
  • Method Details

    • format

      public final Format format()
      Any instance of Format is its own formatting result.
      Specified by:
      format in interface Formattable
      Returns:
      This instance, which already is a format.
    • of

      public static Format of(Object thing)
      Returns a format which represents the argument as a textual representation. If the argument implements Formattable or FormatClient, the methods defined with these types are used. As a fall-back, the Java Object.toString() method is used; from the result, a Literal is constructed.
      Parameters:
      thing - to convert into a format
      Returns:
      a format which represents the argument textually.
    • server

      public static FormatServer<Format> server()
    • literal

      public static Format literal(String s)
      Create a literal or return an already cached one. This factory method uses literalCache and is thus synchronized. Empty content will be translated into an empty format; whitespace only into a space format. Tab and linefeed characters are rejected.
      Parameters:
      s - the text to be contained in the literal
      Returns:
      a new literal format instance, or the empty instance if and only if the argument is empty.
      Throws:
      IllegalArgumentException - if the text contains forbidden characters as defined by Literal.ILLEGAL_CONTENTS.
      See Also:
    • markup

      public static Format markup(String s)
      Creates a mark-up format. A mark-up format is rendered under the assumption that it does not occupy any space. This method is the same as markupLeft(String).
      Parameters:
      s - the text to be printed as mark-up (in case of XML, including the parentheses.
      Returns:
      a markup format
    • markupRight

      public static Format markupRight(String s)
      Creates a mark-up format. A mark-up format is rendered under the assumption that it does not occupy any space. This markup is assumed to stand right to its contents, like an XML "close tag".
      Parameters:
      s - the text to be printed as mark-up (in case of XML, including the parentheses.
      Returns:
      a markup format
    • markupLeft

      public static Format markupLeft(String s)
      Creates a mark-up format. A mark-up format is rendered under the assumption that it does not occupy any space. This markup is assumed to stand left to its contents, like an XML "open tag".
      Parameters:
      s - the text to be printed as mark-up (in case of XML, including the parentheses.)
      Returns:
      a markup format
    • space

      public static Format space(int i)
      Creates a space format.
      Parameters:
      i - the number of space characters contained, must be larger than zero.
      Returns:
      a space format, or an empty format if the argument is zero.
      Throws:
      IllegalArgumentException - if the argument is smaller than one.
    • prior

      public static Format prior(int level, Format noparens, Format parens)
      Creates a priority-controlled format, which is rendered differently, according to its relative positions to ancestor formats of this class. For details see Prior.
      Parameters:
      level - the level of this format. A higher numerical value means a higher binding power, and low-binding compounds in high-bounding context must appear parenthesized.
      noparens - the format to print when no parentheses are necessary
      parens - the format to print when parentheses are necessary
      Returns:
      the constructed format
    • prior

      public static Format prior(int level, int alternative, Format noparens, Format parens)
      Creates a priority-controlled format, which is rendered differently, according to its relative positions to ancestor formats of this class. For details see Prior.
      Parameters:
      level - the level of this format. A higher numerical value means a higher binding power, and low-binding compounds in high-bounding context must appear parenthesized.
      alternative - a code which separates incompatible operators with the same binding power.
      noparens - the format to print when no parentheses are necessary
      parens - the format to print when parentheses are necessary
      Returns:
      the constructed format
    • append

      public static Format append(List<@Opt ? extends Format> f)
      Returns (in most cases) a new append format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is an append format, empty, or the singleton argument.
    • block

      public static Format block(List<@Opt ? extends Format> f)
      Returns (in most cases) a new block format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a block format, empty, or the singleton argument.
    • line

      public static Format line(List<@Opt ? extends Format> f)
      Returns (in most cases) a new line format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a line format, empty, or the singleton argument.
    • beside

      public static Format beside(List<@Opt ? extends Format> f)
      Returns (in most cases) a new beside format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a beside format, empty, or the singleton argument.
    • beneath

      public static Format beneath(List<@Opt ? extends Format> f)
      Returns (in most cases) a new beneath format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a beneath format, empty, or the singleton argument.
    • tabular

      public static Format tabular(List<@Opt ? extends Format> f)
      Calls makeTabular(java.util.List<eu.bandm.tools.format.Format>) while ignoring all empty formats and null pointers contained in the argument list.
      Parameters:
      f - list of subformats
      Returns:
      a tabular format
    • comment

      public static Format comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, List<@Opt ? extends Format> f)
      Creates a comment format. A comment format is created in any case, but all empty formats and null pointers contained in the argument list are ignored.
      Parameters:
      prefix - the string to lead in the first line
      linePrefix - the string to lead in all inner lines, and the first line if prefix is null.
      suffix - the string to lead in an additional last line, if not null.
      f - the commented lines
      Returns:
      a comment format
    • comment

      public static Format comment(String linePrefix, List<? extends Format> f)
      Creates an comment format. A comment format is created in any case, but all empty formats and null pointers contained in the argument list are ignored. Prefix and suffix default to null = not present.
      Parameters:
      linePrefix - the string to lead in all lines
      f - the commented lines
      Returns:
      a comment format
    • append

      public static Format append(Format... f)
      Returns (in most cases) a new append format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is an append format, empty, or the singleton argument.
    • block

      public static Format block(Format... f)
      Returns (in most cases) a new block format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a block format, empty, or the singleton argument.
    • line

      public static Format line(Format... f)
      Returns (in most cases) a new line format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a line format, empty, or the singleton argument.
    • beside

      public static Format beside(Format... f)
      Returns (in most cases) a new beside format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a beside format, empty, or the singleton argument.
    • beneath

      public static Format beneath(Format... f)
      Returns (in most cases) a new beneath format with the given contents. First the list is purged from all null pointers and empty formats. If then the list is empty, an empty format is returned. If the list has only one component, then that is returned. Otherwise a new append format is constructed and returned.
      Parameters:
      f - the contents for the new format.
      Returns:
      a format which is a beneath format, empty, or the singleton argument.
    • tabular

      public static Format tabular(Format... f)
      Calls makeTabular(java.util.List<eu.bandm.tools.format.Format>) while ignoring all empty formats and null pointers contained in the argument list.
      Parameters:
      f - list of subformats
      Returns:
      a tabular format
    • comment

      public static Format comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, Format... f)
      Creates an comment format. A comment format is created in any case, but all empty formats and null pointers contained in the argument list are ignored.
      Parameters:
      prefix - the string to lead in the first line
      linePrefix - the string to lead in all inner lines, and the first line if prefix is null.
      suffix - the string to lead in an additional last line, if not null.
      f - the commented lines
      Returns:
      a comment format
    • comment

      public static Format comment(String linePrefix, Format... f)
      Creates an comment format. A comment format is created in any case, but all empty formats and null pointers contained in the argument list are ignored. Prefix and suffix default to null = not present.
      Parameters:
      linePrefix - the string to lead in all lines
      f - the commented lines
      Returns:
      a comment format
    • maxOfMins

      protected static int maxOfMins(List<Format> subs)
      Calculate the maximum of the minWidth fields of all Formats in subs.
      Parameters:
      subs - the formats to analyse
      Returns:
      the maximum of all minimal width values
    • indent

      public abstract Format indent(int i)
      Returns a clone of this with the new value of indent.
      Parameters:
      i - the new value for indent.
      Returns:
      an new format with identical values but i, or this, if i is its indent value.
      Throws:
      IllegalArgumentException - if ident value not valid, see checkValidIndent(int)
    • annotated

      public static <A> Format annotated(Format format, @Opt A annotation)
      Creates an annotated format.
      Type Parameters:
      A - the type of the annotated data.
      Parameters:
      format - the format to annotate
      annotation - the annotead data
      Returns:
      an annotated format.
    • variable

      public static Format variable(String name)
      Creates a new FreeVariable with the given name.
      Parameters:
      name - of the new variable
      Returns:
      a new variable
    • variable

      public static Format variable(int index)
      Creates a new BoundVariable with the given number.
      Parameters:
      index - of the new variable
      Returns:
      a new variable
    • subst

      public static Format subst(Format body, Context c, boolean partial)
      Creates a scope which imposes the given variable substitutions on a subtree of formats. These substitutions will become effective when the variables are resolved by the descending execution of eval(Context,boolean).
      Parameters:
      body - in which the variables shall be resolved
      c - Context which binds names and numbers of variables to Format values
      partial - whether some variables are still unbound
      Returns:
      a new subst format
    • subst

      public static Format subst(Format body, Format... args)
      Creates a scope which imposes the given variable substitutions on a subtree of formats. These substitutions will become effective when the variables are resolved by the descending execution of eval(Context,boolean).
      Parameters:
      body - in which the variables shall be resolved
      args - the format values which are bound to the numbered variables BoundVariable ascending from zero.
      Returns:
      a new subst format
    • subst

      public static Format subst(Format body, String name, Format value)
      Creates a new scope in which the variable with the given name is bound to the given Format value. This substitutions will become effective when the variables are resolved by the descending execution of eval(Context,boolean). The argument partial defaults to true.
      Parameters:
      body - in which the variables shall be resolved
      name - of the variable to define for the new scope
      value - of the variable to define for the new scope
      Returns:
      a new subst format
    • apply

      public static Format apply(Format body, Context c, boolean partial)
      Returns the format which results from replacing all Variables by their binding defined in context c, if any.
      Parameters:
      body - format in which all variables shall be replaced by the defined value
      c - defines the values for all or some of the variables to resolve
      partial - decides when a Variable not defined in the context is found: if true the Variable stays unaltered; if false an IllegalArgumentException is thrown.
      Returns:
      the format with possibly variables replaced by their value in context
    • apply

      public static Format apply(Format body, Format... args)
      Returns the format which results from replacing all bound (=numeric) variables by the argument on the position given by their number. Evaluation must be total.
      Parameters:
      body - format in which all bound (=numeric) variables shall be replaced by the defined value
      args - formats which are assigned to the bound (=numeric) variables in ascending order
      Returns:
      a format with variables replaced by values
      Throws:
      IllegalArgumentException - if a BoundVariable is not defined or a FreeVariable occurs.
    • apply

      public static Format apply(Format body, Formattable... args)
      Returns the format which results from replacing all bound (=numeric) variables by the argument on the position given by their number. Evaluation must be total.
      Parameters:
      body - format in which all bound (=numeric) variables shall be replaced by the defined value
      args - formats which are assigned to the bound (=numeric) variables in ascending order
      Returns:
      a format with variables replaced by values
      Throws:
      IllegalArgumentException - if a BoundVariable is not defined or a FreeVariable occurs.
    • apply

      public static Format apply(Format body, String name, Format value)
      Returns the format which results from replacing all FreeVariable with the given name by the given value. Evaluation is partial: All unbound Variables stay untouched and no exception occurs.
      Parameters:
      body - format in which one free (=named) variable shall be replaced by the defined value
      name - of the variable to replace
      value - with which to replace the variable
      Returns:
      a format with variables replaced by values
    • applyTo

      public final Format applyTo(Format... args)
      Resolve all bound (=numbered) variables in this format against the list of arguments. Evaluation must be total.
      Parameters:
      args - formats which are assigned to the bound (=numeric) variables in ascending order
      Returns:
      a format with variables replaced by values
      Throws:
      IllegalArgumentException - if a BoundVariable is not defined or a FreeVariable occurs.
    • applyTo

      public final Format applyTo(Formattable... args)
      Resolve all bound (=numbered) variables in this format against the list of arguments. Evaluation must be total.
      Parameters:
      args - formats which are assigned to the bound (=numeric) variables in ascending order
      Returns:
      a format with variables replaced by values
      Throws:
      IllegalArgumentException - if a BoundVariable is not defined or a FreeVariable occurs.
    • applyPartial

      public final Format applyPartial(Formattable... args)
      Resolve all bound (=numbered) variables in this format against the list of arguments. Evaluation can be partial: free variable and bound variable with numbers beyond the argument length -1 stays as they are.1
      Parameters:
      args - formats which are assigned to the bound (=numeric) variables in ascending order
      Returns:
      a format with variables replaced by values
      Throws:
      IllegalArgumentException - if a BoundVariable is not defined or a FreeVariable occurs.
    • showLn

      public String showLn(int depth)
      Creates a debugging representation of a Format term, restricted to show only the top "depth" levels.
      Parameters:
      depth - the limit to descend into the format tree
      Returns:
      a text representation of the data structure
    • properties

      public String properties()
      Returns a text representation of the attributes of a format.
             [1/13/g/m/-1]
              | |  | | | 
              | |  | | indent 
              | |  | always multiline ("m") or not ("-")
              | |  ground ("g") or not ("-")
              min and max width
        
    • debugPrefix

      public abstract String debugPrefix(int n)
      Deliver the concatenation of the text contents, limited by the given number of characters, approximately. Useful for debugging purpose.
      Parameters:
      n - the maximal number of characters which can be generated per tree node.
      Returns:
      the concatenated, unformatted text contents.
    • indentIsSet

      protected boolean indentIsSet()
      Whether this indentation value is a specific one.
      Returns:
      whether this indentation value is a specific one.
    • checkValidIndent

      public static void checkValidIndent(int i)
    • isSpace

      protected boolean isSpace()
      Whether this format is a space.
      Returns:
      whether this format is a space.
    • getIndent

      public int getIndent()
      Returns the indentation value explicitly assigned by the user. This will determine the number of spaces the format will begin further to the right then the beginning of its immediate container, iff the format is the first in an output line.
      Returns:
      the indentation value explicitly assigned by the user.
    • minWidth

      public int minWidth()
      Return the minimal width if not directly at start of line, ie respecting blanks and not including indentation. (This is because after starting a new line, no decision on line break is necessary anyhow.)
      Returns:
      the minimal width if not directly at start of line.
    • maxWidth

      public int maxWidth()
      Return the maximal width, ie reflects the printing situation where no single contained optional line-break contained in (the sub-formats of) this format is realized.
      Returns:
      the maximal width.
    • isAlwaysMultiline

      public boolean isAlwaysMultiline()
      Returns whether this format contains any Beneath format. Needed for line and block formats, which propagate line breaks contained in their content formats to their own layout.
      Returns:
      whether this format contains any non-denormalized Beneath format.
    • ground

      public boolean ground()
      Returns whether this format does not contain variables.
      Returns:
      whether this format does not contain variables.
    • eval

      public Format eval(Context c, boolean partial)
      Return the result of replacing all variables with the bindings in the given context.
      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
      Throws:
      IllegalArgumentException - if partial is false and one or multiple variables cannot be resolved.
    • doprint

      protected abstract void doprint(FormatPrinter v)
      Over-ridden by all sub-classes of Format, for performing the print operations.
      Parameters:
      v - realizes the dynamic context for printing
    • printFormat

      public void printFormat(PrintWriter pw)
      Service point: print this format.
      Parameters:
      pw - the target for printing
    • printFormat

      public void printFormat(PrintWriter pw, int width)
      Service point: print this format with the given line width.

      The given limit is not absolute and possibly transgressed by a few characters.

      Parameters:
      pw - the target for printing
      width - the line width to respect by inserting line feeds
    • printNonFormat

      public void printNonFormat(PrintWriter pw)
      Service point: print this format without any formatting.

      Only small structures are human-readable. It useful for debugging or automated processing, e.g. as map keys. This method uses a NonFormatPrinter.

      Parameters:
      pw - the target for printing
    • toString

      public String toString()
      Convert a format without any formatting.

      Only small structures are human-readable. It useful for debugging or automated processing, e.g. as map keys. This method uses a NonFormatPrinter.

      Overrides:
      toString in class Object
      Returns:
      a text representaton without line feeds and other formatting.
    • toString

      public String toString(int width)
      Print the format in a formatted way to a string (include linefeeds), with the specified maximal column width.
      Parameters:
      width - the line width to respect by inserting line feeds
      Returns:
      a text representaton including line feeds and other formatting.
    • toObjString

      public String toObjString()
      Call toString from the Object superclass, for debugging only.
      Returns:
      the text representatio as defined by Object.