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 longaddAndGet(K key, long delta)Adds delta to the value currently associated with key, and returns the new value.voidclear()Clears all entries from the map.longdecrementAndGet(K key)Decrements by one the value currently associated with key, and returns the new value.longget(K key)Returns the value associated with key, or zero if there is no value associated with key.longgetAndAdd(K key, long delta)Adds delta to the value currently associated with key, and returns the old value.longgetAndDecrement(K key)Decrements by one the value currently associated with key, and returns the old value.longgetAndIncrement(K key)Increments by one the value currently associated with key, and returns the old value.longincrementAndGet(K key)Increments by one the value currently associated with key, and returns the new value.booleanisEmpty()If the map is empty, returns true, otherwise false.longput(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.longputIfAbsent(K key, long newValue)If key is not already associated with a value or if key is associated with zero, associate it with newValue.longremove(K key)Removes and returns the value associated with key.booleanremove(K key, long value)If (key, value) is currently in the map, this method removes it and returns true; otherwise, this method returns false.booleanreplace(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.intsize()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:AtomicCounterMapIncrements by one the value currently associated with key, and returns the new value.- Specified by:
incrementAndGetin 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:AtomicCounterMapDecrements by one the value currently associated with key, and returns the new value.- Specified by:
decrementAndGetin 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:AtomicCounterMapIncrements by one the value currently associated with key, and returns the old value.- Specified by:
getAndIncrementin 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:AtomicCounterMapDecrements by one the value currently associated with key, and returns the old value.- Specified by:
getAndDecrementin 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:AtomicCounterMapAdds delta to the value currently associated with key, and returns the new value.- Specified by:
addAndGetin 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:AtomicCounterMapAdds delta to the value currently associated with key, and returns the old value.- Specified by:
getAndAddin 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:AtomicCounterMapReturns the value associated with key, or zero if there is no value associated with key.- Specified by:
getin 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:AtomicCounterMapAssociates ewValue with key in this map, and returns the value previously associated with key, or zero if there was no such value.- Specified by:
putin 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:AtomicCounterMapIf 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:
putIfAbsentin 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:AtomicCounterMapIf (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:
replacein 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:AtomicCounterMapRemoves and returns the value associated with key. If key is not in the map, this method has no effect and returns zero.- Specified by:
removein 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:AtomicCounterMapIf (key, value) is currently in the map, this method removes it and returns true; otherwise, this method returns false.- Specified by:
removein 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:AtomicCounterMapReturns the number of entries in the map.- Specified by:
sizein interfaceAtomicCounterMap<K>- Returns:
- the number of entries in the map, including
0values
-
isEmpty
public boolean isEmpty()
Description copied from interface:AtomicCounterMapIf the map is empty, returns true, otherwise false.- Specified by:
isEmptyin interfaceAtomicCounterMap<K>- Returns:
- true if the map is empty.
-
clear
public void clear()
Description copied from interface:AtomicCounterMapClears all entries from the map.- Specified by:
clearin interfaceAtomicCounterMap<K>
-
-