Package org.onosproject.store.primitives
Class DefaultConsistentMultimap<K,V>
- java.lang.Object
- 
- org.onosproject.store.service.Synchronous<AsyncConsistentMultimap<K,V>>
- 
- org.onosproject.store.primitives.DefaultConsistentMultimap<K,V>
 
 
- 
- All Implemented Interfaces:
- java.lang.Iterable<java.util.Map.Entry<K,V>>,- ConsistentMultimap<K,V>,- DistributedPrimitive
 
 public class DefaultConsistentMultimap<K,V> extends Synchronous<AsyncConsistentMultimap<K,V>> implements ConsistentMultimap<K,V> Implementation ofConsistentMultimapproviding synchronous access toAsyncConsistentMultimap.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitiveDistributedPrimitive.Status, DistributedPrimitive.Type
 
- 
 - 
Field Summary- 
Fields inherited from interface org.onosproject.store.service.DistributedPrimitiveDEFAULT_OPERATION_TIMEOUT_MILLIS
 
- 
 - 
Constructor SummaryConstructors Constructor Description DefaultConsistentMultimap(AsyncConsistentMultimap<K,V> asyncMultimap, long operationTimeoutMillis)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(MultimapEventListener<K,V> listener, java.util.concurrent.Executor executor)Registers the specified listener to be notified whenever the map is updated.java.util.Map<K,java.util.Collection<V>>asMap()Returns a map of keys to collections of values that reflect the set of key-value pairs contained in the multimap, where the key value pairs would be the key paired with each of the values in the collection.voidclear()Removes all key-value pairs, after which it will be empty.booleancontainsEntry(K key, V value)Returns true if this map contains at least one key-value pair with key and value specified.booleancontainsKey(K key)Returns true if there is at lease one key-value pair with a key equal to key.booleancontainsValue(V value)Returns true if this map contains at lease one key-value pair with a value equal to value.java.util.Collection<java.util.Map.Entry<K,V>>entries()Returns a collection of each key-value pair in this map.Versioned<java.util.Collection<? extends V>>get(K key)Returns a collection of values associated with the specified key, if the key is not in the map it will return an empty collection.booleanisEmpty()Returns if this multimap contains no key-value pairs.java.util.Iterator<java.util.Map.Entry<K,V>>iterator()com.google.common.collect.Multiset<K>keys()Returns a multiset of the keys present in this multimap with one or more associated values each.java.util.Set<K>keySet()Returns a set of the keys contained in this multimap with one or more associated values.booleanput(K key, V value)If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns true, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.booleanputAll(K key, java.util.Collection<? extends V> values)Adds the set of key-value pairs of the specified key with each of the values in the iterable if each key-value pair does not already exist, if the pair does exist the behavior is implementation specific.Versioned<java.util.Collection<? extends V>>putAndGet(K key, V value)If the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns the updated value, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.booleanremove(K key, V value)Removes the key-value pair with the specified values if it exists.Versioned<java.util.Collection<? extends V>>removeAll(K key)Removes all values associated with the specified key as well as the key itself.booleanremoveAll(K key, java.util.Collection<? extends V> values)Removes the key-value pairs with the specified key and values if they exist.Versioned<java.util.Collection<? extends V>>removeAndGet(K key, V value)Removes the key-value pair with the specified values if it exists.voidremoveListener(MultimapEventListener<K,V> listener)Unregisters the specified listener such that it will no longer receive map change notifications.Versioned<java.util.Collection<? extends V>>replaceValues(K key, java.util.Collection<V> values)Stores all the values in values associated with the key specified, removes all preexisting values and returns a collection of the removed values which may be empty if the entry did not exist.intsize()Returns the number of key-value pairs in this multimap.com.google.common.collect.Multiset<V>values()Returns a collection of values in the set with duplicates permitted, the size of this collection will equal the size of the map at the time of creation.- 
Methods inherited from class org.onosproject.store.service.Synchronousdestroy, name, primitiveType
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.onosproject.store.service.ConsistentMultimapaddListener, stream
 - 
Methods inherited from interface org.onosproject.store.service.DistributedPrimitiveaddStatusChangeListener, applicationId, destroy, name, primitiveType, removeStatusChangeListener, statusChangeListeners
 
