Separate out ModificationApplyOperation.verifyStructure()
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / InMemoryDataTreeCandidate.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.impl.schema.tree;
9
10 import com.google.common.base.MoreObjects;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
16
17 final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
18
19     private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
20         RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
21             super(mod, oldMeta, newMeta);
22         }
23
24         @Override
25         @Nonnull
26         public PathArgument getIdentifier() {
27             throw new IllegalStateException("Attempted to get identifier of the root node");
28         }
29     }
30
31     private final RootNode root;
32
33     InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
34             final TreeNode beforeRoot, final TreeNode afterRoot) {
35         super(rootPath);
36         this.root = new RootNode(modificationRoot, beforeRoot, afterRoot);
37     }
38
39     @Override
40     @Nonnull
41     protected TreeNode getTipRoot() {
42         return root.getNewMeta();
43     }
44
45     TreeNode getBeforeRoot() {
46         return root.getOldMeta();
47     }
48
49     @Override
50     public DataTreeCandidateNode getRootNode() {
51         return root;
52     }
53
54     @Override
55     public String toString() {
56         return MoreObjects.toStringHelper(this).add("rootPath", getRootPath())
57                 .add("rootNode", getRootNode()).toString();
58     }
59 }