package DE;
import java.io.Serializable;

/**
 * This class wraps a value of the primitive type in almost exactly the
 * same way as java.lang.Double.  The major difference is that this class
 * implements the Parameter interface.  If java.lang.Double was not marked
 * final, it would have been extended instead.
 * Written by Chris Studholme
 * Licenced for redistribution under the GNU General Public Licence
 */
public final class DoubleParameter extends Number 
    implements Parameter, Serializable {
    
    private double value;

    public DoubleParameter(double value) {
	this.value=value;
    }
    public DoubleParameter(String value) throws NumberFormatException {
	this.value=Double.parseDouble(value);
    }

    public double doubleValue() {
	return value;
    }
    public float floatValue() {
	return (float)value;
    }
    public byte byteValue() {
	return (byte)value;
    }
    public short shortValue() {
	return (short)value;
    }
    public int intValue() {
	return (int)value;
    }
    public long longValue() {
	return (long)value;
    }

    public String toString() {
	return Double.toString(value);
    }

    public Parameter scaleadd(double factor,
			      Parameter other, 
			      double otherfactor) {
	double result = factor*value;
	if (other instanceof DoubleParameter)
	    result += otherfactor*((DoubleParameter)other).value;
	return new DoubleParameter(result);
    }
}
