Move case statement implementations
[yangtools.git] / data / yang-data-spi / src / main / java / org / opendaylight / yangtools / yang / data / spi / tree / 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.spi.tree;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.util.Map;
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;
17
18 /**
19  * A container node which has been modified. It tracks the subtree version and all modified children.
20  */
21 abstract class AbstractModifiedContainerNode extends AbstractContainerNode {
22     private final Map<PathArgument, TreeNode> children;
23     private final Version subtreeVersion;
24
25     protected AbstractModifiedContainerNode(final NormalizedNode data, final Version version,
26             final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
27         super(data, version);
28         this.subtreeVersion = requireNonNull(subtreeVersion);
29         this.children = requireNonNull(children);
30     }
31
32     protected final TreeNode getModifiedChild(final PathArgument childId) {
33         return children.get(childId);
34     }
35
36     protected final Map<PathArgument, TreeNode> snapshotChildren() {
37         return MapAdaptor.getDefaultInstance().takeSnapshot(children);
38     }
39
40     @Override
41     public final Version getSubtreeVersion() {
42         return subtreeVersion;
43     }
44
45     @Override
46     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
47         return helper.add("subtreeVersion", subtreeVersion).add("children", children);
48     }
49 }