com.atlassian.util.concurrent.atomic
Class AtomicLongArray

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

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

AtomicReferenceArray with richer functionality. This class implements commonly implemented patterns of use of compareAndSet such as #getAndSetIf(int, Object, Object) and update(int, Function).

Since:
0.0.12
See Also:
Serialized Form

Constructor Summary
AtomicLongArray(int length)
          Creates a new AtomicLongArray of given length.
AtomicLongArray(long[] initialValue)
          Creates a new AtomicLongArray with the same length as, and all elements copied from, the given array.
 
Method Summary
 long getOrSetAndGetIf(int index, long oldValue, long newValue)
          Check the current value and if it matches the old value argument, set it to the new value and return that instead.
 long update(int index, com.google.common.base.Function<java.lang.Long,java.lang.Long> newValueFactory)
          Do the actual update.
 
Methods inherited from class java.util.concurrent.atomic.AtomicLongArray
addAndGet, compareAndSet, decrementAndGet, get, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, incrementAndGet, lazySet, length, set, toString, weakCompareAndSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicLongArray

public AtomicLongArray(int length)
Creates a new AtomicLongArray of given length.

Parameters:
length - the length of the array

AtomicLongArray

public AtomicLongArray(long[] initialValue)
Creates a new AtomicLongArray with the same length as, and all elements copied from, the given array.

Parameters:
array - the array to copy elements from
Throws:
java.lang.NullPointerException - if array is null
Method Detail

getOrSetAndGetIf

public final long getOrSetAndGetIf(int index,
                                   long oldValue,
                                   long 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:
index - the array index
oldValue - to check the current value against (reference equality check only)
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 long update(int index,
                         com.google.common.base.Function<java.lang.Long,java.lang.Long> 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.