Package org.onosproject.store.primitives
Class DefaultAtomicCounterMap<K>
- java.lang.Object
-
- org.onosproject.store.service.Synchronous<AsyncAtomicCounterMap<K>>
-
- org.onosproject.store.primitives.DefaultAtomicCounterMap<K>
-
- Type Parameters:
K
- map key type
- All Implemented Interfaces:
AtomicCounterMap<K>
,DistributedPrimitive
public class DefaultAtomicCounterMap<K> extends Synchronous<AsyncAtomicCounterMap<K>> implements AtomicCounterMap<K>
Default implementation ofAtomicCounterMap
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitive
DistributedPrimitive.Status, DistributedPrimitive.Type
-
-
Field Summary
-
Fields inherited from interface org.onosproject.store.service.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description DefaultAtomicCounterMap(AsyncAtomicCounterMap<K> asyncCounterMap, long operationTimeoutMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addAndGet(K key, long delta)
Adds delta to the value currently associated with key, and returns the new value.void
clear()
Clears all entries from the map.long
decrementAndGet(K key)
Decrements by one the value currently associated with key, and returns the new value.long
get(K key)
Returns the value associated with key, or zero if there is no value associated with key.long
getAndAdd(K key, long delta)
Adds delta to the value currently associated with key, and returns the old value.long
getAndDecrement(K key)
Decrements by one the value currently associated with key, and returns the old value.long
getAndIncrement(K key)
Increments by one the value currently associated with key, and returns the old value.long
incrementAndGet(K key)
Increments by one the value currently associated with key, and returns the new value.boolean
isEmpty()
If the map is empty, returns true, otherwise false.long
put(K key, long newValue)
Associates ewValue with key in this map, and returns the value previously associated with key, or zero if there was no such value.long
putIfAbsent(K key, long newValue)
If key is not already associated with a value or if key is associated with zero, associate it with newValue.long
remove(K key)
Removes and returns the value associated with key.boolean
remove(K key, long value)
If (key, value) is currently in the map, this method removes it and returns true; otherwise, this method returns false.boolean
replace(K key, long expectedOldValue, long newValue)
If (key, expectedOldValue) is currently in the map, this method replaces expectedOldValue with newValue and returns true; otherwise, this method return false.int
size()
Returns the number of entries in the map.-
Methods inherited from class org.onosproject.store.service.Synchronous
destroy, name, primitiveType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.onosproject.store.service.AtomicCounterMap
primitiveType
-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Constructor Detail
-
DefaultAtomicCounterMap
public DefaultAtomicCounterMap(AsyncAtomicCounterMap<K> asyncCounterMap, long operationTimeoutMillis)
-
-
Method Detail
-
incrementAndGet
public long incrementAndGet(K key)
Description copied from interface:AtomicCounterMap
Increments by one the value currently associated with key, and returns the new value.- Specified by:
incrementAndGet
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- incremented value
-
decrementAndGet
public long decrementAndGet(K key)
Description copied from interface:AtomicCounterMap
Decrements by one the value currently associated with key, and returns the new value.- Specified by:
decrementAndGet
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- updated value
-
getAndIncrement
public long getAndIncrement(K key)
Description copied from interface:AtomicCounterMap
Increments by one the value currently associated with key, and returns the old value.- Specified by:
getAndIncrement
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- previous value
-
getAndDecrement
public long getAndDecrement(K key)
Description copied from interface:AtomicCounterMap
Decrements by one the value currently associated with key, and returns the old value.- Specified by:
getAndDecrement
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- previous value
-
addAndGet
public long addAndGet(K key, long delta)
Description copied from interface:AtomicCounterMap
Adds delta to the value currently associated with key, and returns the new value.- Specified by:
addAndGet
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associateddelta
- the value to add- Returns:
- updated value
-
getAndAdd
public long getAndAdd(K key, long delta)
Description copied from interface:AtomicCounterMap
Adds delta to the value currently associated with key, and returns the old value.- Specified by:
getAndAdd
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associateddelta
- the value to add- Returns:
- previous value
-
get
public long get(K key)
Description copied from interface:AtomicCounterMap
Returns the value associated with key, or zero if there is no value associated with key.- Specified by:
get
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- current value
-
put
public long put(K key, long newValue)
Description copied from interface:AtomicCounterMap
Associates ewValue with key in this map, and returns the value previously associated with key, or zero if there was no such value.- Specified by:
put
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associatednewValue
- the value to put- Returns:
- previous value or zero
-
putIfAbsent
public long putIfAbsent(K key, long newValue)
Description copied from interface:AtomicCounterMap
If key is not already associated with a value or if key is associated with zero, associate it with newValue. Returns the previous value associated with key, or zero if there was no mapping for key.- Specified by:
putIfAbsent
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associatednewValue
- the value to put- Returns:
- previous value or zero
-
replace
public boolean replace(K key, long expectedOldValue, long newValue)
Description copied from interface:AtomicCounterMap
If (key, expectedOldValue) is currently in the map, this method replaces expectedOldValue with newValue and returns true; otherwise, this method return false. If expectedOldValue is zero, this method will succeed if (key, zero) is currently in the map, or if key is not in the map at all.- Specified by:
replace
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associatedexpectedOldValue
- the expected valuenewValue
- the value to replace- Returns:
- true if the value was replaced, false otherwise
-
remove
public long remove(K key)
Description copied from interface:AtomicCounterMap
Removes and returns the value associated with key. If key is not in the map, this method has no effect and returns zero.- Specified by:
remove
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associated- Returns:
- the previous value associated with the specified key or null
-
remove
public boolean remove(K key, long value)
Description copied from interface:AtomicCounterMap
If (key, value) is currently in the map, this method removes it and returns true; otherwise, this method returns false.- Specified by:
remove
in interfaceAtomicCounterMap<K>
- Parameters:
key
- key with which the specified value is to be associatedvalue
- the value to remove- Returns:
- true if the value was removed, false otherwise
-
size
public int size()
Description copied from interface:AtomicCounterMap
Returns the number of entries in the map.- Specified by:
size
in interfaceAtomicCounterMap<K>
- Returns:
- the number of entries in the map, including
0
values
-
isEmpty
public boolean isEmpty()
Description copied from interface:AtomicCounterMap
If the map is empty, returns true, otherwise false.- Specified by:
isEmpty
in interfaceAtomicCounterMap<K>
- Returns:
- true if the map is empty.
-
clear
public void clear()
Description copied from interface:AtomicCounterMap
Clears all entries from the map.- Specified by:
clear
in interfaceAtomicCounterMap<K>
-
-