Object
DefaultTreeTable
- All Implemented Interfaces:
Serializable
,Cloneable
,TreeTable
A
The
TreeTable
implementation with a list of columns given at
construction time. The list of columns is unmodifiable, but the root node
can be modified.
Example:
public class CityLocation {
public static final TableColumn<String> CITY_NAME = new TableColumn<>(String.class, "City name");
public static final TableColumn<Float> LATITUDE = new TableColumn<>(Float.class, "Latitude");
public static final TableColumn<Float> LONGTITUDE = new TableColumn<>(Float.class, "Longitude");
public TreeTable createTable() {
DefaultTreeTable table = new DefaultTreeTable(CITY_NAME, LATITUDE, LONGITUDE);
TreeTable.Node city = table.getRoot();
city.setValue(CITY_NAME, "Rimouski");
city.setValue(LATITUDE, 48.470417);
city.setValue(LONGITUDE, -68.521385);
return table;
}
}
setRoot(…)
method accepts arbitrary TreeTable.Node
implementations.
However, it is likely to be safer and more memory efficient when used together with the
implementation provided in the DefaultTreeTable.Node
inner class.- Since:
- 0.3
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ATreeTable.Node
implementation which can store values for a predefined list of columns. -
Constructor Summary
ConstructorDescriptionCreates a new tree table initialized to the given root.DefaultTreeTable
(TableColumn<?>... columns) Creates a new tree table with the given columns. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this table.boolean
Compares the given object with this tree table for equality.final List
<TableColumn<?>> Returns the table columns given at construction time.getRoot()
Returns the root node.int
Returns a hash code value for this table.protected void
initialize
(TreeTable.Node root) Invoked whengetRoot()
is invoked for the first time and no root had been specified to the constructor.void
setRoot
(TreeTable.Node root) Sets the root to the given node.Returns a string representation of this tree table.
-
Constructor Details
-
DefaultTreeTable
Creates a new tree table with the given columns. The given array shall not be null or empty, and shall not contain null or duplicated elements.- Parameters:
columns
- the list of table columns.
-
DefaultTreeTable
Creates a new tree table initialized to the given root. The list of columns is inferred from the given node.- Parameters:
root
- the tree table root (cannot be null).
-
-
Method Details
-
getColumns
Returns the table columns given at construction time. The returned list is never null neither empty.- Specified by:
getColumns
in interfaceTreeTable
- Returns:
- the union of all table columns in every tree node.
- See Also:
-
getRoot
Returns the root node. This method returns the node specified at construction time or to the last call of thesetRoot(TreeTable.Node)
method.- Specified by:
getRoot
in interfaceTreeTable
- Returns:
- the root node of the tree.
-
setRoot
Sets the root to the given node. If a root already existed prior this method call, then the previous root node will be discarded.- Parameters:
root
- the new root node (cannot be null).- Throws:
IllegalArgumentException
- if the table columns in the given node are inconsistent with the table columns in thisDefaultTreeTable
.
-
initialize
Invoked whengetRoot()
is invoked for the first time and no root had been specified to the constructor. Theroot
argument is a newly created empty node to be returned bygetRoot()
. The default implementation does nothing. Subclasses can override for lazy initialization of tree table content.- Parameters:
root
- a newly created tree table root.- Since:
- 1.2
-
clone
Returns a clone of this table. This method clones the root node. If the root is an instance ofDefaultTreeTable.Node
, then cloning the root will recursively clone all its children.- Overrides:
clone
in classObject
- Returns:
- a clone of this table.
- Throws:
CloneNotSupportedException
- if this table, the root node or one of its children cannot be cloned.- See Also:
-
equals
Compares the given object with this tree table for equality. This method compares the columns and the root node. If the later is an instance of theDefaultTreeTable.Node
inner class, then all node values and children will be compared recursively. -
hashCode
public int hashCode()Returns a hash code value for this table. This method is defined for consistency withequals(Object)
contract. -
toString
Returns a string representation of this tree table. The current implementation uses a shared instance ofTreeTableFormat
. This is okay for debugging or occasional usages. However for more extensive usages, developers are encouraged to create and configure their ownTreeTableFormat
instance.
-