This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 26b4daa6a56c6768710b74d086235548e0298d7e
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Oct 27 15:17:17 2021 +0200

    Provide an extension point in `DefaultTreeTable` for initializing the tree 
only when the root node is first requested.
---
 .../apache/sis/util/collection/DefaultTreeTable.java | 20 +++++++++++++++++---
 .../org/apache/sis/util/collection/package-info.java |  2 +-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
index ae0a2c8..ff7f48e 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/DefaultTreeTable.java
@@ -64,7 +64,7 @@ import static 
org.apache.sis.util.collection.Containers.hashMapCapacity;
  * implementation provided in the {@link Node} inner class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.3
+ * @version 1.2
  *
  * @see Node
  * @see TableColumn
@@ -208,6 +208,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
     public TreeTable.Node getRoot() {
         if (root == null) {
             root = new Node(this);
+            initialize(root);
         }
         return root;
     }
@@ -232,6 +233,19 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
     }
 
     /**
+     * Invoked when {@link #getRoot()} is invoked for the first time and no 
root had been specified to the constructor.
+     * The {@code root} argument is a newly created empty node to be returned 
by {@link #getRoot()}.
+     * The default implementation does nothing.
+     * Subclasses can override for lazy initialization of tree table content.
+     *
+     * @param  root  a newly created tree table root.
+     *
+     * @since 1.2
+     */
+    protected void initialize(final TreeTable.Node root) {
+    }
+
+    /**
      * Returns a clone of this table. This method clones the {@linkplain 
#getRoot() root} node.
      * If the root is an instance of {@link Node}, then cloning the root will 
recursively clone
      * all its {@linkplain Node#getChildren() children}.
@@ -268,7 +282,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
         if (other != null && other.getClass() == getClass()) {
             final DefaultTreeTable that = (DefaultTreeTable) other;
             return columnIndices.equals(that.columnIndices) &&
-                    Objects.equals(root, that.root);
+                    Objects.equals(getRoot(), that.getRoot());
         }
         return false;
     }
@@ -281,7 +295,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
      */
     @Override
     public int hashCode() {
-        return (columnIndices.hashCode() + 31*Objects.hashCode(root)) ^ (int) 
serialVersionUID;
+        return (columnIndices.hashCode() + 31*Objects.hashCode(getRoot())) ^ 
(int) serialVersionUID;
     }
 
     /**
diff --git 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
index 9c844bb..56d7425 100644
--- 
a/core/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
+++ 
b/core/sis-utility/src/main/java/org/apache/sis/util/collection/package-info.java
@@ -51,7 +51,7 @@
  * </ul>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   0.3
  * @module
  */

Reply via email to