FileDocCategorySizeDatePackage
AtomicDouble.javaAPI DocExample4390Thu Mar 11 19:56:52 GMT 2004javathreads.examples.ch05

AtomicDouble

public class AtomicDouble extends Number

Fields Summary
private AtomicReference
value
Constructors Summary
public AtomicDouble()

        this(0.0);
    
public AtomicDouble(double initVal)

        value = new AtomicReference<Double>(new Double(initVal));
    
Methods Summary
public java.lang.DoubleDoubleValue()

        return value.get();
    
public doubleaddAndGet(double delta)

        Double origVal, newVal;

        while (true) {
            origVal = value.get();
            newVal = new Double(origVal.doubleValue() + delta);
            if (value.compareAndSet(origVal, newVal))
                return newVal.doubleValue();
        }
    
public bytebyteValue()

        return (byte)intValue();
    
public booleancompareAndSet(double expect, double update)

        Double origVal, newVal;

        newVal = new Double(update);
        while (true) {
            origVal = value.get();

            if (Double.compare(origVal.doubleValue(), expect) == 0) {
                if (value.compareAndSet(origVal, newVal))
                    return true; 
            } else {
                return false;
            }
        }
    
public intcompareTo(java.lang.Double aValue)

        return Double.compare(doubleValue(), aValue.doubleValue());
    
public intcompareTo(javathreads.examples.ch05.AtomicDouble aValue)

        return Double.compare(doubleValue(), aValue.doubleValue());
    
public doubledecrementAndGet()

        return addAndGet((double) -1.0);
    
public doubledoubleValue()

        return DoubleValue().doubleValue();
    
public booleanequals(java.lang.Object obj)

        Double origVal = DoubleValue();

        return ((obj instanceof Double)
                && (origVal.equals((Double)obj)))
               ||
               ((obj instanceof AtomicDouble)
                && 
(origVal.equals(((AtomicDouble)obj).DoubleValue())));
    
public floatfloatValue()

        return DoubleValue().floatValue();
    
public doubleget()

        return value.get().doubleValue();
    
public doublegetAndAdd(double delta)

        Double origVal, newVal;

        while (true) {
            origVal = value.get();
            newVal = new Double(origVal.doubleValue() + delta);
            if (value.compareAndSet(origVal, newVal))
                return origVal.doubleValue();
        }
    
public doublegetAndDecrement()

        return getAndAdd((double) -1.0);
    
public doublegetAndIncrement()

        return getAndAdd((double) 1.0);
    
public doublegetAndMultiply(double multiple)

        Double origVal, newVal;

        while (true) {
            origVal = value.get();
            newVal = new Double(origVal.doubleValue() * multiple);
            if (value.compareAndSet(origVal, newVal))
                return origVal.doubleValue();
        }
    
public doublegetAndSet(double setVal)

        Double origVal, newVal;

        newVal = new Double(setVal);
        while (true) {
            origVal = value.get();

            if (value.compareAndSet(origVal, newVal))
                return origVal.doubleValue();
        }
    
public inthashCode()

        return DoubleValue().hashCode();
    
public doubleincrementAndGet()

        return addAndGet((double) 1.0);
    
public intintValue()

        return DoubleValue().intValue();
    
public booleanisInfinite()

        return DoubleValue().isInfinite();
    
public booleanisNaN()

        return DoubleValue().isNaN();
    
public longlongValue()

        return DoubleValue().longValue();
    
public doublemultiplyAndGet(double multiple)

        Double origVal, newVal;

        while (true) {
            origVal = value.get();
            newVal = new Double(origVal.doubleValue() * multiple);
            if (value.compareAndSet(origVal, newVal))
                return newVal.doubleValue();
        }
    
public voidset(double newVal)

        value.set(new Double(newVal));
    
public shortshortValue()

        return (short)intValue();
    
public java.lang.StringtoString()

        return DoubleValue().toString();
    
public booleanweakCompareAndSet(double expect, double update)

        return compareAndSet(expect, update);