Package org.apache.sis.util.collection

## Class DefaultTreeTable

- Object
- - DefaultTreeTable

- All Implemented Interfaces:
    `Serializable`, `Cloneable`, `TreeTable`

      public class DefaultTreeTable
      extends Object
      implements TreeTable, Cloneable, Serializable

  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:

  >     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;
  >         }
  >     }

  The `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:
    `DefaultTreeTable​.Node`, `TableColumn`, Serialized Form

  Defined in the `sis-utility` module

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `DefaultTreeTable.Node` | A `TreeTable​.Node` implementation which can store values for a pre-defined list of columns.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultTreeTable​(DefaultTreeTable.Node root)` | Creates a new tree table initialized to the given root.
    `DefaultTreeTable​(TableColumn<?>... columns)` | Creates a new tree table with the given columns.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DefaultTreeTable` | `clone()` | Returns a clone of this table.
    `boolean` | `equals​(Object other)` | Compares the given object with this tree table for equality.
    `List<TableColumn<?>>` | `getColumns()` | Returns the table columns given at construction time.
    `TreeTable.Node` | `getRoot()` | Returns the root node.
    `int` | `hashCode()` | Returns a hash code value for this table.
    `void` | `setRoot​(TreeTable.Node root)` | Sets the root to the given node.
    `String` | `toString()` | Returns a string representation of this tree table.

    - ### Methods inherited from class Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultTreeTable

          public DefaultTreeTable​(TableColumn<?>... columns)

      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

          public DefaultTreeTable​(DefaultTreeTable.Node root)

      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 Detail

    - #### getColumns

          public final List<TableColumn<?>> getColumns()

      Returns the table columns given at construction time. The returned list is never null neither empty.
      Specified by:
        `getColumns` in interface `TreeTable`
      Returns:
        the union of all table columns in every tree node.
      See Also:
        `DefaultTreeTable​.Node​.getValue(TableColumn)`, `DefaultTreeTable​.Node​.setValue(TableColumn, Object)`

    - #### getRoot

          public TreeTable.Node getRoot()

      Returns the root node. This method returns the node specified at construction time or to the last call of the `setRoot(TreeTable​.Node)` method.
      Specified by:
        `getRoot` in interface `TreeTable`
      Returns:
        the root node of the tree.

    - #### setRoot

          public void setRoot​(TreeTable.Node root)

      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 this `DefaultTreeTable`.

    - #### clone

          public DefaultTreeTable clone()
                                 throws CloneNotSupportedException

      Returns a clone of this table. This method clones the root node. If the root is an instance of `DefaultTreeTable​.Node`, then cloning the root will recursively clone all its children.
      Overrides:
        `clone` in class `Object`
      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:
        `DefaultTreeTable​.Node​.clone()`

    - #### equals

          public boolean equals​(Object other)

      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 the `DefaultTreeTable​.Node` inner class, then all node values and children will be compared recursively.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `other` - the object to compare with this table.
      Returns:
        `true` if the two objects are equal.
      See Also:
        `DefaultTreeTable​.Node​.equals(Object)`

    - #### hashCode

          public int hashCode()

      Returns a hash code value for this table. This method is defined for consistency with `equals(Object)` contract.
      Overrides:
        `hashCode` in class `Object`
      See Also:
        `DefaultTreeTable​.Node​.hashCode()`

    - #### toString

          public String toString()

      Returns a string representation of this tree table. The current implementation uses a shared instance of `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.
      Overrides:
        `toString` in class `Object`
      Returns:
        a string representation of this tree table.