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.tree.api;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.base.VerifyException;
13 import java.util.Collection;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 * A single node within a {@link DataTreeCandidate}. The nodes are organized in tree hierarchy, reflecting
22 * the modification from which this candidate was created. The node itself exposes the before- and after-image
23 * of the tree restricted to the modified nodes.
25 public interface DataTreeCandidateNode {
27 * Get the node underlying {@link NormalizedNode#name()}.
29 * @return The node identifier.
31 @NonNull PathArgument name();
34 * Get an unmodifiable collection of modified child nodes. Note that the collection may include
35 * {@link ModificationType#UNMODIFIED} nodes, which the caller is expected to handle as if they were not present.
37 * @return Unmodifiable collection of modified child nodes.
39 @NonNull Collection<DataTreeCandidateNode> childNodes();
42 * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
43 * when there is evidence of the node or its parent being involved in modification which has turned out not to
44 * modify the node's contents.
46 * @param childName Identifier of child node
47 * @return Modified child or {@code null} if the specified child has not been modified
48 * @throws NullPointerException if {@code childNamez} is {@code null}
50 @Nullable DataTreeCandidateNode modifiedChild(PathArgument childName);
53 * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
54 * when there is evidence of the node or its parent being involved in modification which has turned out not to
55 * modify the node's contents.
57 * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on
58 * {@link #modifiedChild(PathArgument)}.
59 * @param childName Identifier of child node
60 * @return Modified child or empty.
61 * @throws NullPointerException if {@code childIdentifier} is {@code null}
63 default @NonNull Optional<DataTreeCandidateNode> findModifiedChild(final PathArgument childName) {
64 return Optional.ofNullable(modifiedChild(childName));
68 * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
69 * when there is evidence of the node or its parent being involved in modification which has turned out not to
70 * modify the node's contents.
72 * @implSpec Default implementation defers to {@link #modifiedChild(PathArgument)}.
73 * @param childName Identifier of child node
74 * @return Modified child
75 * @throws NullPointerException if {@code childName} is {@code null}
76 * @throws VerifyException if no modified child with specified name is found
78 default @NonNull DataTreeCandidateNode getModifiedChild(final PathArgument childName) {
79 return verifyNotNull(modifiedChild(childName), "No modified child named %s", childName);
83 * Return the type of modification this node is undergoing.
85 * @return Node modification type.
87 @NonNull ModificationType modificationType();
90 * Return the before-image of data corresponding to the node.
92 * @return Node data as they were present in the tree before the modification was applied.
94 @Nullable NormalizedNode dataBefore();
97 * Return the before-image of data corresponding to the node.
99 * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataBefore()}.
100 * @return Node data as they were present in the tree before the modification was applied, or empty.
102 default @NonNull Optional<NormalizedNode> findDataBefore() {
103 return Optional.ofNullable(dataBefore());
107 * Return the before-image of data corresponding to the node.
109 * @implSpec Default implementation defers to {@link #dataBefore()}.
110 * @return Node data as they were present in the tree before the modification was applied.
111 * @throws VerifyException if no before-image is present
113 default @NonNull NormalizedNode getDataBefore() {
114 return verifyNotNull(dataBefore(), "No before-image available");
118 * Return the after-image of data corresponding to the node.
120 * @return Node data as they will be present in the tree after the modification is applied
122 @Nullable NormalizedNode dataAfter();
125 * Return the after-image of data corresponding to the node.
127 * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataAfter()}.
128 * @return Node data as they will be present in the tree after the modification is applied, or empty
130 default @NonNull Optional<NormalizedNode> findDataAfter() {
131 return Optional.ofNullable(dataAfter());
135 * Return the after-image of data corresponding to the node.
137 * @implSpec Default implementation defers to {@link #dataAfter()}.
138 * @return Node data as they will be present in the tree after the modification is applied.
139 * @throws VerifyException if no after-image is present
141 default @NonNull NormalizedNode getDataAfter() {
142 return verifyNotNull(dataAfter(), "No after-image available");