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:
If the sameNode #1 ├─Node #2 │ └─Node #4 └─Node #3
TreeTable
is formatted with two columns,
then the String
result is like the following example:
This representation can be printed to the console output (for example) if the stream uses a monospaced font and supports Unicode characters.Node #1……………………… More #1 ├─Node #2…………… More #2 │ └─Node #4… More #4 └─Node #3…………… More #3
"?……[…] "
, 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 |
---|---|
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 object formatted by this class, which is
TreeTable . |
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 an error occurred while parsing the characters. |
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
clone, createFormat, format, getFormat, 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()
TreeTable
.getValueType
in class CompoundFormat<TreeTable>
Format
instance.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 an error occurred while parsing the characters.
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.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 in the given appender.TreeTables.toString(TreeTable)
Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.