public final class TreeTables extends Static
TreeTable
objects and their nodes.
This class provides methods for some tasks considered generic enough,
and example codes for more specialized tasks that developers can customize.
The remaining of this class javadoc contains example codes placed in public domain. Developers can copy and adapt those examples as they see fit.
Before | After |
---|---|
root ├─users │ └─alice │ ├─data │ │ └─mercator │ └─document └─lib |
root ├─users/alice │ ├─data/mercator │ └─document └─lib |
NAME
columns are concatenated only if the VALUE
column
has no value (for avoiding data lost when the node is discarded) and use the system file
separator as name separator:
final TableColumn columnToProtect = TableColumn.VALUE; final TableColumn columnToConcatenate = TableColumn.NAME; TreeTable.Node concatenateSingletons(final TreeTable.Node node) { // This simple example is restricted to nodes which are known to handle // their children in a list instead than some other kind of collection. final List<TreeTable.Node> children = (List<TreeTable.Node>) node.getChildren(); final int size = children.size(); for (int i=0; i<size; i++) { children.set(i, concatenateSingletons(children.get(i))); } if (size == 1) { final TreeTable.Node child = children.get(0); if (node.getValue(columnToProtect) == null) { children.remove(0); child.setValue(columnToConcatenate, node .getValue(columnToConcatenate) + File.separator + child.getValue(columnToConcatenate)); return child; } } return node; }
TreeTable
Defined in the sis-utility
module
Modifier and Type | Method and Description |
---|---|
static TreeTable.Node |
nodeForPath(TreeTable.Node from,
TableColumn<? super String> column,
File path)
Finds the node for the given path, or creates a new node if none exists.
|
static TreeTable |
parse(String tree,
TableColumn<?> labelColumn,
TableColumn<?>... otherColumns)
Parses the given string as tree.
|
static int |
replaceCharSequences(TreeTable table,
Locale locale)
For every columns having values of type
CharSequence or String ,
converts the values to localized String s. |
static String |
toString(TreeTable table)
Returns a string representation of the given tree table.
|
public static TreeTable.Node nodeForPath(TreeTable.Node from, TableColumn<? super String> column, File path)
For example if the given path is "users/alice/data"
, then this method
finds or creates the nodes for the following tree, where "from"
is the
node given in argument to this method:
from └─users └─alice └─data
from
- The root node from which to start the search.column
- The column containing the file name.path
- The file for which to find or create a node.public static int replaceCharSequences(TreeTable table, Locale locale)
CharSequence
or String
,
converts the values to localized String
s. During conversions, this method also
replaces duplicated String
instances by references to the same singleton instance.
This method may be invoked before to serialize the table in order to reduce the serialization stream size.
table
- The table in which to replace values by their string representations.locale
- The locale to use when replacing InternationalString
instances. Can be null
.public static String toString(TreeTable table)
TreeTableFormat
.
This is okay for debugging or occasional usages. However for more extensive usages,
developers are encouraged to create and configure their own TreeTableFormat
instance.table
- The tree table to format.public static TreeTable parse(String tree, TableColumn<?> labelColumn, TableColumn<?>... otherColumns) throws ParseException
TreeTableFormat
instead.tree
- The string representation of the tree to parse.labelColumn
- The columns where to store the node labels. This is often TableColumn.NAME
.otherColumns
- Optional columns where to store the values, if any.ParseException
- If an error occurred while parsing the tree.Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.