BUG-1092: rename data.api.InstanceIdentifier to YangInstanceIdentifier
[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 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.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
17
18 import java.util.Collections;
19
20 /**
21  * Internal utility class for an empty candidate. We instantiate this class
22  * for empty modifications, saving memory and processing speed. Instances
23  * of this class are explicitly recognized and processing of them is skipped.
24  */
25 final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
26     private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() {
27         @Override
28         public ModificationType getModificationType() {
29             return ModificationType.UNMODIFIED;
30         }
31
32         @Override
33         public Iterable<DataTreeCandidateNode> getChildNodes() {
34             return Collections.emptyList();
35         }
36
37         @Override
38         public PathArgument getIdentifier() {
39             throw new IllegalStateException("Attempted to read identifier of the no-operation change");
40         }
41
42         @Override
43         public Optional<NormalizedNode<?, ?>> getDataAfter() {
44             return Optional.absent();
45         }
46
47         @Override
48         public Optional<NormalizedNode<?, ?>> getDataBefore() {
49             return Optional.absent();
50         }
51     };
52
53     protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot) {
54         super(rootPath);
55         Preconditions.checkArgument(modificationRoot.getType() == ModificationType.UNMODIFIED);
56     }
57
58     @Override
59     public DataTreeCandidateNode getRootNode() {
60         return ROOT;
61     }
62 }