Class AtomicDouble

  • All Implemented Interfaces:
    Serializable

    public class AtomicDouble
    extends Number

    Thread safe double container

    Author:
    David B. Bracewell
    See Also:
    Serialized Form
    • Constructor Detail

      • AtomicDouble

        public AtomicDouble()
        Instantiates a new Atomic double.
      • AtomicDouble

        public AtomicDouble​(double value)
        Instantiates a new Atomic double.
        Parameters:
        value - the value
    • Method Detail

      • addAndGet

        public final double addAndGet​(double value)
        Atomically adds the given value to the current value.
        Parameters:
        value - the value
        Returns:
        the updated value
      • compareAndSet

        public final boolean compareAndSet​(double expect,
                                           double update)
        Atomically sets the value to the given updated value if the current value == the expected value.
        Parameters:
        expect - the expected value
        update - the new value
        Returns:
        true if successful. False return indicates that the actual value was not equal to the expected value.
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class Number
      • get

        public double get()
        Gets the double value
        Returns:
        the double
      • getAndAdd

        public final double getAndAdd​(double value)
        Atomically adds the given value to the current value.
        Parameters:
        value - the value
        Returns:
        the previous value
      • getAndSet

        public double getAndSet​(double value)
        Atomically sets to the given value and returns the old value.
        Parameters:
        value - the value to set
        Returns:
        the value before the update
      • intValue

        public int intValue()
        Specified by:
        intValue in class Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class Number
      • set

        public void set​(double value)
        Sets to the given value.
        Parameters:
        value - the value
      • weakCompareAndSet

        public final boolean weakCompareAndSet​(double expect,
                                               double update)
        Atomically sets the value to the given updated value if the current value == the expected value.
        Parameters:
        expect - the expected value
        update - the updated value
        Returns:
        True if updated, False if not