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