blob: 25fd2afb0b93f1a48f7dd21ca213746b19cd7d25 [file] [log] [blame]
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -07001/*
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.service;
18
19import com.google.common.collect.Multiset;
20
21import java.util.Collection;
22import java.util.Map;
23import java.util.Set;
24
25/**
26 * This provides a synchronous version of the functionality provided by
27 * {@link AsyncConsistentMultimap}. Instead of returning futures this map
28 * blocks until the future completes then returns the result.
29 */
30public interface ConsistentMultimap<K, V> extends DistributedPrimitive {
31 /**
32 * Returns the number of key-value pairs in this multimap.
33 * @return the number of key-value pairs
34 */
35 int size();
36
37 /**
38 * Returns if this multimap contains no key-value pairs.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070039 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070040 * @return true if no key-value pairs exist, false otherwise
41 */
42 boolean isEmpty();
43
44 /**
45 * Returns true if there is at lease one key-value pair with a key equal to
46 * key.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070047 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070048 * @param key the key to query
49 * @return true if the map contains a
50 * key-value pair with key false otherwise
51 */
52 boolean containsKey(K key);
53
54 /**
55 * Returns true if this map contains at lease one key-value pair with a
56 * value equal to value.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070057 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070058 * @param value the value to query
59 * @return true if there is a key-value pair with the specified value,
60 * false otherwise.
61 */
62 boolean containsValue(V value);
63
64 /**
65 * Returns true if this map contains at least one key-value pair with key
66 * and value specified.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070067 *
68 * @param key the key to query
69 * @param value the value to query
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070070 * @return true if there is a key-value pair with the specified key and
71 * value, false otherwise.
72 */
73 boolean containsEntry(K key, V value);
74
75 /**
76 * If the key-value pair does not already exist adds either the key value
77 * pair or the value to the set of values associated with the key and
78 * returns true, if the key-value pair already exists then behavior is
79 * implementation specific with some implementations allowing duplicates
80 * and others ignoring put requests for existing entries.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070081 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070082 * @param key the key to add
83 * @param value the value to add
84 * @return true if the map has changed because of this call,
85 * false otherwise
86 */
87 boolean put(K key, V value);
88
89 /**
90 * Removes the key-value pair with the specified values if it exists. In
91 * implementations that allow duplicates which matching entry will be
92 * removed is undefined.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -070093 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -070094 * @param key the key of the pair to be removed
95 * @param value the value of the pair to be removed
96 * @return true if the map changed because of this call, false otherwise.
97 */
98 boolean remove(K key, V value);
99
100 /**
101 * Removes the key-value pairs with the specified key and values if they
102 * exist. In implementations that allow duplicates each instance of a key
103 * will remove one matching entry, which one is not defined. Equivalent to
104 * repeated calls to {@code remove()} for each key value pair but more
105 * efficient.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700106 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700107 * @param key the key of the pair to be removed
108 * @param values the set of values to be removed
109 * @return true if the map changes because of this call, false otherwise.
110 */
111 boolean removeAll(K key, Collection<? extends V> values);
112
113 /**
114 * Removes all values associated with the specified key as well as the key
115 * itself.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700116 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700117 * @param key the key whose key-value pairs will be removed
118 * @return the set of values that were removed, which may be empty, if the
119 * values did not exist the version will be less than one.
120 */
121 Versioned<Collection<? extends V>> removeAll(K key);
122
123 /**
124 * Adds the set of key-value pairs of the specified key with each of the
125 * values in the iterable if each key-value pair does not already exist,
126 * if the pair does exist the behavior is implementation specific.
127 * (Same as repeated puts but with efficiency gains.)
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700128 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700129 * @param key the key to use for all pairs to be added
130 * @param values the set of values to be added in pairs with the key
131 * @return true if any change in the map results from this call,
132 * false otherwise
133 */
134 boolean putAll(K key, Collection<? extends V> values);
135
136 /**
137 * Stores all the values in values associated with the key specified,
138 * removes all preexisting values and returns a collection of the removed
139 * values which may be empty if the entry did not exist.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700140 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700141 * @param key the key for all entries to be added
142 * @param values the values to be associated with the key
143 * @return the collection of removed values, which may be empty
144 */
145 Versioned<Collection<? extends V>> replaceValues(K key,
146 Collection<V> values);
147
148 /**
149 * Removes all key-value pairs, after which it will be empty.
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700150 */
151 void clear();
152
153 /**
154 * Returns a collection of values associated with the specified key, if the
155 * key is not in the map it will return an empty collection.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700156 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700157 * @param key the key whose associated values will be returned
158 * @return the collection of the values
159 * associated with the specified key, the collection may be empty
160 */
161 Versioned<Collection<? extends V>> get(K key);
162
163 /**
164 * Returns a set of the keys contained in this multimap with one or more
165 * associated values.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700166 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700167 * @return the collection of all keys with one or more associated values,
168 * this may be empty
169 */
170 Set<K> keySet();
171
172 /**
173 * Returns a multiset of the keys present in this multimap with one or more
174 * associated values each. Keys will appear once for each key-value pair
175 * in which they participate.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700176 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700177 * @return a multiset of the keys, this may be empty
178 */
179 Multiset<K> keys();
180
181 /**
182 * Returns a collection of values in the set with duplicates permitted, the
183 * size of this collection will equal the size of the map at the time of
184 * creation.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700185 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700186 * @return a collection of values, this may be empty
187 */
188 Multiset<V> values();
189
190 /**
191 * Returns a collection of each key-value pair in this map.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700192 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700193 * @return a collection of all entries in the map, this may be empty
194 */
195 Collection<Map.Entry<K, V>> entries();
196
197 /**
198 * Returns a map of keys to collections of values that reflect the set of
199 * key-value pairs contained in the multimap, where the key value pairs
200 * would be the key paired with each of the values in the collection.
Yuta HIGUCHIfaa7c672016-07-28 13:42:07 -0700201 *
Aaron Kruglikovb6ec9cd2016-07-25 16:01:10 -0700202 * @return a map of keys to collections of values, the returned map may be
203 * empty.
204 */
205 Map<K, Collection<V>> asMap();
206}