Sho SHIMIZU

Stop passing duplicate original continuous resource

Change-Id: I3608b1cd362cca5e3c0534b6dfb18a7204c42aef
......@@ -107,7 +107,7 @@ class ConsistentContinuousResourceSubStore {
return true;
}
return allocation.value().hasEnoughResource(allocation.value().original(), resource);
return allocation.value().hasEnoughResource(resource);
}
<T> Stream<ContinuousResource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls) {
......
......@@ -44,12 +44,11 @@ final class ContinuousResourceAllocation {
* Checks if there is enough resource volume to allocated the requested resource
* against the specified resource.
*
* @param original original resource
* @param request requested resource
* @return true if there is enough resource volume. Otherwise, false.
*/
// computational complexity: O(n) where n is the number of allocations
boolean hasEnoughResource(ContinuousResource original, ContinuousResource request) {
boolean hasEnoughResource(ContinuousResource request) {
double allocated = allocations.stream()
.filter(x -> x.resource() instanceof ContinuousResource)
.map(x -> (ContinuousResource) x.resource())
......
......@@ -141,7 +141,7 @@ class TransactionalContinuousResourceSubStore {
ContinuousResourceAllocation allocations = consumers.get(request.id());
if (!Optional.ofNullable(allocations)
.orElse(ContinuousResourceAllocation.empty(original))
.hasEnoughResource(original, request)) {
.hasEnoughResource(request)) {
return false;
}
......