- 
 
- 
- 
- 
Constructor Detail- 
DefaultConsistentMultimappublic DefaultConsistentMultimap(AsyncConsistentMultimap<K,V> asyncMultimap, long operationTimeoutMillis) 
 
- 
 - 
Method Detail- 
sizepublic int size() Description copied from interface:ConsistentMultimapReturns the number of key-value pairs in this multimap.- Specified by:
- sizein interface- ConsistentMultimap<K,V>
- Returns:
- the number of key-value pairs
 
 - 
isEmptypublic boolean isEmpty() Description copied from interface:ConsistentMultimapReturns if this multimap contains no key-value pairs.- Specified by:
- isEmptyin interface- ConsistentMultimap<K,V>
- Returns:
- true if no key-value pairs exist, false otherwise
 
 - 
containsKeypublic boolean containsKey(K key) Description copied from interface:ConsistentMultimapReturns true if there is at lease one key-value pair with a key equal to key.- Specified by:
- containsKeyin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key to query
- Returns:
- true if the map contains a key-value pair with key false otherwise
 
 - 
containsValuepublic boolean containsValue(V value) Description copied from interface:ConsistentMultimapReturns true if this map contains at lease one key-value pair with a value equal to value.- Specified by:
- containsValuein interface- ConsistentMultimap<K,V>
- Parameters:
- value- the value to query
- Returns:
- true if there is a key-value pair with the specified value, false otherwise.
 
 - 
containsEntrypublic boolean containsEntry(K key, V value) Description copied from interface:ConsistentMultimapReturns true if this map contains at least one key-value pair with key and value specified.- Specified by:
- containsEntryin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key to query
- value- the value to query
- Returns:
- true if there is a key-value pair with the specified key and value, false otherwise.
 
 - 
putpublic boolean put(K key, V value) Description copied from interface:ConsistentMultimapIf the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns true, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.- Specified by:
- putin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key to add
- value- the value to add
- Returns:
- true if the map has changed because of this call, false otherwise
 
 - 
putAndGetpublic Versioned<java.util.Collection<? extends V>> putAndGet(K key, V value) Description copied from interface:ConsistentMultimapIf the key-value pair does not already exist adds either the key value pair or the value to the set of values associated with the key and returns the updated value, if the key-value pair already exists then behavior is implementation specific with some implementations allowing duplicates and others ignoring put requests for existing entries.- Specified by:
- putAndGetin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key to add
- value- the value to add
- Returns:
- the updated values
 
 - 
removepublic boolean remove(K key, V value) Description copied from interface:ConsistentMultimapRemoves the key-value pair with the specified values if it exists. In implementations that allow duplicates which matching entry will be removed is undefined.- Specified by:
- removein interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key of the pair to be removed
- value- the value of the pair to be removed
- Returns:
- true if the map changed because of this call, false otherwise.
 
 - 
removeAndGetpublic Versioned<java.util.Collection<? extends V>> removeAndGet(K key, V value) Description copied from interface:ConsistentMultimapRemoves the key-value pair with the specified values if it exists. In implementations that allow duplicates which matching entry will be removed is undefined.- Specified by:
- removeAndGetin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key of the pair to be removed
- value- the value of the pair to be removed
- Returns:
- the updated values
 
 - 
removeAllpublic boolean removeAll(K key, java.util.Collection<? extends V> values) Description copied from interface:ConsistentMultimapRemoves the key-value pairs with the specified key and values if they exist. In implementations that allow duplicates each instance of a key will remove one matching entry, which one is not defined. Equivalent to repeated calls toremove()for each key value pair but more efficient.- Specified by:
- removeAllin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key of the pair to be removed
- values- the set of values to be removed
- Returns:
- true if the map changes because of this call, false otherwise.
 
 - 
removeAllpublic Versioned<java.util.Collection<? extends V>> removeAll(K key) Description copied from interface:ConsistentMultimapRemoves all values associated with the specified key as well as the key itself.- Specified by:
- removeAllin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key whose key-value pairs will be removed
- Returns:
- the set of values that were removed, which may be empty, if the values did not exist the version will be less than one.
 
 - 
