public class DefaultConsistentMultimap<K,V> extends Synchronous<AsyncConsistentMultimap<K,V>> implements ConsistentMultimap<K,V>
ConsistentMultimap
providing synchronous access to
AsyncConsistentMultimap
.DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS
Constructor and Description |
---|
DefaultConsistentMultimap(AsyncConsistentMultimap<K,V> asyncMultimap,
long operationTimeoutMillis) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(MultimapEventListener<K,V> listener,
Executor executor)
Registers the specified listener to be notified whenever the map is updated.
|
Map<K,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.
|
void |
clear()
Removes all key-value pairs, after which it will be empty.
|
boolean |
containsEntry(K key,
V value)
Returns true if this map contains at least one key-value pair with key
and value specified.
|
boolean |
containsKey(K key)
Returns true if there is at lease one key-value pair with a key equal to
key.
|
boolean |
containsValue(V value)
Returns true if this map contains at lease one key-value pair with a
value equal to value.
|
Collection<Map.Entry<K,V>> |
entries()
Returns a collection of each key-value pair in this map.
|
Versioned<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.
|
boolean |
isEmpty()
Returns if this multimap contains no key-value pairs.
|
Iterator<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.
|
Set<K> |
keySet()
Returns a set of the keys contained in this multimap with one or more
associated values.
|
boolean |
put(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.
|
boolean |
putAll(K key,
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<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.
|
boolean |
remove(K key,
V value)
Removes the key-value pair with the specified values if it exists.
|
Versioned<Collection<? extends V>> |
removeAll(K key)
Removes all values associated with the specified key as well as the key
itself.
|
boolean |
removeAll(K key,
Collection<? extends V> values)
Removes the key-value pairs with the specified key and values if they
exist.
|
Versioned<Collection<? extends V>> |
removeAndGet(K key,
V value)
Removes the key-value pair with the specified values if it exists.
|
void |
removeListener(MultimapEventListener<K,V> listener)
Unregisters the specified listener such that it will no longer
receive map change notifications.
|
Versioned<Collection<? extends V>> |
replaceValues(K key,
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.
|
int |
size()
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.
|
destroy, name, primitiveType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addListener, stream
addStatusChangeListener, applicationId, destroy, name, primitiveType, removeStatusChangeListener, statusChangeListeners
forEach, spliterator
public DefaultConsistentMultimap(AsyncConsistentMultimap<K,V> asyncMultimap, long operationTimeoutMillis)
public int size()
ConsistentMultimap
size
in interface ConsistentMultimap<K,V>
public boolean isEmpty()
ConsistentMultimap
isEmpty
in interface ConsistentMultimap<K,V>
public boolean containsKey(K key)
ConsistentMultimap
containsKey
in interface ConsistentMultimap<K,V>
key
- the key to querypublic boolean containsValue(V value)
ConsistentMultimap
containsValue
in interface ConsistentMultimap<K,V>
value
- the value to querypublic boolean containsEntry(K key, V value)
ConsistentMultimap
containsEntry
in interface ConsistentMultimap<K,V>
key
- the key to queryvalue
- the value to querypublic boolean put(K key, V value)
ConsistentMultimap
put
in interface ConsistentMultimap<K,V>
key
- the key to addvalue
- the value to addpublic Versioned<Collection<? extends V>> putAndGet(K key, V value)
ConsistentMultimap
putAndGet
in interface ConsistentMultimap<K,V>
key
- the key to addvalue
- the value to addpublic boolean remove(K key, V value)
ConsistentMultimap
remove
in interface ConsistentMultimap<K,V>
key
- the key of the pair to be removedvalue
- the value of the pair to be removedpublic Versioned<Collection<? extends V>> removeAndGet(K key, V value)
ConsistentMultimap
removeAndGet
in interface ConsistentMultimap<K,V>
key
- the key of the pair to be removedvalue
- the value of the pair to be removedpublic boolean removeAll(K key, Collection<? extends V> values)
ConsistentMultimap
remove()
for each key value pair but more
efficient.removeAll
in interface ConsistentMultimap<K,V>
key
- the key of the pair to be removedvalues
- the set of values to be removedpublic Versioned<Collection<? extends V>> removeAll(K key)
ConsistentMultimap
removeAll
in interface ConsistentMultimap<K,V>
key
- the key whose key-value pairs will be removedpublic boolean putAll(K key, Collection<? extends V> values)
ConsistentMultimap
putAll
in interface ConsistentMultimap<K,V>
key
- the key to use for all pairs to be addedvalues
- the set of values to be added in pairs with the keypublic Versioned<Collection<? extends V>> replaceValues(K key, Collection<V> values)
ConsistentMultimap
replaceValues
in interface ConsistentMultimap<K,V>
key
- the key for all entries to be addedvalues
- the values to be associated with the keypublic void clear()
ConsistentMultimap
clear
in interface ConsistentMultimap<K,V>
public Versioned<Collection<? extends V>> get(K key)
ConsistentMultimap
get
in interface ConsistentMultimap<K,V>
key
- the key whose associated values will be returnedpublic Set<K> keySet()
ConsistentMultimap
keySet
in interface ConsistentMultimap<K,V>
public com.google.common.collect.Multiset<K> keys()
ConsistentMultimap
keys
in interface ConsistentMultimap<K,V>
public com.google.common.collect.Multiset<V> values()
ConsistentMultimap
values
in interface ConsistentMultimap<K,V>
public Collection<Map.Entry<K,V>> entries()
ConsistentMultimap
Do not use this method to read large maps. Use an Iterable.iterator()
or ConsistentMultimap.stream()
instead.
entries
in interface ConsistentMultimap<K,V>
public Map<K,Collection<V>> asMap()
ConsistentMultimap
asMap
in interface ConsistentMultimap<K,V>
public void addListener(MultimapEventListener<K,V> listener, Executor executor)
ConsistentMultimap
addListener
in interface ConsistentMultimap<K,V>
listener
- listener to notify about map eventsexecutor
- executor to use for handling incoming map eventspublic void removeListener(MultimapEventListener<K,V> listener)
ConsistentMultimap
removeListener
in interface ConsistentMultimap<K,V>
listener
- listener to unregister