blob: 68122bd1d777c99c92892932d857c900bb597a92 [file] [log] [blame]
Sho SHIMIZUf57d6002016-05-19 11:38:16 -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 SHIMIZU68e8bfa2016-06-08 12:01:31 -070018import com.google.common.base.MoreObjects;
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070019import com.google.common.collect.ImmutableSet;
20import org.onosproject.net.resource.DiscreteResource;
21import org.onosproject.net.resource.DiscreteResourceId;
22
Jordan Halterman7af71da2017-05-15 13:41:00 -070023import java.util.Objects;
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070024import java.util.Optional;
25import java.util.Set;
26
27/**
28 * Represents an empty set of discrete resource.
29 */
30final class EmptyDiscreteResources implements DiscreteResources {
Sho SHIMIZU226d0412016-06-08 11:32:12 -070031 static final EmptyDiscreteResources INSTANCE = new EmptyDiscreteResources();
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070032
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 SHIMIZU34847b72016-06-07 14:31:54 -070052 public boolean containsAny(Set<DiscreteResource> other) {
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070053 return false;
54 }
55
56 @Override
57 public DiscreteResources add(DiscreteResources other) {
58 return other;
59 }
60
61 @Override
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070062 public Set<DiscreteResource> values() {
63 return ImmutableSet.of();
64 }
Sho SHIMIZU68e8bfa2016-06-08 12:01:31 -070065
66 @Override
Jordan Halterman9eead3c2017-05-09 12:24:14 -070067 public int hashCode() {
Jordan Halterman7af71da2017-05-15 13:41:00 -070068 return Objects.hash(values());
Jordan Halterman9eead3c2017-05-09 12:24:14 -070069 }
70
71 @Override
72 public boolean equals(Object object) {
73 return object instanceof DiscreteResources && ((DiscreteResources) object).isEmpty();
74 }
75
76 @Override
Sho SHIMIZU68e8bfa2016-06-08 12:01:31 -070077 public String toString() {
78 return MoreObjects.toStringHelper(this)
79 .add("values", ImmutableSet.of())
80 .toString();
81 }
Sho SHIMIZU9cc4a242016-05-26 12:55:35 -070082
83 @Override
84 public <T> Set<DiscreteResource> valuesOf(Class<T> cls) {
85 return ImmutableSet.of();
86 }
Sho SHIMIZUf57d6002016-05-19 11:38:16 -070087}