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.api.schema.tree.spi;
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.util.MapAdaptor;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 * A container node which has been modified. It tracks the subtree version and all modified children.
20 abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
21 private final Map<PathArgument, TreeNode> children;
22 private final Version subtreeVersion;
24 protected AbstractModifiedContainerNode(final NormalizedNode<?, ?> data, final Version version,
25 final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
27 this.subtreeVersion = Preconditions.checkNotNull(subtreeVersion);
28 this.children = Preconditions.checkNotNull(children);
31 protected final TreeNode getModifiedChild(final PathArgument childId) {
32 return children.get(childId);
35 protected final Map<PathArgument, TreeNode> snapshotChildren() {
36 return MapAdaptor.getDefaultInstance().takeSnapshot(children);
40 public final Version getSubtreeVersion() {
41 return subtreeVersion;
45 protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
46 return helper.add("subtreeVersion", subtreeVersion).add("children", children);