Bump upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / FlowUtil.java
index efb67735308e29944db579d075b344e3fd5a4c24..3c10e637adcd28f75c54200ab52b427fd7641efa 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.util;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -13,10 +12,9 @@ import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import javax.annotation.Nonnull;
+import java.util.Map;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
@@ -38,15 +36,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.bat
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Key;
+import org.opendaylight.yangtools.yang.binding.KeyAware;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public final class FlowUtil {
 
     private static final RpcResultBuilder<List<BatchFailedFlowsOutput>> SUCCESSFUL_FLOW_OUTPUT_RPC_RESULT =
-            RpcResultBuilder.success(Collections.emptyList());
+            RpcResultBuilder.success(List.of());
 
     /**
      * Attach barrier response to given {@link RpcResult}&lt;RemoveFlowsBatchOutput&gt;.
@@ -78,7 +81,7 @@ public final class FlowUtil {
         RpcResult<RemoveFlowsBatchOutput>> FLOW_REMOVE_TRANSFORM =
             batchFlowsCumulativeResult -> {
                 final RemoveFlowsBatchOutput batchOutput = new RemoveFlowsBatchOutputBuilder()
-                        .setBatchFailedFlowsOutput(batchFlowsCumulativeResult.getResult()).build();
+                        .setBatchFailedFlowsOutput(index(batchFlowsCumulativeResult.getResult())).build();
 
                 final RpcResultBuilder<RemoveFlowsBatchOutput> resultBld =
                         createCumulativeRpcResult(batchFlowsCumulativeResult, batchOutput);
@@ -92,7 +95,7 @@ public final class FlowUtil {
         RpcResult<AddFlowsBatchOutput>> FLOW_ADD_TRANSFORM =
             batchFlowsCumulativeResult -> {
                 final AddFlowsBatchOutput batchOutput = new AddFlowsBatchOutputBuilder()
-                        .setBatchFailedFlowsOutput(batchFlowsCumulativeResult.getResult()).build();
+                        .setBatchFailedFlowsOutput(index(batchFlowsCumulativeResult.getResult())).build();
 
                 final RpcResultBuilder<AddFlowsBatchOutput> resultBld =
                         createCumulativeRpcResult(batchFlowsCumulativeResult, batchOutput);
@@ -106,7 +109,7 @@ public final class FlowUtil {
         RpcResult<UpdateFlowsBatchOutput>> FLOW_UPDATE_TRANSFORM =
             batchFlowsCumulativeResult -> {
                 final UpdateFlowsBatchOutput batchOutput = new UpdateFlowsBatchOutputBuilder()
-                        .setBatchFailedFlowsOutput(batchFlowsCumulativeResult.getResult()).build();
+                        .setBatchFailedFlowsOutput(index(batchFlowsCumulativeResult.getResult())).build();
 
                 final RpcResultBuilder<UpdateFlowsBatchOutput> resultBld =
                         createCumulativeRpcResult(batchFlowsCumulativeResult, batchOutput);
@@ -114,7 +117,11 @@ public final class FlowUtil {
             };
 
     private FlowUtil() {
-        throw new IllegalStateException("This class should not be instantiated.");
+        // Hidden on purpose
+    }
+
+    static <K extends Key<V>, V extends KeyAware<K>> Map<K, V> index(final List<V> list) {
+        return list == null ? null : BindingMap.ordered(list);
     }
 
     /**
@@ -177,7 +184,7 @@ public final class FlowUtil {
      * @return instance identifier assembled for given node, table and flow
      */
     public static FlowRef buildFlowPath(final InstanceIdentifier<Node> nodePath,
-                                        final short tableId, final FlowId flowId) {
+                                        final Uint8 tableId, final FlowId flowId) {
         final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = nodePath
                 .augmentation(FlowCapableNode.class)
                 .child(Table.class, new TableKey(tableId))
@@ -195,19 +202,19 @@ public final class FlowUtil {
      * @return static reusable function
      */
     public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>> createCumulatingFunction(
-            final List<? extends BatchFlowIdGrouping> inputBatchFlows) {
+            final Collection<? extends BatchFlowIdGrouping> inputBatchFlows) {
         return new CumulatingFunction<O>(inputBatchFlows).invoke();
     }
 
     private static class CumulatingFunction<O> {
-        private final List<? extends BatchFlowIdGrouping> inputBatchFlows;
+        private final Collection<? extends BatchFlowIdGrouping> inputBatchFlows;
 
-        CumulatingFunction(List<? extends BatchFlowIdGrouping> inputBatchFlows) {
+        CumulatingFunction(final Collection<? extends BatchFlowIdGrouping> inputBatchFlows) {
             this.inputBatchFlows = inputBatchFlows;
         }
 
         public Function<List<RpcResult<O>>, RpcResult<List<BatchFailedFlowsOutput>>> invoke() {
-            return (@Nonnull final List<RpcResult<O>> innerInput) -> {
+            return (final List<RpcResult<O>> innerInput) -> {
                 final int sizeOfFutures = innerInput.size();
                 final int sizeOfInputBatch = inputBatchFlows.size();
                 Preconditions.checkArgument(sizeOfFutures == sizeOfInputBatch,
@@ -225,7 +232,7 @@ public final class FlowUtil {
                     if (!flowModOutput.isSuccessful()) {
                         batchFlows.add(new BatchFailedFlowsOutputBuilder()
                                 .setFlowId(flowId)
-                                .setBatchOrder(batchOrder)
+                                .setBatchOrder(Uint16.valueOf(batchOrder))
                                 .build());
                         flowErrors.addAll(flowModOutput.getErrors());
                     }