Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 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 | |
Jonathan Hart | 46bf89b | 2017-02-27 15:56:42 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Multiset; |
| 20 | import org.onosproject.store.service.AsyncConsistentMultimap; |
Jordan Halterman | 21ef9e4 | 2018-05-21 22:11:07 -0700 | [diff] [blame] | 21 | import org.onosproject.store.service.AsyncIterator; |
Jonathan Hart | 46bf89b | 2017-02-27 15:56:42 -0800 | [diff] [blame] | 22 | import org.onosproject.store.service.MultimapEventListener; |
| 23 | import org.onosproject.store.service.Versioned; |
| 24 | |
Jordan Halterman | 9bdc24f | 2017-04-19 23:45:12 -0700 | [diff] [blame] | 25 | import java.util.Collection; |
| 26 | import java.util.Map; |
| 27 | import java.util.Set; |
| 28 | import java.util.concurrent.CompletableFuture; |
| 29 | |
Jonathan Hart | 46bf89b | 2017-02-27 15:56:42 -0800 | [diff] [blame] | 30 | import java.util.concurrent.Executor; |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 31 | |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 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> |
Jordan Halterman | 9bdc24f | 2017-04-19 23:45:12 -0700 | [diff] [blame] | 40 | extends DelegatingDistributedPrimitive implements AsyncConsistentMultimap<K, V> { |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 41 | |
| 42 | private final AsyncConsistentMultimap<K, V> delegateMap; |
| 43 | |
| 44 | public DelegatingAsyncConsistentMultimap( |
| 45 | AsyncConsistentMultimap<K, V> delegateMap) { |
Jordan Halterman | 9bdc24f | 2017-04-19 23:45:12 -0700 | [diff] [blame] | 46 | super(delegateMap); |
| 47 | this.delegateMap = delegateMap; |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public CompletableFuture<Integer> size() { |
| 52 | return delegateMap.size(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public CompletableFuture<Boolean> isEmpty() { |
| 57 | return delegateMap.isEmpty(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public CompletableFuture<Boolean> containsKey(K key) { |
| 62 | return delegateMap.containsKey(key); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public CompletableFuture<Boolean> containsValue(V value) { |
| 67 | return delegateMap.containsValue(value); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public CompletableFuture<Boolean> containsEntry(K key, V value) { |
| 72 | return delegateMap.containsEntry(key, value); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public CompletableFuture<Boolean> put(K key, V value) { |
| 77 | return delegateMap.put(key, value); |
| 78 | } |
| 79 | |
| 80 | @Override |
Jordan Halterman | 99c654d | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 81 | public CompletableFuture<Versioned<Collection<? extends V>>> putAndGet(K key, V value) { |
| 82 | return delegateMap.putAndGet(key, value); |
| 83 | } |
| 84 | |
| 85 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 86 | public CompletableFuture<Boolean> remove(K key, V value) { |
| 87 | return delegateMap.remove(key, value); |
| 88 | } |
| 89 | |
| 90 | @Override |
Jordan Halterman | 99c654d | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 91 | public CompletableFuture<Versioned<Collection<? extends V>>> removeAndGet(K key, V value) { |
| 92 | return delegateMap.removeAndGet(key, value); |
| 93 | } |
| 94 | |
| 95 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 96 | public CompletableFuture<Boolean> removeAll( |
| 97 | K key, Collection<? extends V> values) { |
| 98 | return delegateMap.removeAll(key, values); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public CompletableFuture<Versioned<Collection<? extends V>>> |
| 103 | removeAll(K key) { |
| 104 | return delegateMap.removeAll(key); |
| 105 | } |
| 106 | |
| 107 | @Override |
pier | fa48c6e | 2019-10-11 18:19:59 +0200 | [diff] [blame^] | 108 | public CompletableFuture<Boolean> removeAll( |
| 109 | Map<K, Collection<? extends V>> mapping) { |
| 110 | return delegateMap.removeAll(mapping); |
| 111 | } |
| 112 | |
| 113 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 114 | public CompletableFuture<Boolean> putAll( |
| 115 | K key, Collection<? extends V> values) { |
| 116 | return delegateMap.putAll(key, values); |
| 117 | } |
| 118 | |
| 119 | @Override |
pier | fa48c6e | 2019-10-11 18:19:59 +0200 | [diff] [blame^] | 120 | public CompletableFuture<Boolean> putAll( |
| 121 | Map<K, Collection<? extends V>> mapping) { |
| 122 | return delegateMap.putAll(mapping); |
| 123 | } |
| 124 | |
| 125 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 126 | public CompletableFuture<Versioned<Collection<? extends V>>> |
| 127 | replaceValues(K key, Collection<V> values) { |
| 128 | return delegateMap.replaceValues(key, values); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public CompletableFuture<Void> clear() { |
| 133 | return delegateMap.clear(); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public CompletableFuture<Versioned<Collection<? extends V>>> get(K key) { |
| 138 | return delegateMap.get(key); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public CompletableFuture<Set<K>> keySet() { |
| 143 | return delegateMap.keySet(); |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public CompletableFuture<Multiset<K>> keys() { |
| 148 | return delegateMap.keys(); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public CompletableFuture<Multiset<V>> values() { |
| 153 | return delegateMap.values(); |
| 154 | } |
| 155 | |
| 156 | @Override |
Jordan Halterman | 21ef9e4 | 2018-05-21 22:11:07 -0700 | [diff] [blame] | 157 | public CompletableFuture<AsyncIterator<Map.Entry<K, V>>> iterator() { |
| 158 | return delegateMap.iterator(); |
| 159 | } |
| 160 | |
| 161 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 162 | public CompletableFuture<Collection<Map.Entry<K, V>>> entries() { |
| 163 | return delegateMap.entries(); |
| 164 | } |
| 165 | |
| 166 | @Override |
Jonathan Hart | 46bf89b | 2017-02-27 15:56:42 -0800 | [diff] [blame] | 167 | public CompletableFuture<Void> addListener(MultimapEventListener<K, V> listener, Executor executor) { |
| 168 | return delegateMap.addListener(listener, executor); |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public CompletableFuture<Void> removeListener(MultimapEventListener<K, V> listener) { |
| 173 | return delegateMap.removeListener(listener); |
| 174 | } |
| 175 | |
| 176 | @Override |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 177 | public CompletableFuture<Map<K, Collection<V>>> asMap() { |
| 178 | return delegateMap.asMap(); |
| 179 | } |
Aaron Kruglikov | 61582a0 | 2016-09-06 13:18:58 -0700 | [diff] [blame] | 180 | } |