Clean up use of Augmentation generics
[yangtools.git] / benchmarks / src / main / java / org / opendaylight / yangtools / yang / data / impl / tree / InMemoryDataTreeBenchmark.java
index d944fc8c5d6763b19b231f0dbb3c7ce8bf88dc67..9dd4a0b4ba4cc47a558c85938f01f8d6fd939517 100644 (file)
@@ -10,24 +10,18 @@ package org.opendaylight.yangtools.yang.data.impl.tree;
 import com.google.common.collect.Streams;
 import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
+import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
 import org.openjdk.jmh.annotations.Fork;
@@ -67,40 +61,46 @@ public class InMemoryDataTreeBenchmark {
     private static final NodeIdentifierWithPredicates[] OUTER_LIST_IDS = Streams.mapWithIndex(
         IntStream.range(0, OUTER_LIST_100K),
         (i, index) -> NodeIdentifierWithPredicates.of(BenchmarkModel.OUTER_LIST_QNAME, BenchmarkModel.ID_QNAME, i))
-            .collect(Collectors.toList()).toArray(new NodeIdentifierWithPredicates[0]);
+            .toArray(NodeIdentifierWithPredicates[]::new);
 
     private static final YangInstanceIdentifier[] OUTER_LIST_PATHS = Arrays.stream(OUTER_LIST_IDS)
             .map(id -> BenchmarkModel.OUTER_LIST_PATH.node(id).toOptimized())
-            .collect(Collectors.toList()).toArray(new YangInstanceIdentifier[0]);
+            .toArray(YangInstanceIdentifier[]::new);
 
-    private static final MapNode EMPTY_OUTER_LIST = ImmutableNodes.mapNodeBuilder(BenchmarkModel.OUTER_LIST).build();
+    private static final MapNode EMPTY_OUTER_LIST = ImmutableNodes.newSystemMapBuilder()
+        .withNodeIdentifier(BenchmarkModel.OUTER_LIST)
+        .build();
     private static final MapNode ONE_ITEM_INNER_LIST = initInnerListItems(1);
     private static final MapNode TWO_ITEM_INNER_LIST = initInnerListItems(2);
     private static final MapNode TEN_ITEM_INNER_LIST = initInnerListItems(10);
 
     private static MapNode initInnerListItems(final int count) {
-        final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapEntryBuilder = ImmutableNodes
-            .mapNodeBuilder(BenchmarkModel.INNER_LIST);
+        final var mapEntryBuilder = ImmutableNodes.newSystemMapBuilder()
+            .withNodeIdentifier(BenchmarkModel.INNER_LIST);
 
         for (int i = 0; i < count; ++i) {
-            mapEntryBuilder
-                .withChild(ImmutableNodes.mapEntry(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i));
+            mapEntryBuilder.withChild(ImmutableNodes.newMapEntryBuilder()
+                .withNodeIdentifier(
+                    NodeIdentifierWithPredicates.of(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i))
+                .withChild(ImmutableNodes.leafNode(BenchmarkModel.NAME_QNAME, i))
+                .build());
         }
 
         return mapEntryBuilder.build();
     }
 
-    private static final NormalizedNode[] OUTER_LIST_ONE_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_100K,
+    private static final MapEntryNode[] OUTER_LIST_ONE_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_100K,
         ONE_ITEM_INNER_LIST);
-    private static final NormalizedNode[] OUTER_LIST_TWO_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_50K,
+    private static final MapEntryNode[] OUTER_LIST_TWO_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_50K,
         TWO_ITEM_INNER_LIST);
-    private static final NormalizedNode[] OUTER_LIST_TEN_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_10K,
+    private static final MapEntryNode[] OUTER_LIST_TEN_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_10K,
         TEN_ITEM_INNER_LIST);
 
-    private static NormalizedNode[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) {
-        return Arrays.stream(OUTER_LIST_IDS).limit(outerListItemsCount)
-                .map(id -> ImmutableNodes.mapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build())
-                .collect(Collectors.toList()).toArray(new NormalizedNode[0]);
+    private static MapEntryNode[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) {
+        return Arrays.stream(OUTER_LIST_IDS)
+            .limit(outerListItemsCount)
+            .map(id -> ImmutableNodes.newMapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build())
+            .toArray(MapEntryNode[]::new);
     }
 
     private DataTree datastore;
@@ -120,8 +120,10 @@ public class InMemoryDataTreeBenchmark {
             BenchmarkModel.createTestContext());
 
         final DataTreeModification modification = begin();
-        modification.write(BenchmarkModel.TEST_PATH, ImmutableContainerNodeBuilder.create()
-            .withNodeIdentifier(BenchmarkModel.TEST).withChild(EMPTY_OUTER_LIST).build());
+        modification.write(BenchmarkModel.TEST_PATH, ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(BenchmarkModel.TEST)
+            .withChild(EMPTY_OUTER_LIST)
+            .build());
         commit(modification);
     }
 
@@ -146,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.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
+        try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_100K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_ONE_ITEM_INNER_LIST[outerListKey]);
             }
@@ -181,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.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
+        try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_50K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TWO_ITEM_INNER_LIST[outerListKey]);
             }
@@ -216,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.openCursor(BenchmarkModel.OUTER_LIST_PATH).get()) {
+        try (var cursor = modification.openCursor(BenchmarkModel.OUTER_LIST_PATH).orElseThrow()) {
             for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
                 cursor.write(OUTER_LIST_IDS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
             }