Make (Mutable)TreeNode a class 42/98942/4
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Dec 2021 01:14:38 +0000 (02:14 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Dec 2021 07:37:24 +0000 (08:37 +0100)
A pure interface leads to us having AbstractTreeNode, which is
superfluous. Turn interfaces into abstract classes instead.

Change-Id: Icbf2daf28abb1c7b390006f61989d63d10329ecc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractModifiedContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractMutableContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractTreeNode.java [deleted file]
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/LazyContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/MaterializedContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/MutableTreeNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/SimpleContainerNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/TreeNode.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/ValueNode.java

index 294319abf195d7670969e57926843e2e5e57dc1d..873309d491a5fc3146c9fc1aaa3f1ab5c351f5f1 100644 (file)
@@ -16,17 +16,17 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * A TreeNode capable of holding child nodes. The fact that any of the children
  * changed is tracked by the subtree version.
  */
-abstract class AbstractContainerNode extends AbstractTreeNode {
-    protected AbstractContainerNode(final NormalizedNode data, final Version version) {
+abstract class AbstractContainerNode extends TreeNode {
+    AbstractContainerNode(final NormalizedNode data, final Version version) {
         super(data, version);
     }
 
     @SuppressWarnings("unchecked")
-    protected final DistinctNodeContainer<PathArgument, NormalizedNode> castData() {
+    final DistinctNodeContainer<PathArgument, NormalizedNode> castData() {
         return (DistinctNodeContainer<PathArgument, NormalizedNode>) getData();
     }
 
-    protected final @Nullable TreeNode getChildFromData(final PathArgument childId) {
+    final @Nullable TreeNode getChildFromData(final PathArgument childId) {
         // We do not cache the instantiated node as it is dirt cheap
         return getChildFromData(castData(), childId, getVersion());
     }
index 93dc2d9aec711430a1f4f825419a83d60e0c9dbe..4d6b432397bb7463f28e58db8649b9e6ff98e642 100644 (file)
@@ -22,18 +22,18 @@ abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
     private final Map<PathArgument, TreeNode> children;
     private final Version subtreeVersion;
 
-    protected AbstractModifiedContainerNode(final NormalizedNode data, final Version version,
+    AbstractModifiedContainerNode(final NormalizedNode data, final Version version,
             final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
         super(data, version);
         this.subtreeVersion = requireNonNull(subtreeVersion);
         this.children = requireNonNull(children);
     }
 
-    protected final TreeNode getModifiedChild(final PathArgument childId) {
+    final TreeNode getModifiedChild(final PathArgument childId) {
         return children.get(childId);
     }
 
-    protected final Map<PathArgument, TreeNode> snapshotChildren() {
+    final Map<PathArgument, TreeNode> snapshotChildren() {
         return MapAdaptor.getDefaultInstance().takeSnapshot(children);
     }
 
@@ -43,7 +43,7 @@ abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
     }
 
     @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+    ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         return helper.add("subtreeVersion", subtreeVersion).add("children", children);
     }
 }
index 69f4e63573b3d80a17372b2b649d081e419b3f47..a8f43498cf8bc0e49ff9c7ef952878a11a65389a 100644 (file)
@@ -20,30 +20,29 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * Abstract base for container-based {@link MutableTreeNode}s. It tracks modified nodes in a map and deals with
  * correctly implementing {@link #seal()}.
  */
-abstract class AbstractMutableContainerNode implements MutableTreeNode {
+abstract class AbstractMutableContainerNode extends MutableTreeNode {
     private final Version version;
     private Map<PathArgument, TreeNode> children;
     private NormalizedNode data;
     private Version subtreeVersion;
 
-    protected AbstractMutableContainerNode(final AbstractContainerNode parent,
-            final Map<PathArgument, TreeNode> children) {
-        this.data = parent.getData();
-        this.version = parent.getVersion();
-        this.subtreeVersion = parent.getSubtreeVersion();
+    AbstractMutableContainerNode(final AbstractContainerNode parent, final Map<PathArgument, TreeNode> children) {
+        data = parent.getData();
+        version = parent.getVersion();
+        subtreeVersion = parent.getSubtreeVersion();
         this.children = requireNonNull(children);
     }
 
-    protected final Version getVersion() {
+    final Version getVersion() {
         return version;
     }
 
-    protected final TreeNode getModifiedChild(final PathArgument child) {
+    final TreeNode getModifiedChild(final PathArgument child) {
         return children.get(child);
     }
 
     @SuppressWarnings("unchecked")
-    protected final DistinctNodeContainer<PathArgument, NormalizedNode> getData() {
+    final DistinctNodeContainer<PathArgument, NormalizedNode> getData() {
         return (DistinctNodeContainer<PathArgument, NormalizedNode>) data;
     }
 
diff --git a/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractTreeNode.java b/data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/node/AbstractTreeNode.java
deleted file mode 100644 (file)
index d55610c..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.tree.impl.node;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * A very basic data tree node. Contains some versioned data.
- */
-@NonNullByDefault
-abstract class AbstractTreeNode implements TreeNode {
-    private final NormalizedNode data;
-    private final Version version;
-
-    protected AbstractTreeNode(final NormalizedNode data, final Version version) {
-        this.data = requireNonNull(data);
-        this.version = requireNonNull(version);
-    }
-
-    @Override
-    public final PathArgument getIdentifier() {
-        return data.getIdentifier();
-    }
-
-    @Override
-    public final Version getVersion() {
-        return version;
-    }
-
-    @Override
-    public final NormalizedNode getData() {
-        return data;
-    }
-
-    @Override
-    public final String toString() {
-        return addToStringAttributes(MoreObjects.toStringHelper(this).add("version", version)).toString();
-    }
-
-    protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
-}
index cf9373baeb09c9d9d9aad83d2f151f657a7912f7..be0eefb4e58c89d928bfd3575ef99aa12a4bdef0 100644 (file)
@@ -44,7 +44,7 @@ final class LazyContainerNode extends AbstractModifiedContainerNode {
     }
 
     @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+    ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         // Modified children add added by superclass. Here we filter the other children.
         return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().body(),
             input -> getModifiedChild(input.getIdentifier()) == null));
index 24f065e6d2d77eab72a8f84c617566483b623d29..1ce11454a2bf25868120a011ce1b17f618054e99 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * A fully-modified node -- we know we have all children, so it performs lookups only.
  */
 final class MaterializedContainerNode extends AbstractModifiedContainerNode {
-    protected MaterializedContainerNode(final NormalizedNode data, final Version version,
+    MaterializedContainerNode(final NormalizedNode data, final Version version,
             final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
         super(data, version, children, subtreeVersion);
     }
index d8cd869391f03ace51fdd45911e5912633ece01b..709b6acfad1a1d79140a3de34039e41de2d3fdfe 100644 (file)
@@ -17,14 +17,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
  * A mutable tree node. This is a transient view materialized from a pre-existing node. Modifications are isolated. Once
  * this object is {@link #seal()}ed, any interactions with it will result in undefined behavior.
  */
-public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
+public abstract class MutableTreeNode implements StoreTreeNode<TreeNode> {
     /**
      * Set the data component of the node.
      *
      * @param data New data component, may not be null.
      * @throws NullPointerException if {@code data} is null
      */
-    void setData(NormalizedNode data);
+    public abstract void setData(NormalizedNode data);
 
     /**
      * Set the new subtree version. This is typically invoked when the user
@@ -33,7 +33,7 @@ public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
      * @param subtreeVersion New subtree version.
      * @throws NullPointerException if {@code subtreeVersion} is null
      */
-    void setSubtreeVersion(Version subtreeVersion);
+    public abstract void setSubtreeVersion(Version subtreeVersion);
 
     /**
      * Add a new child node. This acts as add-or-replace operation, e.g. it succeeds even if a conflicting child is
@@ -43,7 +43,7 @@ public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
      * @return Replaced child, or null if there was no previous child
      * @throws NullPointerException if {@code child} is null
      */
-    @Nullable TreeNode putChild(TreeNode child);
+    public abstract @Nullable TreeNode putChild(TreeNode child);
 
     /**
      * Remove a child node. This acts as delete-or-nothing operation, e.g. it succeeds even if the corresponding child
@@ -53,7 +53,7 @@ public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
      * @return Removed child, or null if there was no matching child
      * @throws NullPointerException if {@code id} is null
      */
-    @Nullable TreeNode removeChild(PathArgument id);
+    public abstract @Nullable TreeNode removeChild(PathArgument id);
 
     /**
      * Finish node modification and return a read-only view of this node. After
@@ -62,5 +62,5 @@ public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
      *
      * @return Read-only view of this node.
      */
-    @NonNull TreeNode seal();
+    public abstract @NonNull TreeNode seal();
 }
index 8b2bc28ad53392e6c82af79b1cb12acbe6f0f509..3a623a1627caa2f519ee94fe0914399509d210a7 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * A container node which has not seen a modification. All nodes underneath it share the same subtree version.
  */
 final class SimpleContainerNode extends AbstractContainerNode {
-    protected SimpleContainerNode(final NormalizedNode data, final Version version) {
+    SimpleContainerNode(final NormalizedNode data, final Version version) {
         super(data, version);
     }
 
@@ -35,7 +35,7 @@ final class SimpleContainerNode extends AbstractContainerNode {
     }
 
     @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+    ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         return helper.add("data", getData());
     }
 }
index e69f6614394bdbedaea337f5a27b869bf1787412..ccffdbb359e7d5c7531adadf010c3c4158bceb20 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.data.tree.impl.node;
 
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -31,7 +35,20 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
 // FIXME: BUG-2399: clarify that versioning rules are not enforced for non-presence containers, as they are not
 //                  considered to be data nodes.
 @NonNullByDefault
-public interface TreeNode extends Identifiable<PathArgument>, StoreTreeNode<TreeNode> {
+public abstract class TreeNode implements Identifiable<PathArgument>, StoreTreeNode<TreeNode> {
+    private final NormalizedNode data;
+    private final Version version;
+
+    TreeNode(final NormalizedNode data, final Version version) {
+        this.data = requireNonNull(data);
+        this.version = requireNonNull(version);
+    }
+
+    @Override
+    public final PathArgument getIdentifier() {
+        return data.getIdentifier();
+    }
+
     /**
      * Get the data node version. This version is updated whenever the data representation of this particular node
      * changes as a result of a direct write to this node or to its parent nodes -- thus indicating that this node
@@ -39,7 +56,9 @@ public interface TreeNode extends Identifiable<PathArgument>, StoreTreeNode<Tree
      *
      * @return Current data node version.
      */
-    Version getVersion();
+    public final Version getVersion() {
+        return version;
+    }
 
     /**
      * Get the subtree version. This version is updated whenever the data representation of this particular node
@@ -47,19 +66,28 @@ public interface TreeNode extends Identifiable<PathArgument>, StoreTreeNode<Tree
      *
      * @return Current subtree version.
      */
-    Version getSubtreeVersion();
+    public abstract Version getSubtreeVersion();
 
     /**
      * Get a read-only view of the underlying data.
      *
      * @return Unmodifiable view of the underlying data.
      */
-    NormalizedNode getData();
+    public final NormalizedNode getData() {
+        return data;
+    }
 
     /**
      * Get a mutable, isolated copy of the node.
      *
      * @return Mutable copy
      */
-    MutableTreeNode mutable();
+    public abstract MutableTreeNode mutable();
+
+    @Override
+    public final String toString() {
+        return addToStringAttributes(MoreObjects.toStringHelper(this).add("version", version)).toString();
+    }
+
+    abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
 }
index 7a24d75ed3bc517a0a14d5ccf7881705793e4801..c6357cc524d37812ebfd9a19c73a4be3792f98da 100644 (file)
@@ -18,10 +18,10 @@ import org.slf4j.LoggerFactory;
  * Instances of this class report all children as absent, subtree version
  * equal to this node's version and do not support mutable view.
  */
-final class ValueNode extends AbstractTreeNode {
+final class ValueNode extends TreeNode {
     private static final Logger LOG = LoggerFactory.getLogger(ValueNode.class);
 
-    protected ValueNode(final NormalizedNode data, final Version version) {
+    ValueNode(final NormalizedNode data, final Version version) {
         super(data, version);
     }
 
@@ -46,7 +46,7 @@ final class ValueNode extends AbstractTreeNode {
     }
 
     @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+    ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         return helper.add("value", getData());
     }
 }