/**
 * Derived class that represents a number value.
 *   @author Dave Reed
 *   @version 2/3/18
 */
public class NumberValue implements DataValue {
    public double value;

    /**
     * Constructs a number value.
     *   @param num the number being stored
     */
    public NumberValue(double num) {
        this.value = num;
    }

    /**
     * Accesses the stored number value.
     *   @return the double value (as an Object)
     */
    public Object getValue() {
        return new Double(this.value);
    }

    /**
     * Identifies the actual type of the value.
     *   @return Token.Type.NUMBER
     */
    public Token.Type getType() {
        return Token.Type.NUMBER;
    }

    /**
     * Converts the number value to a String.
     *   @return a String representation of the number value
     */
    public String toString() {
        if (this.value == (int)this.value) {
            return "" + (int)this.value;
        }
        else {
            return "" + this.value;
        }
    }

    /**
     * Comparison method for NumberValues.
     *   @param other the value being compared with
     *   @return negative if <, 0 if ==, positive if >
     */
    public int compareTo(DataValue other) {
        return ((Double)this.getValue()).compareTo((Double)other.getValue());
    }
}