Remove CursorAwareDataTreeSnapshot.createCursor() 93/81193/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Mar 2019 14:31:27 +0000 (15:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Mar 2019 14:54:14 +0000 (15:54 +0100)
This method has been superseded by openCursor(), which has
a slightly better contract. Remove the old method.

Change-Id: I4d7f1befeb20f00a7f67c4eb37e33ddcc8bbd380
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
benchmarks/src/main/java/org/opendaylight/yangtools/yang/data/impl/tree/InMemoryDataTreeBenchmark.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/CursorAwareDataTreeModification.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/CursorAwareDataTreeSnapshot.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeSnapshot.java

index 6ed34b721b528871e0b13b151c29f6af5958012a..e3410c69abb8c8e70955d49216e8128ba8d0d872 100644 (file)
@@ -148,7 +148,7 @@ public class InMemoryDataTreeBenchmark {
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     public void write100KSingleNodeWithOneInnerItemInOneCommitCursorBenchmark() throws DataValidationFailedException {
         final CursorAwareDataTreeModification modification = begin();
-        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+        try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
             }
@@ -183,7 +183,7 @@ public class InMemoryDataTreeBenchmark {
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     public void write50KSingleNodeWithTwoInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
         final CursorAwareDataTreeModification modification = begin();
-        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+        try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
             }
@@ -218,7 +218,7 @@ public class InMemoryDataTreeBenchmark {
     @Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
     public void write10KSingleNodeWithTenInnerItemsInOneCommitCursorBenchmark() throws DataValidationFailedException {
         final CursorAwareDataTreeModification modification = begin();
-        try (DataTreeModificationCursor cursor = modification.createCursor(BenchmarkModel.OUTER_LIST_PATH)) {
+        try (DataTreeModificationCursor cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
             }
index eaa7e790df86e9f41a5e24eddb30295b284e4e70..73285963aa66f7a516228b9f070db5224c6bd480 100644 (file)
@@ -16,20 +16,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
  */
 @Beta
 public interface CursorAwareDataTreeModification extends DataTreeModification, CursorAwareDataTreeSnapshot {
-    /**
-     * 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
-    DataTreeModificationCursor createCursor(YangInstanceIdentifier path);
-
     /**
      * Create a new {@link DataTreeModificationCursor} at specified path. May fail
      * if specified path does not exist.
@@ -40,9 +26,7 @@ public interface CursorAwareDataTreeModification extends DataTreeModification, C
      *                               or the modification is already {@link #ready()}.
      */
     @Override
-    default Optional<? extends DataTreeModificationCursor> openCursor(final YangInstanceIdentifier path) {
-        return Optional.ofNullable(createCursor(path));
-    }
+    Optional<? extends DataTreeModificationCursor> openCursor(YangInstanceIdentifier path);
 
     /**
      * Create a new {@link DataTreeModificationCursor} at the root of the modification.
index e647f921498cf3563b455184992da7347d21a93c..896a9003b55015b4109650a218782c9cc7f43785 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.data.api.schema.tree;
 import com.google.common.annotations.Beta;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 /**
@@ -18,18 +17,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
  */
 @Beta
 public interface CursorAwareDataTreeSnapshot extends DataTreeSnapshot {
-    /**
-     * 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 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.
@@ -38,9 +25,7 @@ public interface CursorAwareDataTreeSnapshot extends DataTreeSnapshot {
      * @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));
-    }
+    Optional<? extends DataTreeSnapshotCursor> openCursor(@NonNull YangInstanceIdentifier path);
 
     /**
      * Create a new {@link DataTreeSnapshotCursor} at the root of the modification.
index 51475968201a6928a06b70861c4294b6497df8a1..f8f4683dabd272581448e4005a71b70624dd2510 100644 (file)
@@ -283,9 +283,9 @@ final class InMemoryDataTreeModification extends AbstractCursorAware implements
     }
 
     @Override
-    public DataTreeModificationCursor createCursor(final YangInstanceIdentifier path) {
+    public Optional<DataTreeModificationCursor> openCursor(final YangInstanceIdentifier path) {
         final OperationWithModification op = resolveModificationFor(path);
-        return openCursor(new InMemoryDataTreeModificationCursor(this, path, op));
+        return Optional.of(openCursor(new InMemoryDataTreeModificationCursor(this, path, op)));
     }
 
     @Override
index 42683f3d6290f3c37f556b58be1ffa41c82ab530..eef79642a42530fb1e10922ba9db3fdbd6c8ff99 100644 (file)
@@ -55,15 +55,11 @@ final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements Curs
     }
 
     @Override
-    public DataTreeSnapshotCursor createCursor(final YangInstanceIdentifier path) {
-        final Optional<NormalizedNode<?, ?>> maybeRoot = NormalizedNodes.findNode(rootNode.getData(), path);
-        if (!maybeRoot.isPresent()) {
-            return null;
-        }
-
-        final NormalizedNode<?, ?> root = maybeRoot.get();
-        checkArgument(root instanceof NormalizedNodeContainer, "Child %s is not a container", path);
-        return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (NormalizedNodeContainer<?, ?, ?>)root));
+    public Optional<DataTreeSnapshotCursor> openCursor(final YangInstanceIdentifier path) {
+        return NormalizedNodes.findNode(rootNode.getData(), path).map(root -> {
+            checkArgument(root instanceof NormalizedNodeContainer, "Child %s is not a container", path);
+            return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (NormalizedNodeContainer<?, ?, ?>)root));
+        });
     }
 
     @Override