public class TreeTableFormat extends TabularFormat<TreeTable>
TreeTable
instances.
This formatter is given an arbitrary number of TableColumn
s
to use during the formatting. The first column is taken as the node label.
If a TreeTable
is formatted with only that column,
then the String
result is like the following example:
Node #1 ├─Node #2 │ └─Node #4 └─Node #3If the same
TreeTable
is formatted with two columns,
then the String
result is like the following example:
Node #1……………………… More #1 ├─Node #2…………… More #2 │ └─Node #4… More #4 └─Node #3…………… More #3This representation can be printed to the console output (for example) if the stream uses a monospaced font and supports Unicode characters.
"?……[…] "
, which means "If the next value is non-null,
then insert the "……"
string, repeat the '…'
character as many time as needed
(may be zero), and finally insert a space".
TreeTable
implementations generate the nodes dynamically as wrappers around Java objects.
Such Java objects may contain cyclic associations (A contains B contains C
contains A), which result in a tree of infinite depth. Some examples can been found in ISO 19115
metadata. This TreeTableFormat
class contains a safety against such cycles. The algorithm is based
on the assumption that for each node, the values and children are fully determined by the
user object, if non-null. Consequently for each node C
to be formatted, if the user object of that node is the same instance (in the sense of the ==
operator)
than the user object of a parent node A, then the children of the C node will not be formatted.Defined in the sis-utility
module
Format.Field
beforeFill, columnSeparator, fillCharacter, lineSeparator, omitTrailingNulls
Constructor and Description |
---|
TreeTableFormat(Locale locale,
TimeZone timezone)
Creates a new tree table format.
|
Modifier and Type | Method and Description |
---|---|
TreeTableFormat |
clone()
Returns a clone of this format.
|
void |
format(TreeTable tree,
Appendable toAppendTo)
Writes a graphical representation of the specified tree table in the given stream or buffer.
|
TableColumn<?>[] |
getColumns()
Returns the table columns to parse and format, or
null for the default list of
columns. |
int |
getIndentation()
Returns the number of spaces to add on the left margin for each indentation level.
|
Class<TreeTable> |
getValueType()
Returns the type of objects formatted by this class.
|
int |
getVerticalLinePosition()
Returns the position of the vertical line, relative to the position of the root label.
|
TreeTable |
parse(CharSequence text,
ParsePosition pos)
Creates a tree from the given character sequence,
or returns
null if the given text does not look like a tree for this method. |
void |
setColumns(TableColumn<?>... columns)
Sets the table columns to parse and format.
|
void |
setIndentation(int indentation)
Sets the number of spaces to add on the left margin for each indentation level.
|
void |
setVerticalLinePosition(int verticalLinePosition)
Sets the position of the vertical line, relative to the position of the root label.
|
getColumnSeparatorMatcher, getColumnSeparatorPattern, getLineSeparator, setColumnSeparatorPattern, setLineSeparator
createFormat, format, getFormat, getLocale, getLocale, getTimeZone, parseObject, parseObject
format, formatToCharacterIterator
public TreeTableFormat(Locale locale, TimeZone timezone)
locale
- the locale to use for numbers, dates and angles formatting,
or null
for the root locale.timezone
- the timezone, or null
for UTC.public final Class<TreeTable> getValueType()
getValueType
in class CompoundFormat<TreeTable>
TreeTable.class
public TableColumn<?>[] getColumns()
null
for the default list of
columns. The default is:
String
.TreeTable
columns.null
for the default.public void setColumns(TableColumn<?>... columns) throws IllegalArgumentException
null
value means to use the default
list of columns, as defined in the getColumns()
method.columns
- the table columns to parse and format, or null
for the default.IllegalArgumentException
- if the given array is empty, contains a null element
or a duplicated value.public int getIndentation()
public void setIndentation(int indentation) throws IllegalArgumentException
indentation
- the new indentation.IllegalArgumentException
- if the given value is negative.public int getVerticalLinePosition()
public void setVerticalLinePosition(int verticalLinePosition) throws IllegalArgumentException
verticalLinePosition
- the new vertical line position.IllegalArgumentException
- if the given value is negative or greater than the indentation.public TreeTable parse(CharSequence text, ParsePosition pos) throws ParseException
null
if the given text does not look like a tree for this method.
This method can parse the trees created by the format(…)
methods
defined in this class.
'│'
, '├'
, '└'
or '─'
);getIndentation()
value, but must be consistent across all the parsed tree.null
.
Otherwise if parsing started but failed, then:
ParsePosition.getErrorIndex()
will give the index at the beginning
of line or beginning of cell where the error occurred, andParseException.getErrorOffset()
will give either the same value,
or a slightly more accurate value inside the cell.parse
in class CompoundFormat<TreeTable>
text
- the character sequence for the tree to parse.pos
- the position where to start the parsing.null
if the given character sequence can not be parsed.ParseException
- if an error occurred while parsing a node value.public void format(TreeTable tree, Appendable toAppendTo) throws IOException
CompoundFormat.getFormat(Class)
.format
in class CompoundFormat<TreeTable>
tree
- the tree to format.toAppendTo
- where to format the tree.IOException
- if an error occurred while writing to the given appendable.TreeTables.toString(TreeTable)
public TreeTableFormat clone()
clone
in class TabularFormat<TreeTable>
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.