Refactor: change method parameter type of ResourceStore#release()

Use ResourceAllocation as parameter of ResourceStore#release()

Change-Id: I1833b9b23985cd42820093633591fa21daf2f98e
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
index 3584fab..e67bbe9 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
@@ -63,18 +63,17 @@
     boolean allocate(List<? extends Resource> resources, ResourceConsumer consumer);
 
     /**
-     * Releases the specified resources allocated to the specified corresponding consumers
-     * in transactional way. The state after completion of this method is all the resources
+     * Releases the specified allocated resources in transactional way.
+     * The state after completion of this method is all the resources
      * are released from the consumer, or no resource is released. The whole release fails
      * when any one of the resource can't be released. The size of the list of resources and
      * that of consumers must be equal. The resource and consumer with the same position from
      * the head of each list correspond to each other.
      *
-     * @param resources resources to be released
-     * @param consumers resource consumers to whom the resource allocated to
+     * @param allocations allocaitons to be released
      * @return true if succeeds, otherwise false
      */
-    boolean release(List<Resource> resources, List<ResourceConsumer> consumers);
+    boolean release(List<ResourceAllocation> allocations);
 
     /**
      * Returns the resource consumers to whom the specified resource is allocated.
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
index bbc8678..744931a 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
@@ -98,14 +98,7 @@
     public boolean release(List<ResourceAllocation> allocations) {
         checkNotNull(allocations);
 
-        List<Resource> resources = allocations.stream()
-                .map(ResourceAllocation::resource)
-                .collect(Collectors.toList());
-        List<ResourceConsumer> consumers = allocations.stream()
-                .map(ResourceAllocation::consumer)
-                .collect(Collectors.toList());
-
-        return store.release(resources, consumers);
+        return store.release(allocations);
     }
 
     @Override
diff --git a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index 397bcc6..6d7bc31 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -52,7 +52,6 @@
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -303,10 +302,8 @@
     }
 
     @Override
-    public boolean release(List<Resource> resources, List<ResourceConsumer> consumers) {
-        checkNotNull(resources);
-        checkNotNull(consumers);
-        checkArgument(resources.size() == consumers.size());
+    public boolean release(List<ResourceAllocation> allocations) {
+        checkNotNull(allocations);
 
         TransactionContext tx = service.transactionContextBuilder().build();
         tx.begin();
@@ -315,12 +312,10 @@
                 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
         TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
                 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
-        Iterator<Resource> resourceIte = resources.iterator();
-        Iterator<ResourceConsumer> consumerIte = consumers.iterator();
 
-        while (resourceIte.hasNext() && consumerIte.hasNext()) {
-            Resource resource = resourceIte.next();
-            ResourceConsumer consumer = consumerIte.next();
+        for (ResourceAllocation allocation : allocations) {
+            Resource resource = allocation.resource();
+            ResourceConsumer consumer = allocation.consumer();
 
             if (resource instanceof DiscreteResource) {
                 // if this single release fails (because the resource is allocated to another consumer,
@@ -330,14 +325,14 @@
                 }
             } else if (resource instanceof ContinuousResource) {
                 ContinuousResource continuous = (ContinuousResource) resource;
-                ContinuousResourceAllocation allocation = continuousConsumerTxMap.get(continuous.id());
-                ImmutableList<ResourceAllocation> newAllocations = allocation.allocations().stream()
+                ContinuousResourceAllocation continuousAllocation = continuousConsumerTxMap.get(continuous.id());
+                ImmutableList<ResourceAllocation> newAllocations = continuousAllocation.allocations().stream()
                         .filter(x -> !(x.consumer().equals(consumer) &&
                                 ((ContinuousResource) x.resource()).value() == continuous.value()))
                         .collect(GuavaCollectors.toImmutableList());
 
-                if (!continuousConsumerTxMap.replace(continuous.id(), allocation,
-                        new ContinuousResourceAllocation(allocation.original(), newAllocations))) {
+                if (!continuousConsumerTxMap.replace(continuous.id(), continuousAllocation,
+                        new ContinuousResourceAllocation(continuousAllocation.original(), newAllocations))) {
                     return abortTransaction(tx);
                 }
             }