Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -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 | |
| 17 | package org.onosproject.store.primitives.impl; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.base.Preconditions; |
| 21 | import com.google.common.collect.Multiset; |
| 22 | import org.onosproject.store.service.AsyncConsistentMultimap; |
| 23 | import org.onosproject.store.service.Versioned; |
| 24 | |
| 25 | import java.util.Collection; |
| 26 | import java.util.Map; |
| 27 | import java.util.Objects; |
| 28 | import java.util.Set; |
| 29 | import java.util.concurrent.CompletableFuture; |
| 30 | import java.util.function.Consumer; |
| 31 | |
| 32 | /** |
| 33 | * {@code AsyncConsistentMultimap} that merely delegates control to |
| 34 | * another AsyncConsistentMultimap. |
| 35 | * |
| 36 | * @param <K> key type |
| 37 | * @param <V> value type |
| 38 | */ |
| 39 | public class DelegatingAsyncConsistentMultimap<K, V> |
| 40 | implements AsyncConsistentMultimap<K, V> { |
| 41 | |
| 42 | private final AsyncConsistentMultimap<K, V> delegateMap; |
| 43 | |
| 44 | public DelegatingAsyncConsistentMultimap( |
| 45 | AsyncConsistentMultimap<K, V> delegateMap) { |
| 46 | this.delegateMap = Preconditions.checkNotNull(delegateMap); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String name() { |
| 51 | return delegateMap.name(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public CompletableFuture<Integer> size() { |
| 56 | return delegateMap.size(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public CompletableFuture<Boolean> isEmpty() { |
| 61 | return delegateMap.isEmpty(); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public CompletableFuture<Boolean> containsKey(K key) { |
| 66 | return delegateMap.containsKey(key); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public CompletableFuture<Boolean> containsValue(V value) { |
| 71 | return delegateMap.containsValue(value); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public CompletableFuture<Boolean> containsEntry(K key, V value) { |
| 76 | return delegateMap.containsEntry(key, value); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public CompletableFuture<Boolean> put(K key, V value) { |
| 81 | return delegateMap.put(key, value); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public CompletableFuture<Boolean> remove(K key, V value) { |
| 86 | return delegateMap.remove(key, value); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public CompletableFuture<Boolean> removeAll( |
| 91 | K key, Collection<? extends V> values) { |
| 92 | return delegateMap.removeAll(key, values); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public CompletableFuture<Versioned<Collection<? extends V>>> |
| 97 | removeAll(K key) { |
| 98 | return delegateMap.removeAll(key); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public CompletableFuture<Boolean> putAll( |
| 103 | K key, Collection<? extends V> values) { |
| 104 | return delegateMap.putAll(key, values); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public CompletableFuture<Versioned<Collection<? extends V>>> |
| 109 | replaceValues(K key, Collection<V> values) { |
| 110 | return delegateMap.replaceValues(key, values); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public CompletableFuture<Void> clear() { |
| 115 | return delegateMap.clear(); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public CompletableFuture<Versioned<Collection<? extends V>>> get(K key) { |
| 120 | return delegateMap.get(key); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public CompletableFuture<Set<K>> keySet() { |
| 125 | return delegateMap.keySet(); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public CompletableFuture<Multiset<K>> keys() { |
| 130 | return delegateMap.keys(); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public CompletableFuture<Multiset<V>> values() { |
| 135 | return delegateMap.values(); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public CompletableFuture<Collection<Map.Entry<K, V>>> entries() { |
| 140 | return delegateMap.entries(); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public CompletableFuture<Map<K, Collection<V>>> asMap() { |
| 145 | return delegateMap.asMap(); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void addStatusChangeListener(Consumer<Status> listener) { |
| 150 | delegateMap.addStatusChangeListener(listener); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void removeStatusChangeListener(Consumer<Status> listener) { |
| 155 | delegateMap.removeStatusChangeListener(listener); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public Collection<Consumer<Status>> statusChangeListeners() { |
| 160 | return delegateMap.statusChangeListeners(); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public String toString() { |
| 165 | return MoreObjects.toStringHelper(getClass()) |
| 166 | .add("delegateMap", delegateMap) |
| 167 | .toString(); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public int hashCode() { |
| 172 | return Objects.hash(delegateMap); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public boolean equals(Object other) { |
| 177 | if (other instanceof DelegatingAsyncConsistentMultimap) { |
| 178 | DelegatingAsyncConsistentMultimap<K, V> that = |
| 179 | (DelegatingAsyncConsistentMultimap) other; |
| 180 | return this.delegateMap.equals(that.delegateMap); |
| 181 | } |
| 182 | return false; |
| 183 | } |
| 184 | } |