putAllpublic boolean putAll(K key, java.util.Collection<? extends V> values) Description copied from interface:ConsistentMultimapAdds the set of key-value pairs of the specified key with each of the values in the iterable if each key-value pair does not already exist, if the pair does exist the behavior is implementation specific. (Same as repeated puts but with efficiency gains.)- Specified by:
- putAllin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key to use for all pairs to be added
- values- the set of values to be added in pairs with the key
- Returns:
- true if any change in the map results from this call, false otherwise
 
 - 
replaceValuespublic Versioned<java.util.Collection<? extends V>> replaceValues(K key, java.util.Collection<V> values) Description copied from interface:ConsistentMultimapStores all the values in values associated with the key specified, removes all preexisting values and returns a collection of the removed values which may be empty if the entry did not exist.- Specified by:
- replaceValuesin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key for all entries to be added
- values- the values to be associated with the key
- Returns:
- the collection of removed values, which may be empty
 
 - 
clearpublic void clear() Description copied from interface:ConsistentMultimapRemoves all key-value pairs, after which it will be empty.- Specified by:
- clearin interface- ConsistentMultimap<K,V>
 
 - 
getpublic Versioned<java.util.Collection<? extends V>> get(K key) Description copied from interface:ConsistentMultimapReturns a collection of values associated with the specified key, if the key is not in the map it will return an empty collection.- Specified by:
- getin interface- ConsistentMultimap<K,V>
- Parameters:
- key- the key whose associated values will be returned
- Returns:
- the collection of the values associated with the specified key, the collection may be empty
 
 - 
keySetpublic java.util.Set<K> keySet() Description copied from interface:ConsistentMultimapReturns a set of the keys contained in this multimap with one or more associated values.- Specified by:
- keySetin interface- ConsistentMultimap<K,V>
- Returns:
- the collection of all keys with one or more associated values, this may be empty
 
 - 
keyspublic com.google.common.collect.Multiset<K> keys() Description copied from interface:ConsistentMultimapReturns a multiset of the keys present in this multimap with one or more associated values each. Keys will appear once for each key-value pair in which they participate.- Specified by:
- keysin interface- ConsistentMultimap<K,V>
- Returns:
- a multiset of the keys, this may be empty
 
 - 
valuespublic com.google.common.collect.Multiset<V> values() Description copied from interface:ConsistentMultimapReturns a collection of values in the set with duplicates permitted, the size of this collection will equal the size of the map at the time of creation.- Specified by:
- valuesin interface- ConsistentMultimap<K,V>
- Returns:
- a collection of values, this may be empty
 
 - 
entriespublic java.util.Collection<java.util.Map.Entry<K,V>> entries() Description copied from interface:ConsistentMultimapReturns a collection of each key-value pair in this map.Do not use this method to read large maps. Use an Iterable.iterator()orConsistentMultimap.stream()instead.- Specified by:
- entriesin interface- ConsistentMultimap<K,V>
- Returns:
- a collection of all entries in the map, this may be empty
 
 - 
iteratorpublic java.util.Iterator<java.util.Map.Entry<K,V>> iterator() - Specified by:
- iteratorin interface- java.lang.Iterable<K>
 
 - 
asMappublic java.util.Map<K,java.util.Collection<V>> asMap() Description copied from interface:ConsistentMultimapReturns a map of keys to collections of values that reflect the set of key-value pairs contained in the multimap, where the key value pairs would be the key paired with each of the values in the collection.- Specified by:
- asMapin interface- ConsistentMultimap<K,V>
- Returns:
- a map of keys to collections of values, the returned map may be empty.
 
 - 
addListenerpublic void addListener(MultimapEventListener<K,V> listener, java.util.concurrent.Executor executor) Description copied from interface:ConsistentMultimapRegisters the specified listener to be notified whenever the map is updated.- Specified by:
- addListenerin interface- ConsistentMultimap<K,V>
- Parameters:
- listener- listener to notify about map events
- executor- executor to use for handling incoming map events
 
 - 
removeListenerpublic void removeListener(MultimapEventListener<K,V> listener) Description copied from interface:ConsistentMultimapUnregisters the specified listener such that it will no longer receive map change notifications.- Specified by:
- removeListenerin interface- ConsistentMultimap<K,V>
- Parameters:
- listener- listener to unregister
 
 
- 
 
-