package org.opendaylight.yangtools.yang.data.api.schema.tree;
import com.google.common.annotations.Beta;
+import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* Create a new {@link DataTreeModificationCursor} at specified path. May fail
* if specified path does not exist. It is a programming error to use normal
*
- *
* @param path Path at which the cursor is to be anchored
* @return A new cursor, or null if the path does not exist.
* @throws IllegalStateException if there is another cursor currently open,
* or the modification is already {@link #ready()}.
+ * @deprecated Use {@link #openCursor(YangInstanceIdentifier)} instead.
*/
+ @Deprecated
@Override
@Nullable DataTreeModificationCursor createCursor(@Nonnull YangInstanceIdentifier path);
+
+ /**
+ * Create a new {@link DataTreeModificationCursor} at specified path. May fail
+ * if specified path does not exist.
+ *
+ * @param path Path at which the cursor is to be anchored
+ * @return A new cursor, or empty if the path does not exist.
+ * @throws IllegalStateException if there is another cursor currently open,
+ * or the modification is already {@link #ready()}.
+ */
+ @Override
+ default Optional<? extends DataTreeModificationCursor> openCursor(@Nonnull final YangInstanceIdentifier path) {
+ return Optional.ofNullable(createCursor(path));
+ }
+
+ /**
+ * Create a new {@link DataTreeModificationCursor} at the root of the modification.
+ *
+ * @return A new cursor
+ * @throws IllegalStateException if there is another cursor currently open.
+ */
+ @Override
+ default DataTreeModificationCursor openCursor() {
+ return openCursor(YangInstanceIdentifier.EMPTY).get();
+ }
}
package org.opendaylight.yangtools.yang.data.api.schema.tree;
import com.google.common.annotations.Beta;
+import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* @param path Path at which the cursor is to be anchored
* @return A new cursor, or null if the path does not exist.
* @throws IllegalStateException if there is another cursor currently open.
+ * @deprecated Use {@link #openCursor(YangInstanceIdentifier)} instead.
*/
+ @Deprecated
@Nullable DataTreeSnapshotCursor createCursor(@Nonnull YangInstanceIdentifier path);
+ /**
+ * Create a new {@link DataTreeSnapshotCursor} at specified path. May fail
+ * if specified path does not exist.
+ *
+ * @param path Path at which the cursor is to be anchored
+ * @return A new cursor, or empty if the path does not exist.
+ * @throws IllegalStateException if there is another cursor currently open.
+ */
+ default Optional<? extends DataTreeSnapshotCursor> openCursor(@Nonnull final YangInstanceIdentifier path) {
+ return Optional.ofNullable(createCursor(path));
+ }
+
+ /**
+ * Create a new {@link DataTreeSnapshotCursor} at the root of the modification.
+ *
+ * @return A new cursor
+ * @throws IllegalStateException if there is another cursor currently open.
+ */
+ default DataTreeSnapshotCursor openCursor() {
+ return openCursor(YangInstanceIdentifier.EMPTY).get();
+ }
+
@Override
CursorAwareDataTreeModification newModification();
}
final DataTreeCandidate candidate) {
final YangInstanceIdentifier candidatePath = candidate.getRootPath();
if (candidatePath.isEmpty()) {
- try (DataTreeModificationCursor cursor = modification.createCursor(candidatePath)) {
+ try (DataTreeModificationCursor cursor = modification.openCursor()) {
DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode());
}
} else {
- try (DataTreeModificationCursor cursor = modification.createCursor(candidatePath.getParent())) {
+ try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) {
DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode());
}
}
final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
doReturn(mockedRootPath).when(mockedDataTreeCandidate).getRootPath();
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
- doReturn(mockedCursor).when(mockedModification).createCursor(any(YangInstanceIdentifier.class));
+ doReturn(Optional.of(mockedCursor)).when(mockedModification).openCursor(any(YangInstanceIdentifier.class));
final DataTreeCandidateNode mockedDataTreeCandidateNode = mock(DataTreeCandidateNode.class);
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
doReturn(ModificationType.DELETE).when(mockedDataTreeCandidateNode).getModificationType();
DataTreeCandidates.applyToModification(mockedModification, mockedDataTreeCandidate);
- verify(mockedModification, times(1)).createCursor(any(YangInstanceIdentifier.class));
+ verify(mockedModification, times(1)).openCursor(any(YangInstanceIdentifier.class));
verify(mockedCursor, times(1)).delete(any(PathArgument.class));
doReturn(Boolean.TRUE).when(mockedRootPath).isEmpty();
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
final InMemoryDataTreeModification modification = (InMemoryDataTreeModification) dataTree.takeSnapshot()
.newModification();
- final DataTreeModificationCursor cursor = modification.createCursor(YangInstanceIdentifier.EMPTY);
+ final DataTreeModificationCursor cursor = modification.openCursor();
cursor.write(TestModel.TEST_PATH.getLastPathArgument(), testContainer);
modification.ready();