Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -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 | 68e8bfa | 2016-06-08 12:01:31 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.net.resource.DiscreteResource; |
| 21 | import org.onosproject.net.resource.DiscreteResourceId; |
| 22 | |
Jordan Halterman | 7af71da | 2017-05-15 13:41:00 -0700 | [diff] [blame] | 23 | import java.util.Objects; |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 24 | import java.util.Optional; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | /** |
| 28 | * Represents an empty set of discrete resource. |
| 29 | */ |
| 30 | final class EmptyDiscreteResources implements DiscreteResources { |
Sho SHIMIZU | 226d041 | 2016-06-08 11:32:12 -0700 | [diff] [blame] | 31 | static final EmptyDiscreteResources INSTANCE = new EmptyDiscreteResources(); |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 32 | |
| 33 | // for serializer |
| 34 | private EmptyDiscreteResources() {} |
| 35 | |
| 36 | @Override |
| 37 | public Optional<DiscreteResource> lookup(DiscreteResourceId id) { |
| 38 | return Optional.empty(); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public DiscreteResources difference(DiscreteResources other) { |
| 43 | return this; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean isEmpty() { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | @Override |
Sho SHIMIZU | 34847b7 | 2016-06-07 14:31:54 -0700 | [diff] [blame] | 52 | public boolean containsAny(Set<DiscreteResource> other) { |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 53 | return false; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public DiscreteResources add(DiscreteResources other) { |
| 58 | return other; |
| 59 | } |
| 60 | |
| 61 | @Override |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 62 | public Set<DiscreteResource> values() { |
| 63 | return ImmutableSet.of(); |
| 64 | } |
Sho SHIMIZU | 68e8bfa | 2016-06-08 12:01:31 -0700 | [diff] [blame] | 65 | |
| 66 | @Override |
Jordan Halterman | 9eead3c | 2017-05-09 12:24:14 -0700 | [diff] [blame] | 67 | public int hashCode() { |
Jordan Halterman | 7af71da | 2017-05-15 13:41:00 -0700 | [diff] [blame] | 68 | return Objects.hash(values()); |
Jordan Halterman | 9eead3c | 2017-05-09 12:24:14 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean equals(Object object) { |
| 73 | return object instanceof DiscreteResources && ((DiscreteResources) object).isEmpty(); |
| 74 | } |
| 75 | |
| 76 | @Override |
Sho SHIMIZU | 68e8bfa | 2016-06-08 12:01:31 -0700 | [diff] [blame] | 77 | public String toString() { |
| 78 | return MoreObjects.toStringHelper(this) |
| 79 | .add("values", ImmutableSet.of()) |
| 80 | .toString(); |
| 81 | } |
Sho SHIMIZU | 9cc4a24 | 2016-05-26 12:55:35 -0700 | [diff] [blame] | 82 | |
| 83 | @Override |
| 84 | public <T> Set<DiscreteResource> valuesOf(Class<T> cls) { |
| 85 | return ImmutableSet.of(); |
| 86 | } |
Sho SHIMIZU | f57d600 | 2016-05-19 11:38:16 -0700 | [diff] [blame] | 87 | } |