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 static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects.ToStringHelper;
14 import org.opendaylight.yangtools.util.MapAdaptor;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 * A container node which has been modified. It tracks the subtree version and all modified children.
21 abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
22 private final Map<PathArgument, TreeNode> children;
23 private final Version subtreeVersion;
25 protected AbstractModifiedContainerNode(final NormalizedNode data, final Version version,
26 final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
28 this.subtreeVersion = requireNonNull(subtreeVersion);
29 this.children = requireNonNull(children);
32 protected final TreeNode getModifiedChild(final PathArgument childId) {
33 return children.get(childId);
36 protected final Map<PathArgument, TreeNode> snapshotChildren() {
37 return MapAdaptor.getDefaultInstance().takeSnapshot(children);
41 public final Version getSubtreeVersion() {
42 return subtreeVersion;
46 protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
47 return helper.add("subtreeVersion", subtreeVersion).add("children", children);