blob: ec121cd936b2e5fc04b225b5a2003a877124049f [file] [log] [blame]
Sho SHIMIZU02e6e202016-05-18 10:47:47 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.resource.impl;
17
18import org.onosproject.net.resource.DiscreteResource;
19import org.onosproject.net.resource.DiscreteResourceId;
20
21import java.util.List;
22import java.util.Optional;
23import java.util.Set;
24
25/**
26 * Represents a set of resources containing resources that can be encoded as integer
27 * and those that can't encoded as integer.
28 */
29final class UnifiedDiscreteResources implements DiscreteResources {
30 private final DiscreteResources nonEncodables;
31
32 static DiscreteResources empty() {
33 return new UnifiedDiscreteResources();
34 }
35
36 static DiscreteResources of(List<DiscreteResource> resources) {
37 return new UnifiedDiscreteResources(resources);
38 }
39
40 private UnifiedDiscreteResources() {
41 this.nonEncodables = NonEncodableDiscreteResources.empty();
42 }
43
44 private UnifiedDiscreteResources(List<DiscreteResource> resources) {
45 this.nonEncodables = NonEncodableDiscreteResources.of(resources);
46 }
47
48 @Override
49 public Optional<DiscreteResource> lookup(DiscreteResourceId id) {
50 return nonEncodables.lookup(id);
51 }
52
53 @Override
54 public DiscreteResources difference(DiscreteResources other) {
55 return nonEncodables.difference(other);
56 }
57
58 @Override
59 public boolean isEmpty() {
60 return nonEncodables.isEmpty();
61 }
62
63 @Override
64 public boolean containsAny(List<DiscreteResource> other) {
65 return nonEncodables.containsAny(other);
66 }
67
68 @Override
69 public DiscreteResources add(DiscreteResources other) {
70 return nonEncodables.add(other);
71 }
72
73 @Override
74 public DiscreteResources remove(List<DiscreteResource> removed) {
75 return nonEncodables.remove(removed);
76 }
77
78 @Override
79 public Set<DiscreteResource> values() {
80 return nonEncodables.values();
81 }
82}