blob: 3b3912040b0f9ed23ccdf6b6aec7bf6806362e66 [file] [log] [blame]
Sho SHIMIZUb85000d2016-05-17 14:00:05 -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
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070018import org.onosproject.net.resource.DiscreteResource;
19import org.onosproject.net.resource.DiscreteResourceId;
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070020
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070021import java.util.List;
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070022import java.util.Optional;
23import java.util.Set;
24
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070025/**
26 * A common API for a set of discrete resources.
27 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070028interface DiscreteResources {
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070029 /**
30 * Returns an instance representing an empty set.
31 *
32 * @return a empty set.
33 */
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070034 static DiscreteResources empty() {
Sho SHIMIZU65de9612016-05-19 12:24:20 -070035 return EmptyDiscreteResources.INSTANCE;
Sho SHIMIZU02e6e202016-05-18 10:47:47 -070036 }
37
38 /**
39 * Create an instace from the specified resources.
40 *
41 * @param resources resources
42 * @return instance
43 */
Sho SHIMIZU65de9612016-05-19 12:24:20 -070044 static DiscreteResources of(Set<DiscreteResource> resources) {
Sho SHIMIZU02e6e202016-05-18 10:47:47 -070045 return UnifiedDiscreteResources.of(resources);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070046 }
47
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070048 /**
49 * Look up a discrete resource instance by ID.
50 *
51 * @param id id
52 * @return found instance enclosed by Optional
53 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070054 Optional<DiscreteResource> lookup(DiscreteResourceId id);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070055
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070056 /**
57 * Returns a difference set of this instance and the given instance.
58 *
59 * @param other other instance
60 * @return a new DiscreteResources instance representing a difference set
61 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070062 DiscreteResources difference(DiscreteResources other);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070063
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070064 /**
65 * Checks that this instance is empty.
66 *
67 * @return true if this instance is empty, otherwise false.
68 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070069 boolean isEmpty();
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070070
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070071 /**
72 * Checks that this instance contains any of the given resources.
73 *
74 * @param other resources
75 * @return true this instance contains a resource included in the given resources,
76 * otherwise false.
77 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070078 boolean containsAny(List<DiscreteResource> other);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070079
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070080 /**
81 * Returns a union set of this instance and the given instance.
82 * Note: This method returns a new instance, not mutate the current instance
83 *
84 * @param other other instance
85 * @return a new DiscreteResources instance representing a union set
86 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070087 DiscreteResources add(DiscreteResources other);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070088
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070089 /**
90 * Returns a difference set of this instance and the given resources.
91 * Note: This method returns a new instance, not mutate the current intance.
92 *
93 * @param removed resources
94 * @return a new DiscreteResources instance representing a difference set
95 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -070096 DiscreteResources remove(List<DiscreteResource> removed);
Sho SHIMIZUb85000d2016-05-17 14:00:05 -070097
Sho SHIMIZU94e8a162016-05-19 17:09:59 -070098 /**
99 * Returns all of resources this instance holds.
100 *
101 * @return all resources
102 */
Sho SHIMIZU32f57e92016-05-18 10:23:06 -0700103 Set<DiscreteResource> values();
Sho SHIMIZUb85000d2016-05-17 14:00:05 -0700104}