001    package com.softnetConsult.utils.mutableWrappers;
002    
003    /**
004     * This class wraps a single <strong>public</strong> variable of type {@code double} -
005     * it can be used to emulate passing double values by reference.
006     * All methods here are self-explanatory and perform the same function as the corresponding
007     * methods of the classes {@link java.lang.Number} and {@link java.lang.Double}.
008     * 
009     * <p style="font-size:smaller;">This product includes software developed by the
010     *    <strong>SoftNet-Consult Java Utility Library</strong> project and its contributors.<br />
011     *    (<a href="http://java-tools.sourceforge.net" target="_blank">http://java-tools.sourceforge.net</a>)<br />
012     *    Copyright (c) 2007-2008 SoftNet-Consult.<br />
013     *    Copyright (c) 2007-2008 G. Paperin.<br />
014     *    All rights reserved.
015     * </p>
016     * <p style="font-size:smaller;">File: MutableDouble.java<br />
017     *    Library API version: {@value com.softnetConsult.utils.APIProperties#apiVersion}<br />
018     *    Java compliance version: {@value com.softnetConsult.utils.APIProperties#javaComplianceVersion}
019     * </p>
020     * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or
021     *    without modification, are permitted provided that the following terms and conditions are met:
022     * </p>
023     * <p style="font-size:smaller;">1. Redistributions of source code must retain the above
024     *    acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
025     *    notice, this list of conditions and the following disclaimer.<br />
026     *    2. Redistributions in binary form must reproduce the above acknowledgement of the
027     *    SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
028     *    conditions and the following disclaimer in the documentation and/or other materials
029     *    provided with the distribution.<br />
030     *    3. All advertising materials mentioning features or use of this software or any derived
031     *    software must display the following acknowledgement:<br />
032     *    <em>This product includes software developed by the SoftNet-Consult Java Utility Library
033     *    project and its contributors.</em>
034     * </p>
035     * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY
036     *    OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
037     *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT SHALL
038     *    THE AUTHORS, CONTRIBUTORS OR COPYRIGHT  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
039     *    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR
040     *    IN CONNECTION WITH THE SOFTWARE OR THE USE OR  OTHER DEALINGS IN THE SOFTWARE.
041     * </p> 
042     * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>)
043     * @version {@value com.softnetConsult.utils.APIProperties#apiVersion}
044     *
045     */
046    public class MutableDouble extends Number implements MutableWrapper {
047    
048    public double value = Double.NaN;
049    
050    public MutableDouble() {}
051    
052    public MutableDouble(double value) {
053            this.value = value;
054    }
055    
056    public MutableDouble(String value) {
057            this.value = Double.parseDouble(value);
058    }
059    
060    public boolean booleanValue()                   { return (0.0f == this.value); }
061    @Override public byte byteValue()               { return (byte) this.value; }
062    @Override public short shortValue()             { return (short) this.value; }
063    @Override public int intValue()                 { return (int) this.value; }
064    @Override public long longValue()               { return (long) this.value; }
065    @Override public float floatValue()             { return (float) this.value; }
066    @Override public double doubleValue()   { return this.value; }
067    public String stringValue()                             { return Double.toString(this.value); }
068    @Override public String toString()              { return stringValue(); }
069    
070    } // public class MutableDouble