Package org.apache.sis.util.collection
Class DefaultTreeTable
Object
DefaultTreeTable
- All Implemented Interfaces:
Serializable
,Cloneable
,TreeTable
A
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:
Thepublic 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:
Defined in the sis-utility
module
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ATreeTable.Node
implementation which can store values for a pre-defined list of columns. -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.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 (can not 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 (can not be null).- Throws:
IllegalArgumentException
- if the table columns in the given node are inconsistent with the table columns in thisDefaultTreeTable
.
-
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 can not 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.
-