*/
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;
// 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
*
* @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
*
* @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);
}