2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.tree.impl.node;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.opendaylight.yangtools.concepts.Identifiable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
21 * A very basic data tree node. It has a version (when it was last modified), a subtree version (when any of its
22 * children were modified) and some read-only data.
25 * Semantic difference between these two is important when dealing with modifications involving parent/child
26 * relationships and what operations can be execute concurrently without creating a data dependency conflict.
29 * A replace/delete operation cannot be applied to this node if the subtree version does not match. This mismatch
30 * still allows modifications to its descendants.
33 * A mismatch in node version indicates a replacement, preventing a modification of descendants or itself.
35 // FIXME: BUG-2399: clarify that versioning rules are not enforced for non-presence containers, as they are not
36 // considered to be data nodes.
38 public abstract class TreeNode implements Identifiable<PathArgument>, StoreTreeNode<TreeNode> {
39 private final NormalizedNode data;
40 private final Version version;
42 TreeNode(final NormalizedNode data, final Version version) {
43 this.data = requireNonNull(data);
44 this.version = requireNonNull(version);
48 public final PathArgument getIdentifier() {
49 return data.getIdentifier();
53 * Get the data node version. This version is updated whenever the data representation of this particular node
54 * changes as a result of a direct write to this node or to its parent nodes -- thus indicating that this node
55 * was logically replaced.
57 * @return Current data node version.
59 public final Version getVersion() {
64 * Get the subtree version. This version is updated whenever the data representation of this particular node
65 * changes as the result of a direct or indirect child node being created, replaced or removed.
67 * @return Current subtree version.
69 public abstract Version getSubtreeVersion();
72 * Get a read-only view of the underlying data.
74 * @return Unmodifiable view of the underlying data.
76 public final NormalizedNode getData() {
81 * Get a mutable, isolated copy of the node.
83 * @return Mutable copy
85 public abstract MutableTreeNode mutable();
88 public final String toString() {
89 return addToStringAttributes(MoreObjects.toStringHelper(this).add("version", version)).toString();
92 abstract ToStringHelper addToStringAttributes(ToStringHelper helper);