yang.data.impl.schema.tree clean-up
[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 javax.annotation.Nonnull;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
15
16 final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
17
18     private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
19         public RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
20             super(mod, oldMeta, newMeta);
21         }
22
23         @Override
24         @Nonnull
25         public PathArgument getIdentifier() {
26             throw new IllegalStateException("Attempted to get identifier of the root node");
27         }
28     }
29
30     private final RootNode root;
31
32     InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
33             final TreeNode beforeRoot, final TreeNode afterRoot) {
34         super(rootPath);
35         this.root = new RootNode(modificationRoot, beforeRoot, afterRoot);
36     }
37
38     @Override
39     @Nonnull
40     protected TreeNode getTipRoot() {
41         return root.getNewMeta();
42     }
43
44     TreeNode getBeforeRoot() {
45         return root.getOldMeta();
46     }
47
48     @Override
49     public DataTreeCandidateNode getRootNode() {
50         return root;
51     }
52 }