import static java.util.Objects.requireNonNull;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- throw new UnsupportedOperationException("Not implemented");
+ public final ModificationType modificationType() {
+ return type;
}
@Override
- public final ModificationType getModificationType() {
- return type;
+ public final DataTreeCandidateNode modifiedChild(final PathArgument identifier) {
+ throw new UnsupportedOperationException("Not implemented");
}
@Override
- public final Optional<NormalizedNode> getDataBefore() {
+ public final NormalizedNode dataBefore() {
throw new UnsupportedOperationException("Before-image not available after serialization");
}
}
*/
package org.opendaylight.yangtools.yang.data.codec.binfmt;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.ArrayList;
out.writeYangInstanceIdentifier(candidate.getRootPath());
final var node = candidate.getRootNode();
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case APPEARED -> {
out.writeByte(APPEARED);
- writeChildren(out, node.getChildNodes());
+ writeChildren(out, node.childNodes());
}
case DELETE -> out.writeByte(DELETE);
case DISAPPEARED -> {
out.writeByte(DISAPPEARED);
- writeChildren(out, node.getChildNodes());
+ writeChildren(out, node.childNodes());
}
case SUBTREE_MODIFIED -> {
out.writeByte(SUBTREE_MODIFIED);
- writeChildren(out, node.getChildNodes());
+ writeChildren(out, node.childNodes());
}
case UNMODIFIED -> out.writeByte(UNMODIFIED);
case WRITE -> {
out.writeByte(WRITE);
- out.writeNormalizedNode(node.getDataAfter().orElseThrow());
+ out.writeNormalizedNode(verifyNotNull(node.dataAfter()));
}
default -> throw unhandledNodeType(node);
}
private static void writeNode(final NormalizedNodeDataOutput out, final DataTreeCandidateNode node)
throws IOException {
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case APPEARED -> {
out.writeByte(APPEARED);
- out.writePathArgument(node.getIdentifier());
- writeChildren(out, node.getChildNodes());
+ out.writePathArgument(node.name());
+ writeChildren(out, node.childNodes());
}
case DELETE -> {
out.writeByte(DELETE);
- out.writePathArgument(node.getIdentifier());
+ out.writePathArgument(node.name());
}
case DISAPPEARED -> {
out.writeByte(DISAPPEARED);
- out.writePathArgument(node.getIdentifier());
- writeChildren(out, node.getChildNodes());
+ out.writePathArgument(node.name());
+ writeChildren(out, node.childNodes());
}
case SUBTREE_MODIFIED -> {
out.writeByte(SUBTREE_MODIFIED);
- out.writePathArgument(node.getIdentifier());
- writeChildren(out, node.getChildNodes());
+ out.writePathArgument(node.name());
+ writeChildren(out, node.childNodes());
}
case WRITE -> {
out.writeByte(WRITE);
- out.writeNormalizedNode(node.getDataAfter().orElseThrow());
+ out.writeNormalizedNode(verifyNotNull(node.dataAfter()));
}
case UNMODIFIED -> {
out.writeByte(UNMODIFIED);
}
private static IllegalArgumentException unhandledNodeType(final DataTreeCandidateNode node) {
- return new IllegalArgumentException("Unhandled node type " + node.getModificationType());
+ return new IllegalArgumentException("Unhandled node type " + node.modificationType());
}
}
*/
package org.opendaylight.yangtools.yang.data.codec.binfmt;
+import static java.util.Objects.requireNonNull;
+
import java.util.Collection;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
static DataTreeCandidateNode create() {
return new DeletedDataTreeCandidateNode() {
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
throw new UnsupportedOperationException("Root node does not have an identifier");
}
};
}
static DataTreeCandidateNode create(final PathArgument identifier) {
+ final var name = requireNonNull(identifier);
return new DeletedDataTreeCandidateNode() {
@Override
- public PathArgument getIdentifier() {
- return identifier;
+ public PathArgument name() {
+ return name;
}
};
}
@Override
- public final Optional<NormalizedNode> getDataAfter() {
- return Optional.empty();
+ public final NormalizedNode dataAfter() {
+ return null;
}
@Override
- public final Collection<DataTreeCandidateNode> getChildNodes() {
+ public final Collection<DataTreeCandidateNode> childNodes() {
// We would require the before-image to reconstruct the list of nodes which
// were deleted.
throw new UnsupportedOperationException("Children not available after serialization");
import static java.util.Objects.requireNonNull;
import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
* one of its children.
*/
abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
- private final Collection<DataTreeCandidateNode> children;
+ private final @NonNull Collection<DataTreeCandidateNode> children;
private ModifiedDataTreeCandidateNode(final ModificationType type,
final Collection<DataTreeCandidateNode> children) {
static DataTreeCandidateNode create(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
return new ModifiedDataTreeCandidateNode(type, children) {
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
throw new UnsupportedOperationException("Root node does not have an identifier");
}
};
static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type,
final Collection<DataTreeCandidateNode> children) {
+ final var name = requireNonNull(identifier);
return new ModifiedDataTreeCandidateNode(type, children) {
@Override
- public PathArgument getIdentifier() {
- return identifier;
+ public PathArgument name() {
+ return name;
}
};
}
@Override
- public final Optional<NormalizedNode> getDataAfter() {
+ public final NormalizedNode dataAfter() {
throw new UnsupportedOperationException("After-image not available after serialization");
}
@Override
- public final Collection<DataTreeCandidateNode> getChildNodes() {
+ public final Collection<DataTreeCandidateNode> childNodes() {
return children;
}
}
package org.opendaylight.yangtools.yang.data.codec.binfmt;
import java.util.Collection;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
}
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
throw new UnsupportedOperationException("Root node does not have an identifier");
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
+ public NormalizedNode dataAfter() {
throw new UnsupportedOperationException("After-image not available after serialization");
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
+ public Collection<DataTreeCandidateNode> childNodes() {
throw new UnsupportedOperationException("Children not available after serialization");
}
}
\ No newline at end of file
}
private static void assertEqualMod(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) {
- assertEquals(expected.getModificationType(), actual.getModificationType());
+ assertEquals(expected.modificationType(), actual.modificationType());
- switch (expected.getModificationType()) {
+ switch (expected.modificationType()) {
case DELETE:
case UNMODIFIED:
// No children to verify
break;
default:
- final Collection<DataTreeCandidateNode> expectedChildren = expected.getChildNodes();
- final Collection<DataTreeCandidateNode> actualChildren = actual.getChildNodes();
+ final Collection<DataTreeCandidateNode> expectedChildren = expected.childNodes();
+ final Collection<DataTreeCandidateNode> actualChildren = actual.childNodes();
assertEquals(expectedChildren.size(), actualChildren.size());
final Iterator<DataTreeCandidateNode> ait = actualChildren.iterator();
}
private static void assertEqualNodes(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) {
- assertEquals(expected.getIdentifier(), actual.getIdentifier());
+ assertEquals(expected.name(), actual.name());
assertEqualMod(expected, actual);
}
}
import java.util.Collection;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
* of the tree restricted to the modified nodes.
*/
public interface DataTreeCandidateNode {
+ /**
+ * Get the node underlying {@link NormalizedNode#name()}.
+ *
+ * @return The node identifier.
+ */
+ @NonNull PathArgument name();
+
/**
* Get the node identifier.
*
+ * @implSpec Default implementation defers to {@link #name()}.
* @return The node identifier.
+ * @deprecated Use {@link #name()} instead.
+ */
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull PathArgument getIdentifier() {
+ return name();
+ }
+
+ /**
+ * Get an unmodifiable collection of modified child nodes. Note that the collection may include
+ * {@link ModificationType#UNMODIFIED} nodes, which the caller is expected to handle as if they were not present.
+ *
+ * @return Unmodifiable collection of modified child nodes.
*/
- @NonNull PathArgument getIdentifier();
+ @NonNull Collection<DataTreeCandidateNode> childNodes();
/**
* Get an unmodifiable collection of modified child nodes. Note that the collection may include
* {@link ModificationType#UNMODIFIED} nodes, which the caller is expected to handle as if they were not present.
*
+ * @implSpec Default implementation defers to {@link #childNodes()}.
* @return Unmodifiable collection of modified child nodes.
+ * @deprecated Use {@link #childNodes()} instead.
+ */
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull Collection<DataTreeCandidateNode> getChildNodes() {
+ return childNodes();
+ }
+
+ /**
+ * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
+ * when there is evidence of the node or its parent being involved in modification which has turned out not to
+ * modify the node's contents.
+ *
+ * @param childName Identifier of child node
+ * @return Modified child or {@code null} if the specified child has not been modified
+ * @throws NullPointerException if {@code childNamez} is {@code null}
+ */
+ @Nullable DataTreeCandidateNode modifiedChild(PathArgument childName);
+
+ /**
+ * Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
+ * when there is evidence of the node or its parent being involved in modification which has turned out not to
+ * modify the node's contents.
+ *
+ * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on
+ * {@link #modifiedChild(PathArgument)}.
+ * @param childName Identifier of child node
+ * @return Modified child or empty.
+ * @throws NullPointerException if {@code childIdentifier} is {@code null}
*/
- @NonNull Collection<DataTreeCandidateNode> getChildNodes();
+ default @NonNull Optional<DataTreeCandidateNode> findModifiedChild(final PathArgument childName) {
+ return Optional.ofNullable(modifiedChild(childName));
+ }
/**
* Returns modified child or empty. Note that this method may return an {@link ModificationType#UNMODIFIED} node
* when there is evidence of the node or its parent being involved in modification which has turned out not to
* modify the node's contents.
*
- * @param childIdentifier Identifier of child node
+ * @implSpec Default implementation defers to {@link #findModifiedChild(PathArgument)}.
+ * @param childName Identifier of child node
* @return Modified child or empty.
- * @throws NullPointerException if {@code childIdentifier} is null
+ * @throws NullPointerException if {@code childIdentifier} is {@code null}
+ * @deprecated Use {@link #modifiedChild(PathArgument)} or {@link #findModifiedChild(PathArgument)} instead.
*/
- @NonNull Optional<DataTreeCandidateNode> getModifiedChild(PathArgument childIdentifier);
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childName) {
+ return findModifiedChild(childName);
+ }
/**
* Return the type of modification this node is undergoing.
*
* @return Node modification type.
*/
- @NonNull ModificationType getModificationType();
+ @NonNull ModificationType modificationType();
/**
- * Return the after-image of data corresponding to the node.
+ * Return the type of modification this node is undergoing.
+ *
+ * @implSpec Default implementation defers to {@link #modificationType()}.
+ * @return Node modification type.
+ * @deprecated Use {@link #modificationType()} instead.
+ */
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull ModificationType getModificationType() {
+ return modificationType();
+ }
+
+ /**
+ * Return the before-image of data corresponding to the node.
*
- * @return Node data as they will be present in the tree after
- * the modification is applied.
+ * @return Node data as they were present in the tree before the modification was applied.
*/
- @NonNull Optional<NormalizedNode> getDataAfter();
+ @Nullable NormalizedNode dataBefore();
/**
* Return the before-image of data corresponding to the node.
*
- * @return Node data as they were present in the tree before
- * the modification was applied.
+ * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataBefore()}.
+ * @return Node data as they were present in the tree before the modification was applied, or empty.
+ */
+ default @NonNull Optional<NormalizedNode> findDataBefore() {
+ return Optional.ofNullable(dataBefore());
+ }
+
+ /**
+ * Return the before-image of data corresponding to the node.
+ *
+ * @implSpec Default implementation defers to {@link #findDataBefore()}.
+ * @return Node data as they were present in the tree before the modification was applied.
+ * @deprecated Use {@link #dataBefore()} or {@link #findDataBefore()} instead.
+ */
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull Optional<NormalizedNode> getDataBefore() {
+ return findDataBefore();
+ }
+
+ /**
+ * Return the after-image of data corresponding to the node.
+ *
+ * @return Node data as they will be present in the tree after the modification is applied
+ */
+ @Nullable NormalizedNode dataAfter();
+
+ /**
+ * Return the after-image of data corresponding to the node.
+ *
+ * @implSpec Default implementation defers to {@link Optional#ofNullable(Object)} based on {@link #dataAfter()}.
+ * @return Node data as they will be present in the tree after the modification is applied, or empty
+ */
+ default @NonNull Optional<NormalizedNode> findDataAfter() {
+ return Optional.ofNullable(dataAfter());
+ }
+
+ /**
+ * Return the after-image of data corresponding to the node.
+ *
+ * @implSpec Default implementation defers to {@link #findDataAfter()}.
+ * @return Node data as they will be present in the tree after the modification is applied.
+ * @deprecated Use {@link #dataAfter()} or {@link #findDataAfter()} instead.
*/
- @NonNull Optional<NormalizedNode> getDataBefore();
+ @Deprecated(since = "11.0.0", forRemoval = true)
+ default @NonNull Optional<NormalizedNode> getDataAfter() {
+ return findDataAfter();
+ }
}
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
return meta == null ? null : (DistinctNodeContainer<PathArgument, NormalizedNode>)meta.getData();
}
- private ChildNode childNode(final ModifiedNode childMod) {
- final PathArgument id = childMod.getIdentifier();
+ private @NonNull ChildNode childNode(final ModifiedNode childMod) {
+ final var id = childMod.getIdentifier();
return new ChildNode(childMod, childMeta(oldMeta, id), childMeta(newMeta, id));
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
+ public Collection<DataTreeCandidateNode> childNodes() {
return switch (mod.getModificationType()) {
case APPEARED, DISAPPEARED, SUBTREE_MODIFIED -> Collections2.transform(mod.getChildren(), this::childNode);
case UNMODIFIED -> {
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return verifyNotNull(mod.getModificationType(), "Node %s does not have resolved modification type", mod);
}
- private static @NonNull Optional<NormalizedNode> optionalData(final TreeNode meta) {
- return meta == null ? Optional.empty() : Optional.of(meta.getData());
+ @Override
+ public final NormalizedNode dataBefore() {
+ return data(oldMeta);
}
@Override
- public final Optional<NormalizedNode> getDataAfter() {
- return optionalData(newMeta);
+ public final NormalizedNode dataAfter() {
+ return data(newMeta);
}
- @Override
- public final Optional<NormalizedNode> getDataBefore() {
- return optionalData(oldMeta);
+ private static @Nullable NormalizedNode data(final TreeNode meta) {
+ return meta == null ? null : meta.getData();
}
+
@Override
- public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
+ public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ final var identifier = requireNonNull(childName);
return switch (mod.getModificationType()) {
case APPEARED, DISAPPEARED, SUBTREE_MODIFIED -> {
- final ModifiedNode child = mod.childByArg(identifier);
- yield child == null ? Optional.empty() : Optional.of(childNode(child));
+ final var child = mod.childByArg(identifier);
+ yield child == null ? null : childNode(child);
}
case UNMODIFIED -> {
if (!canHaveChildren(oldMeta, newMeta)) {
- yield Optional.empty();
+ yield null;
}
- yield getContainer(newMeta != null ? newMeta : oldMeta)
- .findChildByArg(identifier)
- .map(DataTreeCandidateNodes::unmodified);
+ final var child = getContainer(newMeta != null ? newMeta : oldMeta).childByArg(identifier);
+ yield child == null ? null : DataTreeCandidateNodes.unmodified(child);
}
case DELETE, WRITE -> {
if (!canHaveChildren(oldMeta, newMeta)) {
- yield Optional.empty();
+ yield null;
}
yield DataTreeCandidateNodes.containerDelta(getContainer(oldMeta), getContainer(newMeta), identifier);
}
}
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
return getMod().getIdentifier();
}
}
import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
-
private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode {
RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) {
super(mod, oldMeta, newMeta);
}
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
throw new IllegalStateException("Attempted to get identifier of the root node");
}
}
InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot,
final TreeNode beforeRoot, final TreeNode afterRoot) {
super(rootPath);
- this.root = new RootNode(modificationRoot, beforeRoot, afterRoot);
+ root = new RootNode(modificationRoot, beforeRoot, afterRoot);
}
@Override
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Optional;
+import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
final class NoopDataTreeCandidate extends AbstractDataTreeCandidate {
private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() {
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.UNMODIFIED;
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
- return ImmutableList.of();
+ public Collection<DataTreeCandidateNode> childNodes() {
+ return List.of();
}
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
throw new IllegalStateException("Attempted to read identifier of the no-operation change");
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.empty();
+ public NormalizedNode dataAfter() {
+ return null;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.empty();
+ public NormalizedNode dataBefore() {
+ return null;
}
@Override
- public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- return Optional.empty();
+ public DataTreeCandidateNode modifiedChild(final PathArgument identifier) {
+ return null;
}
};
*/
package org.opendaylight.yangtools.yang.data.tree.leafref;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayDeque;
public static void validate(final DataTreeCandidate tree, final LeafRefContext rootLeafRefCtx)
throws LeafRefDataValidationFailedException {
- final var root = tree.getRootNode().getDataAfter();
- if (root.isPresent()) {
- new LeafRefValidation(root.orElseThrow())
- .validateChildren(rootLeafRefCtx, tree.getRootNode().getChildNodes());
+ final var root = tree.getRootNode().dataAfter();
+ if (root != null) {
+ new LeafRefValidation(root).validateChildren(rootLeafRefCtx, tree.getRootNode().childNodes());
}
}
private void validateChildren(final LeafRefContext rootLeafRefCtx, final Collection<DataTreeCandidateNode> children)
throws LeafRefDataValidationFailedException {
for (var dataTreeCandidateNode : children) {
- if (dataTreeCandidateNode.getModificationType() != ModificationType.UNMODIFIED) {
- final PathArgument identifier = dataTreeCandidateNode.getIdentifier();
+ if (dataTreeCandidateNode.modificationType() != ModificationType.UNMODIFIED) {
+ final PathArgument identifier = dataTreeCandidateNode.name();
final QName childQName = identifier.getNodeType();
final LeafRefContext referencedByCtx = rootLeafRefCtx.getReferencedChildByName(childQName);
}
private void validateNode(final DataTreeCandidateNode node, final LeafRefContext referencedByCtx,
- final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
+ final LeafRefContext referencingCtx, final YangInstanceIdentifier current) {
+ final var modType = node.modificationType();
- if (node.getModificationType() == ModificationType.WRITE && node.getDataAfter().isPresent()) {
- validateNodeData(node.getDataAfter().orElseThrow(), referencedByCtx, referencingCtx,
- node.getModificationType(), current);
+ if (modType == ModificationType.WRITE) {
+ final var dataAfter = node.dataAfter();
+ if (dataAfter != null) {
+ validateNodeData(dataAfter, referencedByCtx, referencingCtx, ModificationType.WRITE, current);
+ }
return;
}
- if (node.getModificationType() == ModificationType.DELETE && referencedByCtx != null) {
- validateNodeData(node.getDataBefore().orElseThrow(), referencedByCtx, null, node.getModificationType(),
- current);
+ if (modType == ModificationType.DELETE && referencedByCtx != null) {
+ validateNodeData(verifyNotNull(node.dataBefore()), referencedByCtx, null, node.modificationType(), current);
return;
}
- for (var childNode : node.getChildNodes()) {
- if (childNode.getModificationType() != ModificationType.UNMODIFIED) {
+ for (var childNode : node.childNodes()) {
+ if (childNode.modificationType() != ModificationType.UNMODIFIED) {
final LeafRefContext childReferencedByCtx = getReferencedByCtxChild(referencedByCtx, childNode);
final LeafRefContext childReferencingCtx = getReferencingCtxChild(referencingCtx, childNode);
if (childReferencedByCtx != null || childReferencingCtx != null) {
- validateNode(childNode, childReferencedByCtx,childReferencingCtx,
- current.node(childNode.getIdentifier()));
+ validateNode(childNode, childReferencedByCtx,childReferencingCtx, current.node(childNode.name()));
}
}
}
return null;
}
- final QName childQName = childNode.getIdentifier().getNodeType();
+ final QName childQName = childNode.name().getNodeType();
LeafRefContext childReferencingCtx = referencingCtx.getReferencingChildByName(childQName);
if (childReferencingCtx == null) {
- final NormalizedNode data = childNode.getDataAfter().orElseThrow();
+ final NormalizedNode data = verifyNotNull(childNode.dataAfter());
if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
childReferencingCtx = referencingCtx;
}
return null;
}
- final QName childQName = childNode.getIdentifier().getNodeType();
+ final QName childQName = childNode.name().getNodeType();
LeafRefContext childReferencedByCtx = referencedByCtx.getReferencedChildByName(childQName);
if (childReferencedByCtx == null) {
- final NormalizedNode data = childNode.getDataAfter().orElseThrow();
+ final NormalizedNode data = verifyNotNull(childNode.dataAfter());
if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
childReferencedByCtx = referencedByCtx;
}
final DataTreeCandidate candidate = tree.prepare(mod);
final DataTreeCandidateNode root = candidate.getRootNode();
- assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, root.modificationType());
}
}
package org.opendaylight.yangtools.yang.data.tree.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.data.tree.spi.DataTreeCandidates;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class DataTreeCandidatesTest extends AbstractTestModelTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidatesTest.class);
-
private DataTree dataTree;
@Before
final DataTreeCandidate newCandidate = DataTreeCandidates.newDataTreeCandidate(TestModel.INNER_CONTAINER_PATH,
candidate.getRootNode());
- try {
- // lets see if getting the identifier of the root node throws an exception
- newCandidate.getRootNode().getIdentifier();
- fail();
- } catch (IllegalStateException e) {
- LOG.debug("Cannot get identifier of root node candidate which is correct", e);
- }
+ // lets see if getting the identifier of the root node throws an exception
+ assertThrows(IllegalStateException.class, () -> newCandidate.getRootNode().name());
// lets see if we can apply this rooted candidate to a new dataTree
DataTreeCandidates.applyToModification(newModification,
// The entire transaction needs to fizzle to a no-op
DataTreeCandidate candidate = dataTree.prepare(modification);
DataTreeCandidateNode node = candidate.getRootNode();
- assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, node.modificationType());
// 'test'
- assertUnmodified(1, node.getChildNodes());
+ assertUnmodified(1, node.childNodes());
}
@Test
// The entire transaction needs to fizzle to a no-op
DataTreeCandidate candidate = dataTree.prepare(modification);
DataTreeCandidateNode node = candidate.getRootNode();
- assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, node.modificationType());
// 'test'
- assertUnmodified(1, node.getChildNodes());
+ assertUnmodified(1, node.childNodes());
}
@Test
final DataTreeCandidate candidate = dataTree.prepare(modification);
assertEquals(YangInstanceIdentifier.of(), candidate.getRootPath());
final DataTreeCandidateNode node = candidate.getRootNode();
- assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, node.modificationType());
// 'test'
- assertUnmodified(1, node.getChildNodes());
+ assertUnmodified(1, node.childNodes());
}
@Test
final DataTreeCandidate candidate = dataTree.prepare(modification);
assertEquals(YangInstanceIdentifier.of(), candidate.getRootPath());
final DataTreeCandidateNode node = candidate.getRootNode();
- assertEquals(ModificationType.UNMODIFIED, node.getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, node.modificationType());
// 'non-presence' and 'test'
- assertUnmodified(2, node.getChildNodes());
+ assertUnmodified(2, node.childNodes());
}
@Test
DataTreeCandidate candidate2 = dataTree.prepare(modification2);
dataTree.commit(candidate2);
- DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(Arrays.asList(candidate1,candidate2));
+ DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(ModificationType.UNMODIFIED,aggregateCandidate.getRootNode().getModificationType());
+ assertEquals(ModificationType.UNMODIFIED, aggregateCandidate.getRootNode().modificationType());
}
@Test
DataTreeCandidate candidate2 = dataTree.prepare(modification2);
dataTree.commit(candidate2);
- DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(Arrays.asList(candidate1,candidate2));
+ DataTreeCandidate aggregateCandidate = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(ModificationType.SUBTREE_MODIFIED,aggregateCandidate.getRootNode().getModificationType());
+ assertEquals(ModificationType.SUBTREE_MODIFIED,aggregateCandidate.getRootNode().modificationType());
}
private static void assertUnmodified(final int expSize, final Collection<DataTreeCandidateNode> nodes) {
assertEquals(expSize, nodes.size());
- nodes.forEach(node -> assertEquals(ModificationType.UNMODIFIED, node.getModificationType()));
+ nodes.forEach(node -> assertEquals(ModificationType.UNMODIFIED, node.modificationType()));
}
}
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
abstract class AbstractAvailableLeafCandidateNode extends AbstractLeafCandidateNode {
}
@Override
- public final Optional<NormalizedNode> getDataAfter() {
- return dataOptional();
+ public final NormalizedNode dataAfter() {
+ return data;
}
}
\ No newline at end of file
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
- private final DistinctNodeContainer<PathArgument, NormalizedNode> data;
+ final @NonNull DistinctNodeContainer<PathArgument, NormalizedNode> data;
AbstractDataTreeCandidateNode(final DistinctNodeContainer<PathArgument, NormalizedNode> data) {
this.data = requireNonNull(data);
}
@Override
- public final PathArgument getIdentifier() {
+ public final PathArgument name() {
return data.name();
}
return Optional.of(data);
}
- final DistinctNodeContainer<PathArgument, NormalizedNode> data() {
- return data;
- }
-
@Override
public String toString() {
return this.getClass().getSimpleName() + "{data = " + data + "}";
import static java.util.Objects.requireNonNull;
-import java.util.Collection;
import java.util.List;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
abstract class AbstractLeafCandidateNode implements DataTreeCandidateNode {
- private final NormalizedNode data;
+ final @NonNull NormalizedNode data;
AbstractLeafCandidateNode(final NormalizedNode data) {
this.data = requireNonNull(data);
}
- final @NonNull Optional<NormalizedNode> dataOptional() {
- return Optional.of(data);
- }
-
@Override
- public final Collection<DataTreeCandidateNode> getChildNodes() {
+ public final List<DataTreeCandidateNode> childNodes() {
return List.of();
}
@Override
- public final PathArgument getIdentifier() {
+ public final PathArgument name() {
return data.name();
}
@Override
- public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- requireNonNull(identifier);
- return Optional.empty();
+ public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ requireNonNull(childName);
+ return null;
}
}
\ No newline at end of file
import com.google.common.collect.Collections2;
import java.util.Collection;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- return data().findChildByArg(identifier).map(this::createChild);
+ public final DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ final var child = data.childByArg(childName);
+ return child != null ? createChild(child) : null;
}
@Override
- public final Collection<DataTreeCandidateNode> getChildNodes() {
- return Collections2.transform(data().body(), this::createChild);
+ public final Collection<DataTreeCandidateNode> childNodes() {
+ return Collections2.transform(data.body(), this::createChild);
}
abstract DataTreeCandidateNode createContainer(DistinctNodeContainer<PathArgument, NormalizedNode> childData);
}
@Override
- public final ModificationType getModificationType() {
+ public final ModificationType modificationType() {
return ModificationType.WRITE;
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* @param newData New data container, may be null
* @return A {@link DataTreeCandidateNode} describing the change, or empty if the node is not present
*/
- public static @NonNull Optional<DataTreeCandidateNode> containerDelta(
+ public static @Nullable DataTreeCandidateNode containerDelta(
final @Nullable DistinctNodeContainer<PathArgument, NormalizedNode> oldData,
final @Nullable DistinctNodeContainer<PathArgument, NormalizedNode> newData,
final @NonNull PathArgument child) {
final NormalizedNode newChild = getChild(newData, child);
final NormalizedNode oldChild = getChild(oldData, child);
if (oldChild != null) {
- return Optional.of(newChild != null ? replaceNode(oldChild, newChild) : deleteNode(oldChild));
+ return newChild != null ? replaceNode(oldChild, newChild) : deleteNode(oldChild);
} else if (newChild != null) {
- return Optional.of(DataTreeCandidateNodes.writeNode(newChild));
+ return DataTreeCandidateNodes.writeNode(newChild);
} else {
- return Optional.empty();
+ return null;
}
}
* @param node candidate tree to apply
*/
public static void applyToCursor(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) {
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
- cursor.delete(node.getIdentifier());
+ cursor.delete(node.name());
break;
case SUBTREE_MODIFIED:
- cursor.enter(node.getIdentifier());
- AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.getChildNodes().iterator());
+ cursor.enter(node.name());
+ AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.childNodes().iterator());
do {
iterator = iterator.next(cursor);
} while (iterator != null);
// No-op
break;
case WRITE:
- cursor.write(node.getIdentifier(), node.getDataAfter().orElseThrow());
+ cursor.write(node.name(), verifyNotNull(node.dataAfter()));
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
*/
public static void applyRootedNodeToCursor(final DataTreeModificationCursor cursor,
final YangInstanceIdentifier rootPath, final DataTreeCandidateNode node) {
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
cursor.delete(rootPath.getLastPathArgument());
break;
case SUBTREE_MODIFIED:
cursor.enter(rootPath.getLastPathArgument());
- AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.getChildNodes().iterator());
+ AbstractNodeIterator iterator = new ExitingNodeIterator(null, node.childNodes().iterator());
do {
iterator = iterator.next(cursor);
} while (iterator != null);
// No-op
break;
case WRITE:
- cursor.write(rootPath.getLastPathArgument(), node.getDataAfter().orElseThrow());
+ cursor.write(rootPath.getLastPathArgument(), verifyNotNull(node.dataAfter()));
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
public static void applyRootToCursor(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) {
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
throw new IllegalArgumentException("Can not delete root.");
case WRITE:
case SUBTREE_MODIFIED:
- AbstractNodeIterator iterator = new RootNonExitingIterator(node.getChildNodes().iterator());
+ AbstractNodeIterator iterator = new RootNonExitingIterator(node.childNodes().iterator());
do {
iterator = iterator.next(cursor);
} while (iterator != null);
// No-op
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
final AbstractNodeIterator next(final DataTreeModificationCursor cursor) {
while (iterator.hasNext()) {
final DataTreeCandidateNode node = iterator.next();
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
- cursor.delete(node.getIdentifier());
+ cursor.delete(node.name());
break;
case APPEARED:
case DISAPPEARED:
case SUBTREE_MODIFIED:
- final Collection<DataTreeCandidateNode> children = node.getChildNodes();
+ final var children = node.childNodes();
if (!children.isEmpty()) {
- cursor.enter(node.getIdentifier());
+ cursor.enter(node.name());
return new ExitingNodeIterator(this, children.iterator());
}
break;
// No-op
break;
case WRITE:
- cursor.write(node.getIdentifier(), node.getDataAfter().orElseThrow());
+ cursor.write(node.name(), verifyNotNull(node.dataAfter()));
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
exitNode(cursor);
package org.opendaylight.yangtools.yang.data.tree.spi;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
final DataTreeCandidateNode node = candidate.getRootNode();
final YangInstanceIdentifier path = candidate.getRootPath();
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
modification.delete(path);
LOG.debug("Modification {} deleted path {}", modification, path);
case SUBTREE_MODIFIED:
LOG.debug("Modification {} modified path {}", modification, path);
- NodeIterator iterator = new NodeIterator(null, path, node.getChildNodes().iterator());
+ NodeIterator iterator = new NodeIterator(null, path, node.childNodes().iterator());
do {
iterator = iterator.next(modification);
} while (iterator != null);
// No-op
break;
case WRITE:
- modification.write(path, node.getDataAfter().orElseThrow());
+ modification.write(path, verifyNotNull(node.dataAfter()));
LOG.debug("Modification {} written path {}", modification, path);
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
private static DataTreeCandidateNode fastCompressNode(final DataTreeCandidateNode first,
final List<DataTreeCandidateNode> input) {
- final DataTreeCandidateNode last = input.get(input.size() - 1);
- ModificationType nodeModification = last.getModificationType();
- Optional<NormalizedNode> dataBefore = first.getDataBefore();
- Optional<NormalizedNode> dataAfter = last.getDataAfter();
+ final var last = input.get(input.size() - 1);
+ final var nodeModification = last.modificationType();
+ final var dataBefore = first.dataBefore();
+ final var dataAfter = last.dataAfter();
switch (nodeModification) {
case DELETE:
- ModificationType previous = first.getModificationType();
+ ModificationType previous = first.modificationType();
// Check if node had data before
- if (previous == ModificationType.DELETE
- || previous == ModificationType.DISAPPEARED
- || previous == ModificationType.UNMODIFIED && dataBefore.isEmpty()) {
+ if (previous == ModificationType.DELETE || previous == ModificationType.DISAPPEARED
+ || previous == ModificationType.UNMODIFIED && dataBefore == null) {
illegalModification(ModificationType.DELETE, ModificationType.DELETE);
}
- if (dataBefore.isEmpty()) {
+ if (dataBefore == null) {
return new TerminalDataTreeCandidateNode(null, ModificationType.UNMODIFIED, null, null);
}
- return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore.orElseThrow(), null);
+ return new TerminalDataTreeCandidateNode(null, nodeModification, verifyNotNull(dataBefore), null);
case WRITE:
- return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore.orElse(null),
- dataAfter.orElseThrow());
+ return new TerminalDataTreeCandidateNode(null, nodeModification, dataBefore, verifyNotNull(dataAfter));
case APPEARED:
case DISAPPEARED:
case SUBTREE_MODIFIED:
private static DataTreeCandidateNode slowCompressNodes(final DataTreeCandidateNode first,
final List<DataTreeCandidateNode> input) {
// finalNode contains summarized changes
- TerminalDataTreeCandidateNode finalNode = new TerminalDataTreeCandidateNode(
- null, first.getDataBefore().orElse(null));
+ TerminalDataTreeCandidateNode finalNode = new TerminalDataTreeCandidateNode(null, first.dataBefore());
input.forEach(node -> compressNode(finalNode, node, null));
- finalNode.setAfter(input.get(input.size() - 1).getDataAfter().orElse(null));
+ finalNode.setAfter(input.get(input.size() - 1).dataAfter());
return cleanUpTree(finalNode);
}
final PathArgument parent) {
PathArgument identifier;
try {
- identifier = node.getIdentifier();
+ identifier = node.name();
} catch (IllegalStateException e) {
identifier = null;
}
.orElseThrow(() -> new IllegalArgumentException("No node found for " + parent + " identifier"));
TerminalDataTreeCandidateNode childNode = new TerminalDataTreeCandidateNode(
identifier,
- node.getDataBefore().orElse(null),
+ node.dataBefore(),
parentNode);
parentNode.addChildNode(childNode);
}
- ModificationType nodeModification = node.getModificationType();
+ ModificationType nodeModification = node.modificationType();
switch (nodeModification) {
case UNMODIFIED:
// If node is unmodified there is no need iterate through its child nodes
case SUBTREE_MODIFIED:
finalNode.setModification(identifier,
compressModifications(finalNode.getModification(identifier), nodeModification,
- finalNode.getDataAfter(identifier).isEmpty()));
- finalNode.setData(identifier, node.getDataAfter().orElse(null));
+ finalNode.dataAfter(identifier) == null));
+ finalNode.setData(identifier, node.dataAfter());
- for (DataTreeCandidateNode child : node.getChildNodes()) {
+ for (DataTreeCandidateNode child : node.childNodes()) {
compressNode(finalNode, child, identifier);
}
break;
// Compare data before and after in order to find modified nodes without actual changes
private static DataTreeCandidateNode cleanUpTree(final TerminalDataTreeCandidateNode finalNode,
final TerminalDataTreeCandidateNode node) {
- PathArgument identifier = node.getIdentifier();
- ModificationType nodeModification = node.getModificationType();
- Collection<DataTreeCandidateNode> childNodes = node.getChildNodes();
- for (DataTreeCandidateNode childNode : childNodes) {
+ final var identifier = node.name();
+ final var nodeModification = node.modificationType();
+ final var childNodes = node.childNodes();
+ for (var childNode : childNodes) {
cleanUpTree(finalNode, (TerminalDataTreeCandidateNode) childNode);
}
- Optional<NormalizedNode> dataBefore = finalNode.getDataBefore(identifier);
+ final var dataBefore = finalNode.dataBefore(identifier);
switch (nodeModification) {
case UNMODIFIED:
case WRITE:
return finalNode;
case DELETE:
- if (dataBefore.isEmpty()) {
+ if (dataBefore == null) {
finalNode.deleteNode(identifier);
}
return finalNode;
case APPEARED:
- if (dataBefore.isPresent()) {
+ if (dataBefore != null) {
illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
}
if (childNodes.isEmpty()) {
}
return finalNode;
case DISAPPEARED:
- if (dataBefore.isEmpty() || childNodes.isEmpty()) {
+ if (dataBefore == null || childNodes.isEmpty()) {
finalNode.deleteNode(identifier);
}
return finalNode;
case SUBTREE_MODIFIED:
- if (dataBefore.isEmpty()) {
+ if (dataBefore == null) {
illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
}
if (childNodes.isEmpty()) {
switch (firstModification) {
case UNMODIFIED:
if (hasNoDataBefore) {
- switch (secondModification) {
- case UNMODIFIED:
- case WRITE:
- case APPEARED:
- return secondModification;
- case DELETE:
- return illegalModification(ModificationType.DELETE, ModificationType.DELETE);
- case SUBTREE_MODIFIED:
- return illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
- case DISAPPEARED:
- return illegalModification(ModificationType.DISAPPEARED, ModificationType.DELETE);
- default:
+ return switch (secondModification) {
+ case UNMODIFIED, WRITE, APPEARED -> secondModification;
+ case DELETE -> illegalModification(ModificationType.DELETE, ModificationType.DELETE);
+ case SUBTREE_MODIFIED ->
+ illegalModification(ModificationType.SUBTREE_MODIFIED, ModificationType.DELETE);
+ case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, ModificationType.DELETE);
+ default ->
throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ };
}
if (secondModification == ModificationType.APPEARED) {
return illegalModification(ModificationType.APPEARED, ModificationType.WRITE);
}
return secondModification;
case WRITE:
- switch (secondModification) {
- case UNMODIFIED:
- case WRITE:
- case SUBTREE_MODIFIED:
- return ModificationType.WRITE;
- case DELETE:
- return ModificationType.DELETE;
- case DISAPPEARED:
- return ModificationType.DISAPPEARED;
- case APPEARED:
- return illegalModification(ModificationType.APPEARED, firstModification);
- default:
- throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ return switch (secondModification) {
+ case UNMODIFIED, WRITE, SUBTREE_MODIFIED -> ModificationType.WRITE;
+ case DELETE -> ModificationType.DELETE;
+ case DISAPPEARED -> ModificationType.DISAPPEARED;
+ case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+ default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+ };
case DELETE:
- switch (secondModification) {
- case UNMODIFIED:
- return ModificationType.DELETE;
- case WRITE:
- case APPEARED:
- return ModificationType.WRITE;
- case DELETE:
- return illegalModification(ModificationType.DELETE, firstModification);
- case DISAPPEARED:
- return illegalModification(ModificationType.DISAPPEARED, firstModification);
- case SUBTREE_MODIFIED:
- return illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
- default:
- throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ return switch (secondModification) {
+ case UNMODIFIED -> ModificationType.DELETE;
+ case WRITE, APPEARED -> ModificationType.WRITE;
+ case DELETE -> illegalModification(ModificationType.DELETE, firstModification);
+ case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, firstModification);
+ case SUBTREE_MODIFIED -> illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
+ default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+ };
case APPEARED:
- switch (secondModification) {
- case UNMODIFIED:
- case SUBTREE_MODIFIED:
- return ModificationType.APPEARED;
- case DELETE:
- case DISAPPEARED:
- return ModificationType.UNMODIFIED;
- case WRITE:
- return ModificationType.WRITE;
- case APPEARED:
- return illegalModification(ModificationType.APPEARED, firstModification);
- default:
- throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ return switch (secondModification) {
+ case UNMODIFIED, SUBTREE_MODIFIED -> ModificationType.APPEARED;
+ case DELETE, DISAPPEARED -> ModificationType.UNMODIFIED;
+ case WRITE -> ModificationType.WRITE;
+ case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+ default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+ };
case DISAPPEARED:
- switch (secondModification) {
- case UNMODIFIED:
- case WRITE:
- return secondModification;
- case APPEARED:
- return ModificationType.SUBTREE_MODIFIED;
- case DELETE:
- return illegalModification(ModificationType.DELETE, firstModification);
- case DISAPPEARED:
- return illegalModification(ModificationType.DISAPPEARED, firstModification);
-
- case SUBTREE_MODIFIED:
- return illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
- default:
- throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ return switch (secondModification) {
+ case UNMODIFIED, WRITE -> secondModification;
+ case APPEARED -> ModificationType.SUBTREE_MODIFIED;
+ case DELETE -> illegalModification(ModificationType.DELETE, firstModification);
+ case DISAPPEARED -> illegalModification(ModificationType.DISAPPEARED, firstModification);
+ case SUBTREE_MODIFIED -> illegalModification(ModificationType.SUBTREE_MODIFIED, firstModification);
+ default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+ };
case SUBTREE_MODIFIED:
- switch (secondModification) {
- case UNMODIFIED:
- case SUBTREE_MODIFIED:
- return ModificationType.SUBTREE_MODIFIED;
- case WRITE:
- case DELETE:
- case DISAPPEARED:
- return secondModification;
- case APPEARED:
- return illegalModification(ModificationType.APPEARED, firstModification);
- default:
- throw new IllegalStateException("Unsupported modification type " + secondModification);
- }
+ return switch (secondModification) {
+ case UNMODIFIED, SUBTREE_MODIFIED -> ModificationType.SUBTREE_MODIFIED;
+ case WRITE, DELETE, DISAPPEARED -> secondModification;
+ case APPEARED -> illegalModification(ModificationType.APPEARED, firstModification);
+ default -> throw new IllegalStateException("Unsupported modification type " + secondModification);
+ };
default:
throw new IllegalStateException("Unsupported modification type " + secondModification);
}
NodeIterator next(final DataTreeModification modification) {
while (iterator.hasNext()) {
final DataTreeCandidateNode node = iterator.next();
- final YangInstanceIdentifier child = path.node(node.getIdentifier());
+ final YangInstanceIdentifier child = path.node(node.name());
- switch (node.getModificationType()) {
+ switch (node.modificationType()) {
case DELETE:
modification.delete(child);
LOG.debug("Modification {} deleted path {}", modification, child);
case DISAPPEARED:
case SUBTREE_MODIFIED:
LOG.debug("Modification {} modified path {}", modification, child);
- return new NodeIterator(this, child, node.getChildNodes().iterator());
+ return new NodeIterator(this, child, node.childNodes().iterator());
case UNMODIFIED:
LOG.debug("Modification {} unmodified path {}", modification, child);
// No-op
break;
case WRITE:
- modification.write(child, node.getDataAfter().orElseThrow());
+ modification.write(child, verifyNotNull(node.dataAfter()));
LOG.debug("Modification {} written path {}", modification, child);
break;
default:
- throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ throw new IllegalArgumentException("Unsupported modification " + node.modificationType());
}
}
return parent;
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.DELETE;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.empty();
+ public NormalizedNode dataBefore() {
+ return data;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return dataOptional();
+ public NormalizedNode dataAfter() {
+ return null;
}
}
import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode {
- private final PathArgument identifier;
+ private final @NonNull PathArgument name;
- EmptyDataTreeCandidateNode(final PathArgument identifier) {
- this.identifier = requireNonNull(identifier, "Identifier should not be null");
+ EmptyDataTreeCandidateNode(final PathArgument name) {
+ this.name = requireNonNull(name);
}
@Override
- public PathArgument getIdentifier() {
- return identifier;
+ public PathArgument name() {
+ return name;
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
+ public Collection<DataTreeCandidateNode> childNodes() {
return ImmutableList.of();
}
@Override
- public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
- return Optional.empty();
+ public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ return null;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.UNMODIFIED;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.empty();
+ public NormalizedNode dataAfter() {
+ return null;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.empty();
+ public NormalizedNode dataBefore() {
+ return null;
}
}
\ No newline at end of file
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
}
@Override
- public PathArgument getIdentifier() {
+ public PathArgument name() {
return data.name();
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
- if (data instanceof DistinctNodeContainer) {
- return Collections2.transform(((DistinctNodeContainer<?, ?>) data).body(),
- input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
- }
- return ImmutableList.of();
+ public ModificationType modificationType() {
+ return ModificationType.WRITE;
}
@Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
- if (data instanceof DistinctNodeContainer) {
- return ((Optional<@NonNull NormalizedNode>) ((DistinctNodeContainer)data).findChildByArg(childIdentifier))
- .map(NormalizedNodeDataTreeCandidateNode::new);
- }
- return Optional.empty();
+ public NormalizedNode dataBefore() {
+ return null;
}
@Override
- public ModificationType getModificationType() {
- return ModificationType.WRITE;
+ public NormalizedNode dataAfter() {
+ return data;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.of(data);
+ public Collection<DataTreeCandidateNode> childNodes() {
+ if (data instanceof DistinctNodeContainer<?, ?> container) {
+ return Collections2.transform(container.body(),
+ input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
+ }
+ return ImmutableList.of();
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.empty();
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ if (data instanceof DistinctNodeContainer container) {
+ final var child = container.childByArg(childName);
+ return child != null ? new NormalizedNodeDataTreeCandidateNode(child) : null;
+ }
+ return null;
}
}
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.DELETE;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.empty();
+ public NormalizedNode dataAfter() {
+ return null;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return dataOptional();
+ public NormalizedNode dataBefore() {
+ return data;
}
@Override
import static java.util.Objects.requireNonNull;
import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
- private final DistinctNodeContainer<PathArgument, NormalizedNode> oldData;
+ private final @NonNull DistinctNodeContainer<PathArgument, NormalizedNode> oldData;
RecursiveReplaceCandidateNode(final DistinctNodeContainer<PathArgument, NormalizedNode> oldData,
final DistinctNodeContainer<PathArgument, NormalizedNode> newData) {
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.WRITE;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return dataOptional();
+ public NormalizedNode dataBefore() {
+ return oldData;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.of(oldData);
+ public NormalizedNode dataAfter() {
+ return data;
}
@Override
- public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- return DataTreeCandidateNodes.containerDelta(oldData, data(), identifier);
+ public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
+ return DataTreeCandidateNodes.containerDelta(oldData, data, childName);
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
- return DataTreeCandidateNodes.containerDelta(oldData, data());
+ public Collection<DataTreeCandidateNode> childNodes() {
+ return DataTreeCandidateNodes.containerDelta(oldData, data);
}
}
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.UNMODIFIED;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return dataOptional();
+ public NormalizedNode dataBefore() {
+ return data;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return dataOptional();
+ public NormalizedNode dataAfter() {
+ return data;
}
@Override
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.WRITE;
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return dataOptional();
+ public NormalizedNode dataBefore() {
+ return null;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.empty();
+ public NormalizedNode dataAfter() {
+ return data;
}
@Override
import static java.util.Objects.requireNonNull;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class ReplaceLeafCandidateNode extends AbstractWriteCandidate {
- private final NormalizedNode oldData;
+ private final @NonNull NormalizedNode oldData;
ReplaceLeafCandidateNode(final NormalizedNode oldData, final NormalizedNode newData) {
super(newData);
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.of(oldData);
+ public NormalizedNode dataBefore() {
+ return oldData;
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
// Non-final for mocking
class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
private ModificationType modificationType;
- private final PathArgument identifier;
+ private final @NonNull PathArgument name;
private final NormalizedNode before;
private NormalizedNode after;
private final HashMap<PathArgument, TerminalDataTreeCandidateNode> childNodes = new HashMap<>();
this(identifier, ModificationType.UNMODIFIED, data, data);
}
- TerminalDataTreeCandidateNode(final PathArgument identifier, final ModificationType modificationType,
- final NormalizedNode before, final NormalizedNode after) {
- this.modificationType = modificationType;
- this.identifier = identifier;
+ TerminalDataTreeCandidateNode(final PathArgument name, final ModificationType modificationType,
+ final @Nullable NormalizedNode before, final @Nullable NormalizedNode after) {
+ // FIXME: requireNonNull()
+ this.name = name;
+ this.modificationType = requireNonNull(modificationType);
this.before = before;
this.after = after;
}
@Override
- public PathArgument getIdentifier() {
- return identifier;
+ public PathArgument name() {
+ return name;
}
@Override
- public Collection<DataTreeCandidateNode> getChildNodes() {
+ public Collection<DataTreeCandidateNode> childNodes() {
return Collections.unmodifiableCollection(childNodes.values());
}
@Override
- public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
- return Optional.ofNullable(childNodes.get(identifier));
+ public DataTreeCandidateNode modifiedChild(final PathArgument childIdentifier) {
+ return childNodes.get(name);
}
@Override
- public ModificationType getModificationType() {
- return modificationType;
+ public ModificationType modificationType() {
+ return requireNonNull(modificationType);
}
@Override
- public Optional<NormalizedNode> getDataAfter() {
- return Optional.ofNullable(after);
+ public NormalizedNode dataAfter() {
+ return after;
}
- @NonNull Optional<NormalizedNode> getDataAfter(final PathArgument id) {
- return getNode(id).flatMap(TerminalDataTreeCandidateNode::getDataAfter);
+ @Nullable NormalizedNode dataAfter(final PathArgument id) {
+ final var child = node(id);
+ return child != null ? child.dataAfter() : null;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.ofNullable(before);
+ public NormalizedNode dataBefore() {
+ return before;
}
- @NonNull Optional<NormalizedNode> getDataBefore(final PathArgument id) {
- return getNode(id).flatMap(TerminalDataTreeCandidateNode::getDataBefore);
+ @Nullable NormalizedNode dataBefore(final PathArgument id) {
+ final var child = node(id);
+ return child != null ? child.dataBefore() : null;
}
void setAfter(final NormalizedNode after) {
}
void addChildNode(final TerminalDataTreeCandidateNode node) {
- childNodes.put(node.getIdentifier(), node);
+ childNodes.put(node.name(), node);
}
void setModification(final PathArgument id, final ModificationType modification) {
}
private void setModification(final ModificationType modification) {
- modificationType = modification;
+ modificationType = requireNonNull(modification);
}
ModificationType getModification(final PathArgument id) {
- return getNode(id).map(TerminalDataTreeCandidateNode::getModificationType).orElse(ModificationType.UNMODIFIED);
+ return getNode(id).map(TerminalDataTreeCandidateNode::modificationType).orElse(ModificationType.UNMODIFIED);
}
void deleteNode(final PathArgument id) {
childNodes.remove(id);
}
- @NonNull Optional<TerminalDataTreeCandidateNode> getNode(final PathArgument id) {
+ final @Nullable TerminalDataTreeCandidateNode node(final PathArgument id) {
if (id == null) {
- return Optional.of(this);
+ return this;
}
if (childNodes.isEmpty()) {
- return Optional.empty();
+ return null;
}
- if (childNodes.containsKey(id)) {
- return Optional.ofNullable(childNodes.get(id));
+ final var childNode = childNodes.get(id);
+ if (childNode != null) {
+ return childNode;
}
- return findNode(id);
+ return findNode(id).orElse(null);
+ }
+
+ final @NonNull Optional<TerminalDataTreeCandidateNode> getNode(final PathArgument id) {
+ return Optional.ofNullable(node(id));
}
void setData(final PathArgument id, final NormalizedNode node) {
- getNode(id).orElseThrow().setAfter(node);
+ verifyNotNull(node(id)).setAfter(node);
}
private @NonNull Optional<TerminalDataTreeCandidateNode> findNode(final PathArgument id) {
- Collection<HashMap<PathArgument, TerminalDataTreeCandidateNode>> nodes = new HashSet<>();
+ final var nodes = new HashSet<HashMap<PathArgument, TerminalDataTreeCandidateNode>>();
childNodes.forEach((childIdentifier, childNode) -> {
nodes.add(childNode.childNodes);
});
if (nodes.isEmpty()) {
return Optional.empty();
}
- Collection<HashMap<PathArgument, TerminalDataTreeCandidateNode>> nextNodes = new HashSet<>();
- for (HashMap<PathArgument, TerminalDataTreeCandidateNode> map : nodes) {
+ final var nextNodes = new HashSet<HashMap<PathArgument, TerminalDataTreeCandidateNode>>();
+ for (var map : nodes) {
if (map.containsKey(id)) {
return Optional.ofNullable(map.get(id));
}
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
}
@Override
- public ModificationType getModificationType() {
+ public ModificationType modificationType() {
return ModificationType.UNMODIFIED;
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return dataOptional();
+ public NormalizedNode dataBefore() {
+ return data;
}
}
*/
package org.opendaylight.yangtools.yang.data.tree.spi;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class WriteLeafCandidateNode extends AbstractWriteCandidate {
}
@Override
- public Optional<NormalizedNode> getDataBefore() {
- return Optional.empty();
+ public NormalizedNode dataBefore() {
+ return null;
}
}
import static org.mockito.Mockito.verify;
import java.util.List;
-import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+ doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
}
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).delete(isNull());
}
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
+ doReturn(ModificationType.WRITE).when(mockedChildNode2).modificationType();
final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
+ doReturn(mockedNormalizedNode).when(mockedChildNode2).dataAfter();
final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).modificationType();
final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).getModificationType();
- doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).getChildNodes();
+ doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).modificationType();
+ doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).childNodes();
doReturn(List.of(mockedChildNode1, mockedChildNode2, mockedChildNode3))
- .when(mockedDataTreeCandidateNode).getChildNodes();
+ .when(mockedDataTreeCandidateNode).childNodes();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(2)).enter((PathArgument) isNull());
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode));
assertThat(ex.getMessage(), containsString("Unsupported modification"));
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+ doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).delete(isNull());
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
- doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).getChildNodes();
+ doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+ doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode);
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, YangInstanceIdentifier.of(),
mockedDataTreeCandidateNode));
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
- doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).getChildNodes();
+ doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+ doReturn(List.of(mockedChildNode1)).when(mockedDataTreeCandidateNode).childNodes();
DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).delete(isNull());
@Test
public void testApplyRootToCursorWithDeleteModificationType() {
- final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
+ final var mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
+ final var mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
+ final var ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
assertThat(ex.getMessage(), containsString("Can not delete root"));
}
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidateNodes.applyRootToCursor(mockedCursor, mockedDataTreeCandidateNode));
assertThat(ex.getMessage(), containsString("Unsupported modification"));
package org.opendaylight.yangtools.yang.data.tree.spi;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.opendaylight.yangtools.yang.data.tree.api.ModificationType.WRITE;
import java.util.List;
-import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals("value1", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertEquals("value1", aggregationResult.getRootNode().dataAfter().body());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertNull(aggregationResult.getRootNode().dataAfter());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals("value3", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertEquals("value3", aggregationResult.getRootNode().dataAfter().body());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
- assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataBefore());
- assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
+ assertEquals(null, aggregationResult.getRootNode().dataBefore());
+ assertEquals(null, aggregationResult.getRootNode().dataAfter());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertNull(aggregationResult.getRootNode().dataAfter());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value", aggregationResult.getRootNode().dataBefore().body());
+ assertNull(aggregationResult.getRootNode().dataAfter());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().orElseThrow().body());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().orElseThrow().body());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
+ assertEquals("value1", aggregationResult.getRootNode().dataBefore().body());
+ assertEquals("value2", aggregationResult.getRootNode().dataAfter().body());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DELETE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DELETE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(APPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(APPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(UNMODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(UNMODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(DISAPPEARED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(DISAPPEARED, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(WRITE, aggregationResult.getRootNode().getModificationType());
+ assertEquals(WRITE, aggregationResult.getRootNode().modificationType());
}
@Test
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(List.of(candidate1, candidate2));
- assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().getModificationType());
+ assertEquals(SUBTREE_MODIFIED, aggregationResult.getRootNode().modificationType());
}
@Test
final NormalizedNode after,
final ModificationType modification) {
TerminalDataTreeCandidateNode dataTreeCandidateNode = mock(TerminalDataTreeCandidateNode.class);
- doReturn(null).when(dataTreeCandidateNode).getIdentifier();
- doReturn(Optional.ofNullable(before)).when(dataTreeCandidateNode).getDataBefore();
- doReturn(Optional.ofNullable(after)).when(dataTreeCandidateNode).getDataAfter();
- doReturn(modification).when(dataTreeCandidateNode).getModificationType();
+ doReturn(null).when(dataTreeCandidateNode).name();
+ doReturn(before).when(dataTreeCandidateNode).dataBefore();
+ doReturn(after).when(dataTreeCandidateNode).dataAfter();
+ doReturn(modification).when(dataTreeCandidateNode).modificationType();
return dataTreeCandidateNode;
}
private static void setChildNodes(final TerminalDataTreeCandidateNode parentNode,
final List<DataTreeCandidateNode> childNodes) {
- doReturn(null).when(parentNode).getIdentifier();
- childNodes.forEach(child -> doReturn(CHILD_ID).when(child).getIdentifier());
- doReturn(childNodes).when(parentNode).getChildNodes();
+ doReturn(null).when(parentNode).name();
+ childNodes.forEach(child -> doReturn(CHILD_ID).when(child).name());
+ doReturn(childNodes).when(parentNode).childNodes();
}
}
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
DataTreeCandidates.applyToCursor(mockedCursor, mockedDataTreeCandidate);
verify(mockedCursor, times(1)).delete(isNull());
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
verify(mockedModification, times(1)).openCursor(YangInstanceIdentifier.of());
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
- doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
verify(mockedModification, times(1)).delete(YangInstanceIdentifier.of());
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
+ doReturn(mockedNormalizedNode).when(mockedDataTreeCandidateNode).dataAfter();
- doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).modificationType();
DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
verify(mockedModification, times(1)).write(any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedDataTreeCandidateNode).modificationType();
final DataTreeCandidateNode mockedChildNode1 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode1).getModificationType();
- doReturn(new NodeIdentifier(QName.create("test", "test1"))).when(mockedChildNode1).getIdentifier();
+ doReturn(ModificationType.DELETE).when(mockedChildNode1).modificationType();
+ doReturn(new NodeIdentifier(QName.create("test", "test1"))).when(mockedChildNode1).name();
final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
+ doReturn(ModificationType.WRITE).when(mockedChildNode2).modificationType();
final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
- doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
- doReturn(new NodeIdentifier(QName.create("test", "test2"))).when(mockedChildNode2).getIdentifier();
+ doReturn(mockedNormalizedNode).when(mockedChildNode2).dataAfter();
+ doReturn(new NodeIdentifier(QName.create("test", "test2"))).when(mockedChildNode2).name();
final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).getModificationType();
+ doReturn(ModificationType.SUBTREE_MODIFIED).when(mockedChildNode3).modificationType();
final DataTreeCandidateNode mockedChildNode3ChildNode = mock(DataTreeCandidateNode.class);
- doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).getModificationType();
- doReturn(new NodeIdentifier(QName.create("test", "test3"))).when(mockedChildNode3).getIdentifier();
- doReturn(new NodeIdentifier(QName.create("test", "test4"))).when(mockedChildNode3ChildNode).getIdentifier();
- doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).getChildNodes();
+ doReturn(ModificationType.DELETE).when(mockedChildNode3ChildNode).modificationType();
+ doReturn(new NodeIdentifier(QName.create("test", "test3"))).when(mockedChildNode3).name();
+ doReturn(new NodeIdentifier(QName.create("test", "test4"))).when(mockedChildNode3ChildNode).name();
+ doReturn(List.of(mockedChildNode3ChildNode)).when(mockedChildNode3).childNodes();
final List<DataTreeCandidateNode> childNodes = List.of(mockedChildNode1, mockedChildNode2, mockedChildNode3);
- doReturn(childNodes).when(mockedDataTreeCandidateNode).getChildNodes();
+ doReturn(childNodes).when(mockedDataTreeCandidateNode).childNodes();
DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
verify(mockedModification, times(2)).delete(any(YangInstanceIdentifier.class));
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
doReturn(YangInstanceIdentifier.of()).when(mockedDataTreeCandidate).getRootPath();
- doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).getModificationType();
+ doReturn(ModificationType.APPEARED).when(mockedDataTreeCandidateNode).modificationType();
final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate));
package org.opendaylight.yangtools.yang.data.tree.spi;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
final var mockedPathArgument = new NodeIdentifier(QName.create("test", "test"));
doReturn(mockedPathArgument).when(mockedNormalizedNode).name();
- assertSame(mockedPathArgument, normalizedNodeDataTreeCandidateNode.getIdentifier());
+ assertSame(mockedPathArgument, normalizedNodeDataTreeCandidateNode.name());
- final Collection<DataTreeCandidateNode> childNodes = normalizedNodeDataTreeCandidateNode.getChildNodes();
+ final Collection<DataTreeCandidateNode> childNodes = normalizedNodeDataTreeCandidateNode.childNodes();
assertTrue(childNodes instanceof List);
assertTrue(childNodes.isEmpty());
- assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getModifiedChild(mockedPathArgument));
+ assertNull(normalizedNodeDataTreeCandidateNode.modifiedChild(mockedPathArgument));
- assertEquals(ModificationType.WRITE, normalizedNodeDataTreeCandidateNode.getModificationType());
- assertEquals(Optional.of(mockedNormalizedNode), normalizedNodeDataTreeCandidateNode.getDataAfter());
- assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getDataBefore());
+ assertEquals(ModificationType.WRITE, normalizedNodeDataTreeCandidateNode.modificationType());
+ assertEquals(mockedNormalizedNode, normalizedNodeDataTreeCandidateNode.dataAfter());
+ assertEquals(null, normalizedNodeDataTreeCandidateNode.dataBefore());
final DistinctNodeContainer mockedNormalizedNodeContainer = mock(DistinctNodeContainer.class);
final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode2 = new
NormalizedNodeDataTreeCandidateNode(mockedNormalizedNodeContainer);
final NormalizedNode mockedChildNormNode1 = mock(NormalizedNode.class);
final NormalizedNode mockedChildNormNode2 = mock(NormalizedNode.class);
- final Collection<NormalizedNode> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
- mockedChildNormNode2, null);
+ final var mockedChildNodes = Arrays.asList(mockedChildNormNode1, mockedChildNormNode2, null);
doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).body();
- final Collection<DataTreeCandidateNode> childNodes2 = normalizedNodeDataTreeCandidateNode2.getChildNodes();
+ final var childNodes2 = normalizedNodeDataTreeCandidateNode2.childNodes();
assertEquals(3, childNodes2.size());
doReturn(null).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
doCallRealMethod().when(mockedNormalizedNodeContainer).findChildByArg(any(PathArgument.class));
- assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
+ assertNull(normalizedNodeDataTreeCandidateNode2.modifiedChild(mockedPathArgument));
doReturn(mockedChildNormNode1).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
- assertTrue(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument).isPresent());
+ assertNotNull(normalizedNodeDataTreeCandidateNode2.modifiedChild(mockedPathArgument));
}
}
import static org.mockito.Mockito.doReturn;
import java.util.List;
-import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
assertEquals(1, delta.size());
final var first = delta.iterator().next();
- assertEquals(childId, first.getIdentifier());
- assertEquals(ModificationType.DELETE, first.getModificationType());
- assertEquals(Optional.of(child), first.getDataBefore());
- assertEquals(Optional.empty(), first.getDataAfter());
- assertEquals(0, first.getChildNodes().size());
+ assertEquals(childId, first.name());
+ assertEquals(ModificationType.DELETE, first.modificationType());
+ assertEquals(child, first.dataBefore());
+ assertEquals(null, first.dataAfter());
+ assertEquals(0, first.childNodes().size());
}
}