Top Description Fields Constructors Methods
com.google.common.util.concurrent

public Class AtomicDoubleArray

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtIncompatible
@J2ktIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull, java.lang.Double.doubleToRawLongBits, .Double.longBitsToDouble

A double array in which elements may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables.

This class compares primitive double values in methods such as compareAndSet by comparing their bitwise representation using Double#doubleToRawLongBits, which differs from both the primitive double == operator and from Double#equals, as if implemented by:

static boolean bitEquals(double x, double y) {
  long xBits = Double.doubleToRawLongBits(x);
  long yBits = Double.doubleToRawLongBits(y);
  return xBits == yBits;
}
Authors
Doug Lea, Martin Buchholz
Since
11.0

Field Summary

Modifier and TypeField and Description
private transient AtomicLongArray
private static final long

Constructor Summary

AccessConstructor and Description
public
AtomicDoubleArray(int
the length of the array
length
)

Creates a new AtomicDoubleArray of the given length, with all elements initially zero.

public
AtomicDoubleArray(double[]
the array to copy elements from
array
)

Creates a new AtomicDoubleArray with the same length as, and all elements copied from, the given array.

Method Summary

Modifier and TypeMethod and Description
public final double

Returns:

the updated value
accumulateAndGet
(int
the index to update
i
,
double
the update value
x
,
DoubleBinaryOperator
the accumulator function
accumulatorFunction
)

Atomically updates the element at index i with the results of applying the given function to the current and given values.

public double

Returns:

the updated value
addAndGet
(int
the index
i
,
double
the value to add
delta
)

Atomically adds the given value to the element at index i.

public final boolean

Returns:

true if successful. False return indicates that the actual value was not equal to the expected value.
compareAndSet
(int
the index
i
,
double
the expected value
expect
,
double
the new value
update
)

Atomically sets the element at position i to the given updated value if the current value is bitwise equal to the expected value.

public final double

Returns:

the current value
get
(int
the index
i
)

Gets the current value at position i.

public final double

Returns:

the previous value
getAndAccumulate
(int
the index to update
i
,
double
the update value
x
,
DoubleBinaryOperator
the accumulator function
accumulatorFunction
)

Atomically updates the element at index i with the results of applying the given function to the current and given values.

public final double

Returns:

the previous value
getAndAdd
(int
the index
i
,
double
the value to add
delta
)

Atomically adds the given value to the element at index i.

public final double

Returns:

the previous value
getAndSet
(int
the index
i
,
double
the new value
newValue
)

Atomically sets the element at position i to the given value and returns the old value.

public final double

Returns:

the previous value
getAndUpdate
(int
the index to update
i
,
DoubleUnaryOperator
the update function
updaterFunction
)

Atomically updates the element at index i with the results of applying the given function to the current value.

public final void
lazySet(int
the index
i
,
double
the new value
newValue
)

Eventually sets the element at position i to the given value.

public final int

Returns:

the length of the array
length
()

Returns the length of the array.

private void
readObject(ObjectInputStream s)

Reconstitutes the instance from a stream (that is, deserializes it).

public final void
set(int
the index
i
,
double
the new value
newValue
)

Atomically sets the element at position i to the given value.

public String

Returns:

the String representation of the current values of array
toString
()

Overrides java.lang.Object.toString.

Returns the String representation of the current values of array.
public final double

Returns:

the updated value
updateAndGet
(int
the index to update
i
,
DoubleUnaryOperator
the update function
updaterFunction
)

Atomically updates the element at index i with the results of applying the given function to the current value.

public final boolean

Returns:

true if successful
weakCompareAndSet
(int
the index
i
,
double
the expected value
expect
,
double
the new value
update
)

Atomically sets the element at position i to the given updated value if the current value is bitwise equal to the expected value.

private void
writeObject(ObjectOutputStream s)

Saves the state to a stream (that is, serializes it).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

longsback to summary
private transient AtomicLongArray longs
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

AtomicDoubleArrayback to summary
public AtomicDoubleArray(int length)

Creates a new AtomicDoubleArray of the given length, with all elements initially zero.

