Make (Mutable)TreeNode a class
[yangtools.git] / data / yang-data-tree-ri / src / main / java / org / opendaylight / yangtools / yang / data / tree / impl / node / TreeNode.java
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);
 }