blob: 2e46d92b5d2758e134a3dcbcd3e76f42574ed8e4 [file] [log] [blame]
Jordi Ortiz6d17a492017-02-14 18:15:34 +01001/*
2 * Copyright 2017-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.service;
17
18import com.google.common.collect.HashMultimap;
19import com.google.common.collect.Multiset;
20
21import java.util.Collection;
22import java.util.Map;
23import java.util.Set;
Jonathan Hart46bf89b2017-02-27 15:56:42 -080024import java.util.concurrent.Executor;
Jordi Ortiz6d17a492017-02-14 18:15:34 +010025import java.util.concurrent.atomic.AtomicLong;
26
27/**
28 * Implementation to test ConsistentMultimap. Very limited.
29 * No listener notification. Some methods (still not required) not implemented.
30 * @param <K> the key type
31 * @param <V> the value type
32 */
33public class TestConsistentMultimap<K, V> implements ConsistentMultimap<K, V> {
34
35 private String name;
36 private HashMultimap<K, Versioned<V>> innermap;
37 private AtomicLong counter = new AtomicLong();
38
39 public TestConsistentMultimap() {
40 this.innermap = HashMultimap.create();
41 }
42
43 private Versioned<V> version(V v) {
44 return new Versioned<>(v, counter.incrementAndGet(), System.currentTimeMillis());
45 }
46
47 @Override
48 public int size() {
49 return innermap.size();
50 }
51
52 @Override
53 public boolean isEmpty() {
54 return innermap.isEmpty();
55 }
56
57 @Override
58 public boolean containsKey(K key) {
59 return innermap.containsKey(key);
60 }
61
62 @Override
63 public boolean containsValue(V value) {
64 return innermap.containsValue(value);
65 }
66
67 @Override
68 public boolean containsEntry(K key, V value) {
69 return innermap.containsEntry(key, value);
70 }
71
72 @Override
73 public boolean put(K key, V value) {
74 return innermap.put(key, version(value));
75 }
76
77 @Override
78 public boolean remove(K key, V value) {
79 return innermap.remove(key, value);
80 }
81
82 @Override
83 public boolean removeAll(K key, Collection<? extends V> values) {
84 return false;
85 }
86
87 @Override
88 public Versioned<Collection<? extends V>> removeAll(K key) {
89 return null;
90 }
91
92 @Override
93 public boolean putAll(K key, Collection<? extends V> values) {
94 return false;
95 }
96
97 @Override
98 public Versioned<Collection<? extends V>> replaceValues(K key, Collection<V> values) {
99 return null;
100 }
101
102 @Override
103 public void clear() {
104 innermap.clear();
105 }
106
107 @Override
108 public Versioned<Collection<? extends V>> get(K key) {
109 return (Versioned<Collection<? extends V>>) innermap.get(key);
110 }
111
112 @Override
113 public Set<K> keySet() {
114 return innermap.keySet();
115 }
116
117 @Override
118 public Multiset<K> keys() {
119 return innermap.keys();
120 }
121
122 @Override
123 public Multiset<V> values() {
124 return null;
125 }
126
127 @Override
128 public Collection<Map.Entry<K, V>> entries() {
129 return null;
130 }
131
132 @Override
133 public Map<K, Collection<V>> asMap() {
134 return null;
135 }
136
137 @Override
Jonathan Hart46bf89b2017-02-27 15:56:42 -0800138 public void addListener(MultimapEventListener<K, V> listener, Executor executor) {
139 }
140
141 @Override
142 public void removeListener(MultimapEventListener<K, V> listener) {
143 }
144
145 @Override
Jordi Ortiz6d17a492017-02-14 18:15:34 +0100146 public String name() {
147 return this.name;
148 }
149
150 @Override
151 public Type primitiveType() {
152 return null;
153 }
154
155 public static TestConsistentMultimap.Builder builder() {
156 return new TestConsistentMultimap.Builder();
157 }
158
159 public static class Builder<K, V> extends ConsistentMultimapBuilder<K, V> {
160
161 @Override
162 public AsyncConsistentMultimap<K, V> buildMultimap() {
163 return null;
164 }
165
166 @Override
167 public ConsistentMultimap<K, V> build() {
168 return new TestConsistentMultimap<K, V>();
169 }
170 }
171
172}