* 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());
}
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);
}
}
@Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ ToStringHelper addToStringAttributes(final ToStringHelper helper) {
return helper.add("subtreeVersion", subtreeVersion).add("children", children);
}
}
* 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;
}
+++ /dev/null
-/*
- * 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);
-}
}
@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));
* 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);
}
* 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
* @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
* @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
* @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
*
* @return Read-only view of this node.
*/
- @NonNull TreeNode seal();
+ public abstract @NonNull TreeNode seal();
}
* 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);
}
}
@Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ ToStringHelper addToStringAttributes(final ToStringHelper helper) {
return helper.add("data", getData());
}
}
*/
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);
}
* 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);
}
}
@Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ ToStringHelper addToStringAttributes(final ToStringHelper helper) {
return helper.add("value", getData());
}
}