Toshio Koide | ca0fcff | 2014-10-23 14:08:36 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.resource; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.Collections; |
| 5 | import java.util.Map; |
| 6 | import java.util.Set; |
| 7 | |
| 8 | import org.onlab.onos.net.Link; |
| 9 | import org.onlab.onos.net.intent.IntentId; |
| 10 | |
| 11 | /** |
| 12 | * Implementation of {@link LinkResourceAllocations}. |
| 13 | */ |
| 14 | public class DefaultLinkResourceAllocations implements LinkResourceAllocations { |
| 15 | private final LinkResourceRequest request; |
| 16 | private final Map<Link, Set<ResourceAllocation>> allocations; |
| 17 | |
| 18 | /** |
| 19 | * Creates a new link resource allocations. |
| 20 | * |
| 21 | * @param request requested resources |
| 22 | * @param allocations allocated resources |
| 23 | */ |
| 24 | protected DefaultLinkResourceAllocations(LinkResourceRequest request, |
| 25 | Map<Link, Set<ResourceAllocation>> allocations) { |
| 26 | this.request = request; |
| 27 | this.allocations = allocations; |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public IntentId intendId() { |
| 32 | return request.intendId(); |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public Collection<Link> links() { |
| 37 | return request.links(); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public Set<ResourceRequest> resources() { |
| 42 | return request.resources(); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public ResourceType type() { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
| 52 | Set<ResourceAllocation> result = allocations.get(link); |
| 53 | if (result == null) { |
| 54 | result = Collections.emptySet(); |
| 55 | } |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | } |