blob: 8b6b9aaeddafd266b71844bd09352e1552a7011d [file] [log] [blame]
Madan Jampani10073672016-01-21 19:13:59 -08001/*
2 * Copyright 2016 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
17package org.onosproject.store.primitives.impl;
18
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Collection;
22import java.util.Map.Entry;
23import java.util.Objects;
24import java.util.Set;
25import java.util.concurrent.CompletableFuture;
26import java.util.function.BiFunction;
27import java.util.function.Predicate;
28
29import org.onosproject.core.ApplicationId;
Madan Jampani74da78b2016-02-09 21:18:36 -080030import org.onosproject.store.primitives.TransactionId;
Madan Jampani10073672016-01-21 19:13:59 -080031import org.onosproject.store.service.AsyncConsistentMap;
32import org.onosproject.store.service.MapEventListener;
Madan Jampani74da78b2016-02-09 21:18:36 -080033import org.onosproject.store.service.MapTransaction;
Madan Jampani10073672016-01-21 19:13:59 -080034import org.onosproject.store.service.Versioned;
35
36import com.google.common.base.MoreObjects;
37
38/**
39 * {@code AsyncConsistentMap} that merely delegates control to
40 * another AsyncConsistentMap.
41 *
42 * @param <K> key type
43 * @param <V> value type
44 */
45public class DelegatingAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V> {
46
47 private final AsyncConsistentMap<K, V> delegateMap;
48
49 DelegatingAsyncConsistentMap(AsyncConsistentMap<K, V> delegateMap) {
50 this.delegateMap = checkNotNull(delegateMap, "delegate map cannot be null");
51 }
52
53 @Override
54 public String name() {
55 return delegateMap.name();
56 }
57
58 @Override
59 public ApplicationId applicationId() {
60 return delegateMap.applicationId();
61 }
62
63 @Override
64 public CompletableFuture<Integer> size() {
65 return delegateMap.size();
66 }
67
68 @Override
69 public CompletableFuture<Boolean> containsKey(K key) {
70 return delegateMap.containsKey(key);
71 }
72
73 @Override
74 public CompletableFuture<Boolean> containsValue(V value) {
75 return delegateMap.containsValue(value);
76 }
77
78 @Override
79 public CompletableFuture<Versioned<V>> get(K key) {
80 return delegateMap.get(key);
81 }
82
83 @Override
84 public CompletableFuture<Versioned<V>> computeIf(K key,
85 Predicate<? super V> condition,
86 BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
87 return delegateMap.computeIf(key, condition, remappingFunction);
88 }
89
90 @Override
91 public CompletableFuture<Versioned<V>> put(K key, V value) {
92 return delegateMap.put(key, value);
93 }
94
95 @Override
96 public CompletableFuture<Versioned<V>> putAndGet(K key, V value) {
97 return delegateMap.putAndGet(key, value);
98 }
99
100 @Override
101 public CompletableFuture<Versioned<V>> remove(K key) {
102 return delegateMap.remove(key);
103 }
104
105 @Override
106 public CompletableFuture<Void> clear() {
107 return delegateMap.clear();
108 }
109
110 @Override
111 public CompletableFuture<Set<K>> keySet() {
112 return delegateMap.keySet();
113 }
114
115 @Override
116 public CompletableFuture<Collection<Versioned<V>>> values() {
117 return delegateMap.values();
118 }
119
120 @Override
121 public CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet() {
122 return delegateMap.entrySet();
123 }
124
125 @Override
126 public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) {
127 return delegateMap.putIfAbsent(key, value);
128 }
129
130 @Override
131 public CompletableFuture<Boolean> remove(K key, V value) {
132 return delegateMap.remove(key, value);
133 }
134
135 @Override
136 public CompletableFuture<Boolean> remove(K key, long version) {
137 return delegateMap.remove(key, version);
138 }
139
140 @Override
141 public CompletableFuture<Versioned<V>> replace(K key, V value) {
142 return delegateMap.replace(key, value);
143 }
144
145 @Override
146 public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) {
147 return delegateMap.replace(key, oldValue, newValue);
148 }
149
150 @Override
151 public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) {
152 return delegateMap.replace(key, oldVersion, newValue);
153 }
154
155 @Override
156 public CompletableFuture<Void> addListener(MapEventListener<K, V> listener) {
157 return delegateMap.addListener(listener);
158 }
159
160 @Override
161 public CompletableFuture<Void> removeListener(MapEventListener<K, V> listener) {
162 return delegateMap.removeListener(listener);
163 }
164
165 @Override
Madan Jampani74da78b2016-02-09 21:18:36 -0800166 public CompletableFuture<Boolean> prepare(MapTransaction<K, V> transaction) {
167 return delegateMap.prepare(transaction);
168 }
169
170 @Override
171 public CompletableFuture<Void> commit(TransactionId transactionId) {
172 return delegateMap.commit(transactionId);
173 }
174
175 @Override
176 public CompletableFuture<Void> rollback(TransactionId transactionId) {
177 return delegateMap.rollback(transactionId);
178 }
179
180 @Override
Madan Jampani542d9e22016-04-05 15:39:55 -0700181 public CompletableFuture<Boolean> prepareAndCommit(MapTransaction<K, V> transaction) {
182 return delegateMap.prepareAndCommit(transaction);
183 }
184
185 @Override
Madan Jampani10073672016-01-21 19:13:59 -0800186 public String toString() {
187 return MoreObjects.toStringHelper(getClass())
188 .add("delegateMap", delegateMap)
189 .toString();
190 }
191
192 @Override
193 public int hashCode() {
194 return Objects.hash(delegateMap);
195 }
196
197 @Override
198 public boolean equals(Object other) {
199 if (other instanceof DelegatingAsyncConsistentMap) {
200 DelegatingAsyncConsistentMap<K, V> that = (DelegatingAsyncConsistentMap) other;
201 return this.delegateMap.equals(that.delegateMap);
202 }
203 return false;
204 }
205}