Class TreeTableFormat.Writer

All Implemented Interfaces:
Flushable, Appendable, Localized
Enclosing class:
TreeTableFormat

private final class TreeTableFormat.Writer extends PropertyFormat
Creates string representation of the node values. Tabulations are replaced by spaces, and line feeds are replaced by the Pilcrow character. This is necessary in order to avoid conflict with the characters expected by TableAppender.

Instances of TreeTableFormat.Writer are created temporarily before to begin the formatting of a node, and discarded when the formatting is finished.

  • Field Details

    • filter

      private final Predicate<TreeTable.Node> filter
      Combination of TreeTableFormat.nodeFilter with other filter that may be specified by the tree table to format. The TreeTable-specific filter is specified by TreeFormatCustomization.
    • columns

      private final TableColumn<?>[] columns
      The columns to write.
    • formats

      private final Format[] formats
      The format to use for each column.
    • values

      private final Object[] values
      The node values to format.
    • isLast

      private boolean[] isLast
      For each indentation level, true if the previous levels are writing the last node. This array will growth as needed.
    • multiLineCells

      private final boolean multiLineCells
      Whether to allows multi-lines cells instead of using Pilcrow character. This is currently supported only if the number of columns is less than 2.
    • recursivityGuard

      private final Set<TreeTable.Node> recursivityGuard
      The node that have already been formatted. We use this map as a safety against infinite recursivity.
  • Constructor Details

    • Writer

      Writer(Appendable out, TreeTable tree, TableColumn<?>[] columns, Set<TreeTable.Node> recursivityGuard)
      Creates a new instance which will write to the given appendable.
      Parameters:
      out - where to format the tree.
      tree - the tree table to format.
      columns - the columns of the tree table to format.
      recursivityGuard - an initially empty set.
  • Method Details

    • getLocale

      public Locale getLocale()
      Returns the locale to use for formatting property value. This method is invoked by PropertyFormat when needed.
      Returns:
      the locale, or null if not explicitly defined.
    • toString

      protected final String toString(Object value)
      Invoked by PropertyFormat for formatting a value which has not been recognized as one of the types to be handled in a special way. In particular numbers and dates should be handled here. This method checks for a value-by-value format and should be invoked only in last resort. If a column-wide format was specified by the PropertyFormat.columnFormat field, then that format should have been used by PropertyFormat.appendValue(Object) code in order to produce a more uniform formatting.
      Overrides:
      toString in class PropertyFormat
      Parameters:
      value - the value to format (never null).
      Returns:
      the formatted value.
    • format

      final void format(TreeTable.Node node, int level) throws IOException
      Appends the string representation of the given node and all its children. This method invokes itself recursively.
      Parameters:
      node - the node to format.
      level - indentation level. The first level is 0.
      Throws:
      IOException
    • next

      private TreeTable.Node next(Iterator<? extends TreeTable.Node> it)
      Returns the next filtered element from the given iterator, or null if none. The filter applied by this method combines TreeTableFormat.getNodeFilter() with the filter returned by TreeFormatCustomization.filter().