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