*/
package org.opendaylight.yangtools.yang.data.api.schema.tree;
+import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import com.google.common.base.Optional;
-
/**
* A single node within a {@link DataTreeCandidate}. The nodes are organized
* in tree hierarchy, reflecting the modification from which this candidate
* tree restricted to the modified nodes.
*/
public interface DataTreeCandidateNode {
+
/**
* Get the node identifier.
*
* @return The node identifier.
*/
- PathArgument getIdentifier();
+ @Nonnull PathArgument getIdentifier();
/**
* Get an unmodifiable iterable of modified child nodes.
*
* @return Unmodifiable iterable of modified child nodes.
*/
- Iterable<DataTreeCandidateNode> getChildNodes();
+ @Nonnull Iterable<DataTreeCandidateNode> getChildNodes();
+
+ /**
+ * Returns modified child or null if child was not modified
+ * / does not exists.
+ *
+ * @param identifier Identifier of child node
+ * @return Modified child or null if child was not modified.
+ */
+ @Nullable DataTreeCandidateNode getModifiedChild(PathArgument identifier);
/**
* Return the type of modification this node is undergoing.
*
* @return Node modification type.
*/
- ModificationType getModificationType();
+ @Nonnull ModificationType getModificationType();
/**
* Return the before-image of data corresponding to the node.
}
}
+ private DataTreeCandidateNode childNode(final ModifiedNode input) {
+ final PathArgument id = input.getIdentifier();
+ return new ChildNode(input, childMeta(oldMeta, id), childMeta(newMeta, id));
+ }
+
@Override
public Iterable<DataTreeCandidateNode> getChildNodes() {
return Iterables.transform(mod.getChildren(), new Function<ModifiedNode, DataTreeCandidateNode>() {
@Override
public DataTreeCandidateNode apply(final ModifiedNode input) {
- final PathArgument id = input.getIdentifier();
- return new ChildNode(input, childMeta(oldMeta, id), childMeta(newMeta, id));
+ return childNode(input);
}
});
}
public Optional<NormalizedNode<?, ?>> getDataBefore() {
return optionalData(oldMeta);
}
+
+ @Override
+ public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+ final Optional<ModifiedNode> childMod = mod.getChild(identifier);
+ if(childMod.isPresent()) {
+ return childNode(mod);
+ }
+ return null;
+ }
}
private static final class ChildNode extends AbstractNode {
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.util.Collections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
-import java.util.Collections;
-
/**
* Internal utility class for an empty candidate. We instantiate this class
* for empty modifications, saving memory and processing speed. Instances
public Optional<NormalizedNode<?, ?>> getDataBefore() {
return Optional.absent();
}
+
+ @Override
+ public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+ return null;
+ }
};
protected NoopDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot) {