Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.store.resource.impl; |
| 17 | |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 18 | import org.onosproject.net.resource.DiscreteResource; |
| 19 | import org.onosproject.net.resource.DiscreteResourceId; |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 20 | |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 21 | import java.util.Optional; |
| 22 | import java.util.Set; |
| 23 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 24 | /** |
| 25 | * A common API for a set of discrete resources. |
| 26 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 27 | interface DiscreteResources { |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Returns an instance representing an empty set. |
| 30 | * |
| 31 | * @return a empty set. |
| 32 | */ |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 33 | static DiscreteResources empty() { |
Sho SHIMIZU | 65de961 | 2016-05-19 12:24:20 -0700 | [diff] [blame] | 34 | return EmptyDiscreteResources.INSTANCE; |
Sho SHIMIZU | 02e6e20 | 2016-05-18 10:47:47 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Create an instace from the specified resources. |
| 39 | * |
| 40 | * @param resources resources |
| 41 | * @return instance |
| 42 | */ |
Sho SHIMIZU | 65de961 | 2016-05-19 12:24:20 -0700 | [diff] [blame] | 43 | static DiscreteResources of(Set<DiscreteResource> resources) { |
Sho SHIMIZU | 02e6e20 | 2016-05-18 10:47:47 -0700 | [diff] [blame] | 44 | return UnifiedDiscreteResources.of(resources); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Look up a discrete resource instance by ID. |
| 49 | * |
| 50 | * @param id id |
| 51 | * @return found instance enclosed by Optional |
| 52 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 53 | Optional<DiscreteResource> lookup(DiscreteResourceId id); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 54 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 55 | /** |
| 56 | * Returns a difference set of this instance and the given instance. |
| 57 | * |
| 58 | * @param other other instance |
| 59 | * @return a new DiscreteResources instance representing a difference set |
| 60 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 61 | DiscreteResources difference(DiscreteResources other); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 62 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Checks that this instance is empty. |
| 65 | * |
| 66 | * @return true if this instance is empty, otherwise false. |
| 67 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 68 | boolean isEmpty(); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 69 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Checks that this instance contains any of the given resources. |
| 72 | * |
| 73 | * @param other resources |
| 74 | * @return true this instance contains a resource included in the given resources, |
| 75 | * otherwise false. |
| 76 | */ |
Sho SHIMIZU | 34847b7 | 2016-06-07 14:31:54 -0700 | [diff] [blame] | 77 | boolean containsAny(Set<DiscreteResource> other); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 78 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Returns a union set of this instance and the given instance. |
| 81 | * Note: This method returns a new instance, not mutate the current instance |
| 82 | * |
| 83 | * @param other other instance |
| 84 | * @return a new DiscreteResources instance representing a union set |
| 85 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 86 | DiscreteResources add(DiscreteResources other); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 87 | |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 88 | /** |
Sho SHIMIZU | 94e8a16 | 2016-05-19 17:09:59 -0700 | [diff] [blame] | 89 | * Returns all of resources this instance holds. |
| 90 | * |
| 91 | * @return all resources |
| 92 | */ |
Sho SHIMIZU | 32f57e9 | 2016-05-18 10:23:06 -0700 | [diff] [blame] | 93 | Set<DiscreteResource> values(); |
Sho SHIMIZU | 9cc4a24 | 2016-05-26 12:55:35 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Returns all of resources this instance holds and filtered by the specified type. |
| 97 | * |
| 98 | * @param cls class instance of the resource value |
| 99 | * @param <T> type of the resource value |
| 100 | * @return all of resources this instance holds and filtered by the specified type |
| 101 | */ |
| 102 | <T> Set<DiscreteResource> valuesOf(Class<T> cls); |
Sho SHIMIZU | b85000d | 2016-05-17 14:00:05 -0700 | [diff] [blame] | 103 | } |