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 8203b0337bdb6e9bd8c0b42903d102c11b9c7237
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Jan 10 15:42:54 2025 +0100

    Provide default method in `TreeTable.Node` interface for unmodifiable nodes.
---
 .../apache/sis/xml/bind/lan/LocaleAndCharset.java  | 10 +++------
 .../sis/util/collection/DefaultTreeTable.java      | 25 ++++++++--------------
 .../org/apache/sis/util/collection/TreeTable.java  | 21 +++++++++++++-----
 3 files changed, 28 insertions(+), 28 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/lan/LocaleAndCharset.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/lan/LocaleAndCharset.java
index 6363b55d10..5a338870d6 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/lan/LocaleAndCharset.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/lan/LocaleAndCharset.java
@@ -84,14 +84,11 @@ public final class LocaleAndCharset implements Node {
         return node.getParent();
     }
 
-    /**
+    /*
+     * Inherit `isEditable(…)` from the `Node` interface:
      * Considers this node as non-editable since it represents the key in a 
map, and keys cannot be modified
-     * through the {@link Map.Entry} interface. However, {@link Child} will be 
editable for the value column.
+     * through the `Map.Entry` interface. However, `Child` will be editable 
for the value column.
      */
-    @Override
-    public boolean isEditable(final TableColumn<?> column) {
-        return false;
-    }
 
     /**
      * Returns {@code false} since this node can have a children, which is the 
{@link Child}.
@@ -207,7 +204,6 @@ public final class LocaleAndCharset implements Node {
         @Override public boolean          isEditable(TableColumn<?> c) {return 
node.isEditable(c);}
         @Override public boolean          isLeaf()                     {return 
true;}
         @Override public Collection<Node> getChildren()                {return 
Collections.emptySet();}
-        @Override public Node             newChild()                   {throw 
new UnsupportedOperationException();}
 
         /** Returns the value at the given column, with hard-coded names. */
         @Override public <V> V getValue(final TableColumn<V> column) {
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/DefaultTreeTable.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/DefaultTreeTable.java
index 973054de32..f82de9c1a2 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/DefaultTreeTable.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/DefaultTreeTable.java
@@ -255,7 +255,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
      */
     @Override
     public DefaultTreeTable clone() throws CloneNotSupportedException {
-        final DefaultTreeTable clone = (DefaultTreeTable) super.clone();
+        final var clone = (DefaultTreeTable) super.clone();
         if (clone.root instanceof Cloneable) {
             clone.root = (TreeTable.Node) Cloner.cloneIfPublic(clone.root);
         }
@@ -279,7 +279,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
             return true;
         }
         if (other != null && other.getClass() == getClass()) {
-            final DefaultTreeTable that = (DefaultTreeTable) other;
+            final var that = (DefaultTreeTable) other;
             return columnIndices.equals(that.columnIndices) &&
                     Objects.equals(getRoot(), that.getRoot());
         }
@@ -450,7 +450,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
         public Node(final Node parent) {
             this.parent = parent;
             columnIndices = parent.columnIndices;
-            final TreeNodeList addTo = (TreeNodeList) parent.getChildren();
+            final var addTo = (TreeNodeList) parent.getChildren();
             addTo.addChild(addTo.size(), this);
         }
 
@@ -466,7 +466,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
         public Node(final Node parent, final int index) {
             this.parent = parent;
             columnIndices = parent.columnIndices;
-            final TreeNodeList addTo = (TreeNodeList) parent.getChildren();
+            final var addTo = (TreeNodeList) parent.getChildren();
             addTo.addChild(Objects.checkIndex(index, addTo.size() + 1), this);
         }
 
@@ -634,15 +634,6 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
             return columnIndices.containsKey(column);
         }
 
-        /**
-         * Returns the user object associated to this node.
-         * The default implementation returns {@code null}.
-         */
-        @Override
-        public Object getUserObject() {
-            return null;
-        }
-
         /**
          * Returns a clone of this node without parent.
          * This method recursively clones all {@linkplain #getChildren() 
children},
@@ -737,6 +728,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
         @Override
         public int hashCode() {
             int hash = 0;
+            @SuppressWarnings("LocalVariableHidesMemberVariable")
             final Object[] values = this.values;
             if (values != null) {
                 /*
@@ -769,6 +761,7 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
          */
         @Override
         public String toString() {
+            @SuppressWarnings("LocalVariableHidesMemberVariable")
             final Object[] values = this.values;
             if (values != null) {
                 for (final Object value : values) {
@@ -782,9 +775,9 @@ public class DefaultTreeTable implements TreeTable, 
Cloneable, Serializable {
             }
             String name = getClass().getSimpleName();
             if (parent != null) {
-                final Collection<TreeTable.Node> children = 
parent.getChildren();
-                if (children instanceof List<?>) {
-                    name = name + '-' + ((List<TreeTable.Node>) 
children).indexOf(this);
+                final Collection<TreeTable.Node> pc = parent.getChildren();
+                if (pc instanceof List<?>) {
+                    name = name + '-' + ((List<TreeTable.Node>) 
pc).indexOf(this);
                 }
             }
             return name;
diff --git 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/TreeTable.java
 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/TreeTable.java
index e3645161cf..c4ed6524c5 100644
--- 
a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/TreeTable.java
+++ 
b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/collection/TreeTable.java
@@ -115,8 +115,11 @@ public interface TreeTable {
      * In addition, each {@code Node} can be associated to an arbitrary object 
by the
      * {@link #getUserObject()} method. This object is not used directly by 
the tree tables.
      *
+     * <h2>Default implementation</h2>
+     * The methods providing a default implementations are suitable for 
unmodifiable tree nodes.
+     *
      * @author  Martin Desruisseaux (IRD, Geomatys)
-     * @version 0.8
+     * @version 1.5
      * @since   0.3
      */
     public interface Node {
@@ -174,7 +177,9 @@ public interface TreeTable {
          * @return the new child.
          * @throws UnsupportedOperationException if this node cannot add new 
children.
          */
-        Node newChild() throws UnsupportedOperationException;
+        default Node newChild() throws UnsupportedOperationException {
+            throw new UnsupportedOperationException();
+        }
 
         /**
          * Returns the value in the given column, or {@code null} if none.
@@ -203,7 +208,9 @@ public interface TreeTable {
          * @see #isEditable(TableColumn)
          * @category table
          */
-        <V> void setValue(TableColumn<V> column, V value) throws 
IllegalArgumentException, UnsupportedOperationException;
+        default <V> void setValue(TableColumn<V> column, V value) throws 
IllegalArgumentException, UnsupportedOperationException {
+            throw new UnsupportedOperationException();
+        }
 
         /**
          * Determines whether the value in the specified column is editable. 
If the given
@@ -216,7 +223,9 @@ public interface TreeTable {
          *         otherwise.
          * @category table
          */
-        boolean isEditable(TableColumn<?> column);
+        default boolean isEditable(TableColumn<?> column) {
+            return false;
+        }
 
         /**
          * Returns the user object associated to this node.
@@ -231,7 +240,9 @@ public interface TreeTable {
          * @return any object stored at this node by the user, or {@code null} 
if none.
          * @category tree
          */
-        Object getUserObject();
+        default Object getUserObject() {
+            return null;
+        }
 
         /**
          * Returns {@code true} if the given object is a node with the same 
content as this node.

Reply via email to