com.atlassian.util.concurrent.atomic
Class AtomicInteger

java.lang.Object
  extended by java.lang.Number
      extended by java.util.concurrent.atomic.AtomicInteger
          extended by com.atlassian.util.concurrent.atomic.AtomicInteger
All Implemented Interfaces:
java.io.Serializable

public class AtomicInteger
extends java.util.concurrent.atomic.AtomicInteger

AtomicInteger with richer functionality. This class implements commonly implemented patterns of use of compareAndSet such as getOrSetAndGetIf(int, int) and update(Function).

Since:
0.0.12
See Also:
Serialized Form

Constructor Summary
AtomicInteger()
          Creates a new AtomicInteger with a zero initial value.
AtomicInteger(int initialValue)
          Creates a new AtomicInteger with the given initial value.
 
Method Summary
 int getOrSetAndGetIf(int oldValue, int newValue)
          Check the current value and if it matches the old value argument, set it to the new value and return that instead.
 int update(com.google.common.base.Function<java.lang.Integer,java.lang.Integer> newValueFactory)
          Do the actual update.
 
Methods inherited from class java.util.concurrent.atomic.AtomicInteger
addAndGet, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, incrementAndGet, intValue, lazySet, longValue, set, toString, weakCompareAndSet
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicInteger

public AtomicInteger()
Creates a new AtomicInteger with a zero initial value.


AtomicInteger

public AtomicInteger(int initialValue)
Creates a new AtomicInteger with the given initial value.

Parameters:
initialValue - the initial value
Method Detail

getOrSetAndGetIf

public final int getOrSetAndGetIf(int oldValue,
                                  int newValue)
Check the current value and if it matches the old value argument, set it to the new value and return that instead. If the old value argument does not match, ignore both and just return the current value.

Parameters:
oldValue - to check the current value against.
newValue - the new value to set it to.
Returns:
the current reference value if it doesn't match oldValue or a newly created value.

update

public final int update(com.google.common.base.Function<java.lang.Integer,java.lang.Integer> newValueFactory)
Do the actual update. Calls the factory method with the old value to do the update logic, then sets the value to that if it hasn't changed in the meantime.

Returns:
the new updated value.


Copyright © 2011 Atlassian. All Rights Reserved.