package tcra.math;

/**
 * MathInteger is the mathematical representation of an integer
 * inside another MathType or an integer argument to a method.
 */
public class MathInteger implements MathType
{
    private int value;

    /**
     * Constructor specifying the value of the integer.
     * The MathIntegerParser of the MathInteger is constructed
     * fresh.
     *
     * @param val Integer value
     */
    // unused currently but left for future development
    public MathInteger(int val)
    {
       value  = val;
    } // end ctor(int)

    /**
     * Checks if the MathInteger representation of an integer and the
     * stored integer value are equal.
     *
     * @param other MathInteger that this is to be compared to.
     * @return <code>true</code> if the stored value and the other
     *         MathString's value are equal
     *         <code>false</code> otherwise
     */
    public boolean equals(Object other)
    {
       if(other == null) return false;
       if(!(other instanceof MathInteger)) return false;

       MathInteger check = (MathInteger)other;
       return(value == check.value);
    } // end equals(Object)
    
    /**
     * Compares the stored value to the integer supplied.
     * 
     * @param val integer to compare to
     * @return <code>true</code> if the values are equal
     *         <code>false</code> otherwise
     */
    public boolean equals(int val) { return value == val; }

    /**
     * @return Integer value of the MathInteger.
     */
    public int getValue()
    {
       return value;
    } // end getValue()

    public String toString()
    {
       return Integer.toString(value);
    } // end toString()
    
    public String toHTMLString()
    {
       return toString();
    }
} // end class
