Move the resource allocation details into ContinuousResourceAllocation
Change-Id: If5b6a86c92f27cc7acf65e6e397f72afd3a4cb41
Showing
2 changed files
with
8 additions
and
5 deletions
... | @@ -70,6 +70,13 @@ final class ContinuousResourceAllocation { | ... | @@ -70,6 +70,13 @@ final class ContinuousResourceAllocation { |
70 | return allocations; | 70 | return allocations; |
71 | } | 71 | } |
72 | 72 | ||
73 | + ContinuousResourceAllocation allocate(ContinuousResource original, ResourceAllocation value) { | ||
74 | + return new ContinuousResourceAllocation(original, ImmutableList.<ResourceAllocation>builder() | ||
75 | + .addAll(allocations) | ||
76 | + .add(value) | ||
77 | + .build()); | ||
78 | + } | ||
79 | + | ||
73 | ContinuousResourceAllocation release(ContinuousResource resource, ResourceConsumerId consumerId) { | 80 | ContinuousResourceAllocation release(ContinuousResource resource, ResourceConsumerId consumerId) { |
74 | List<ResourceAllocation> nonMatched = allocations.stream() | 81 | List<ResourceAllocation> nonMatched = allocations.stream() |
75 | .filter(x -> !(x.consumerId().equals(consumerId) && | 82 | .filter(x -> !(x.consumerId().equals(consumerId) && | ... | ... |
... | @@ -156,11 +156,7 @@ class TransactionalContinuousResourceStore { | ... | @@ -156,11 +156,7 @@ class TransactionalContinuousResourceStore { |
156 | return true; | 156 | return true; |
157 | } | 157 | } |
158 | 158 | ||
159 | - ContinuousResourceAllocation newValue = new ContinuousResourceAllocation(original, | 159 | + ContinuousResourceAllocation newValue = oldValue.allocate(original, value); |
160 | - ImmutableList.<ResourceAllocation>builder() | ||
161 | - .addAll(oldValue.allocations()) | ||
162 | - .add(value) | ||
163 | - .build()); | ||
164 | return consumers.replace(original.id(), oldValue, newValue); | 160 | return consumers.replace(original.id(), oldValue, newValue); |
165 | } | 161 | } |
166 | 162 | ... | ... |
-
Please register or login to post a comment