Parameters
length:int

the length of the array

AtomicDoubleArrayback to summary
public AtomicDoubleArray(double[] array)

Creates a new AtomicDoubleArray with the same length as, and all elements copied from, the given array.

Parameters
array:double[]

the array to copy elements from

Exceptions
NullPointerException:
if array is null

Method Detail

accumulateAndGetback to summary
public final double accumulateAndGet(int i, double x, DoubleBinaryOperator accumulatorFunction)

Atomically updates the element at index i with the results of applying the given function to the current and given values.

Parameters
i:int

the index to update

x:double

the update value

accumulatorFunction:DoubleBinaryOperator

the accumulator function

Returns:double

the updated value

Annotations
@CanIgnoreReturnValue
Since
31.1
addAndGetback to summary
public double addAndGet(int i, double delta)

Atomically adds the given value to the element at index i.

Parameters
i:int

the index

delta:double

the value to add

Returns:double

the updated value

Annotations
@CanIgnoreReturnValue
compareAndSetback to summary
public final boolean compareAndSet(int i, double expect, double update)

Atomically sets the element at position i to the given updated value if the current value is bitwise equal to the expected value.

Parameters
i:int

the index

expect:double

the expected value

update:double

the new value

Returns:boolean

true if successful. False return indicates that the actual value was not equal to the expected value.

getback to summary
public final double get(int i)

Gets the current value at position i.

Parameters
i:int

the index

Returns:double

the current value

getAndAccumulateback to summary
public final double getAndAccumulate(int i, double x, DoubleBinaryOperator accumulatorFunction)

Atomically updates the element at index i with the results of applying the given function to the current and given values.

Parameters
i:int

the index to update

x:double

the update value

accumulatorFunction:DoubleBinaryOperator

the accumulator function

Returns:double

the previous value

Annotations
@CanIgnoreReturnValue
Since
31.1
getAndAddback to summary
public final double getAndAdd(int i, double delta)

Atomically adds the given value to the element at index i.

Parameters
i:int

the index

delta:double

the value to add

Returns:double

the previous value

Annotations
@CanIgnoreReturnValue
getAndSetback to summary
public final double getAndSet(int i, double newValue)

Atomically sets the element at position i to the given value and returns the old value.

Parameters
i:int

the index

newValue:double

the new value

Returns:double

the previous value

getAndUpdateback to summary
public final double getAndUpdate(int i, DoubleUnaryOperator updaterFunction)

Atomically updates the element at index i with the results of applying the given function to the current value.

Parameters
i:int

the index to update

updaterFunction:DoubleUnaryOperator

the update function

Returns:double

the previous value

Annotations
@CanIgnoreReturnValue
Since
31.1
lazySetback to summary
public final void lazySet(int i, double newValue)

Eventually sets the element at position i to the given value.

Parameters
i:int

the index

newValue:double

the new value

lengthback to summary
public final int length()

Returns the length of the array.

Returns:int

the length of the array

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Reconstitutes the instance from a stream (that is, deserializes it).

setback to summary
public final void set(int i, double newValue)

Atomically sets the element at position i to the given value.

Parameters
i:int

the index

newValue:double

the new value

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the String representation of the current values of array.

Returns:String

the String representation of the current values of array

Annotations
@Override
updateAndGetback to summary
public final double updateAndGet(int i, DoubleUnaryOperator updaterFunction)

Atomically updates the element at index i with the results of applying the given function to the current value.

Parameters
i:int

the index to update

updaterFunction:DoubleUnaryOperator

the update function

Returns:double

the updated value

Annotations
@CanIgnoreReturnValue
Since
31.1
weakCompareAndSetback to summary
public final boolean weakCompareAndSet(int i, double expect, double update)

Atomically sets the element at position i to the given updated value if the current value is bitwise equal to the expected value.

May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.

Parameters
i:int

the index

expect:double

the expected value

update:double

the new value

Returns:boolean

true if successful

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Saves the state to a stream (that is, serializes it).

Serial data
The length of the array is emitted (int), followed by all of its elements (each a double) in the proper order.