Refactor ModificationApplyOperation
[yangtools.git] / data / yang-data-tree-ri / src / main / java / org / opendaylight / yangtools / yang / data / tree / impl / 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.tree.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
17 import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
18
19 final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
20     private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
21         RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
22             super(mod, oldMeta, newMeta);
23         }
24
25         @Override
26         public PathArgument name() {
27             throw new IllegalStateException("Attempted to get identifier of the root node");
28         }
29     }
30
31     private final @NonNull RootNode root;
32
33     InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
34             final TreeNode beforeRoot, final TreeNode afterRoot) {
35         super(rootPath);
36         root = new RootNode(modificationRoot, requireNonNull(beforeRoot), requireNonNull(afterRoot));
37     }
38
39     @Override
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
53     @Override
54     public String toString() {
55         return MoreObjects.toStringHelper(this).add("rootPath", getRootPath()).add("rootNode", getRootNode())
56             .toString();
57     }
58 }