/* * 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.concepts.Identifiable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode; /** * A very basic data tree node. It has a version (when it was last modified), a subtree version (when any of its * children were modified) and some read-only data. * *

* Semantic difference between these two is important when dealing with modifications involving parent/child * relationships and what operations can be execute concurrently without creating a data dependency conflict. * *

* A replace/delete operation cannot be applied to this node if the subtree version does not match. This mismatch * still allows modifications to its descendants. * *

* A mismatch in node version indicates a replacement, preventing a modification of descendants or itself. */ // 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 abstract class TreeNode implements Identifiable, StoreTreeNode { 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 * was logically replaced. * * @return Current data node version. */ public final Version getVersion() { return version; } /** * Get the subtree version. This version is updated whenever the data representation of this particular node * changes as the result of a direct or indirect child node being created, replaced or removed. * * @return Current subtree version. */ public abstract Version getSubtreeVersion(); /** * Get a read-only view of the underlying data. * * @return Unmodifiable view of the underlying data. */ public final NormalizedNode getData() { return data; } /** * Get a mutable, isolated copy of the node. * * @return Mutable copy */ public abstract MutableTreeNode mutable(); @Override public final String toString() { return addToStringAttributes(MoreObjects.toStringHelper(this).add("version", version)).toString(); } abstract ToStringHelper addToStringAttributes(ToStringHelper helper); }