2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Collection;
15 import java.util.Optional;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
25 * Internal utility class for an empty candidate. We instantiate this class
26 * for empty modifications, saving memory and processing speed. Instances
27 * of this class are explicitly recognized and processing of them is skipped.
29 final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
30 private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() {
32 public ModificationType getModificationType() {
33 return ModificationType.UNMODIFIED;
37 public Collection<DataTreeCandidateNode> getChildNodes() {
38 return ImmutableList.of();
42 public PathArgument getIdentifier() {
43 throw new IllegalStateException("Attempted to read identifier of the no-operation change");
47 public Optional<NormalizedNode<?, ?>> getDataAfter() {
48 return Optional.empty();
52 public Optional<NormalizedNode<?, ?>> getDataBefore() {
53 return Optional.empty();
57 public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
62 private final @NonNull TreeNode afterRoot;
64 protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
65 final TreeNode afterRoot) {
67 checkArgument(modificationRoot.getOperation() == LogicalOperation.NONE);
68 this.afterRoot = requireNonNull(afterRoot);
72 public DataTreeCandidateNode getRootNode() {
77 protected TreeNode getTipRoot() {