Revert "Bug 5504 - Controller crashes with OOM. oldRoot/currentRoot, toString()"
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / tree / spi / AbstractModifiedContainerNode.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
9
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.base.Preconditions;
12 import java.util.Map;
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;
16
17 /**
18  * A container node which has been modified. It tracks the subtree version and all modified children.
19  */
20 abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
21     private final Map<PathArgument, TreeNode> children;
22     private final Version subtreeVersion;
23
24     protected AbstractModifiedContainerNode(final NormalizedNode<?, ?> data, final Version version,
25             final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
26         super(data, version);
27         this.subtreeVersion = Preconditions.checkNotNull(subtreeVersion);
28         this.children = Preconditions.checkNotNull(children);
29     }
30
31     protected final TreeNode getModifiedChild(final PathArgument childId) {
32         return children.get(childId);
33     }
34
35     protected final Map<PathArgument, TreeNode> snapshotChildren() {
36         return MapAdaptor.getDefaultInstance().takeSnapshot(children);
37     }
38
39     @Override
40     public final Version getSubtreeVersion() {
41         return subtreeVersion;
42     }
43
44     @Override
45     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
46         return helper.add("subtreeVersion", subtreeVersion).add("children", children);
47     }
48 }