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 / NoopDataTreeCandidate.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.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import java.util.Collections;
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.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
20
21 /**
22  * Internal utility class for an empty candidate. We instantiate this class
23  * for empty modifications, saving memory and processing speed. Instances
24  * of this class are explicitly recognized and processing of them is skipped.
25  */
26 final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
27     private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() {
28         @Override
29         public ModificationType getModificationType() {
30             return ModificationType.UNMODIFIED;
31         }
32
33         @Override
34         public Collection<DataTreeCandidateNode> getChildNodes() {
35             return Collections.emptyList();
36         }
37
38         @Override
39         public PathArgument getIdentifier() {
40             throw new IllegalStateException("Attempted to read identifier of the no-operation change");
41         }
42
43         @Override
44         public Optional<NormalizedNode<?, ?>> getDataAfter() {
45             return Optional.absent();
46         }
47
48         @Override
49         public Optional<NormalizedNode<?, ?>> getDataBefore() {
50             return Optional.absent();
51         }
52
53         @Override
54         public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
55             return null;
56         }
57     };
58     private final TreeNode afterRoot;
59
60     protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot, final TreeNode afterRoot) {
61         super(rootPath);
62         Preconditions.checkArgument(modificationRoot.getOperation() == LogicalOperation.NONE);
63         this.afterRoot = Preconditions.checkNotNull(afterRoot);
64     }
65
66     @Override
67     public DataTreeCandidateNode getRootNode() {
68         return ROOT;
69     }
70
71     @Override
72     protected TreeNode getTipRoot() {
73         return afterRoot;
74     }
75 }