// FILE. . . . . d:/hak/hlt/src/hlt/fot/NumberFunctor.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hak-Laptop
// STARTED ON. . Sat Jul 14 07:23:52 2018

// NB: this is used nowhere so far in the package or elsewhere - why define it?

package hlt.fot;

/**
 * This is a class for a functor denoting a numerical value. Note that
 * it is not related to the class <a
 * href="Functor.html"><tt>Functor</tt></a>.
 *
 * @see         Functor
 *
 * @version     Last modified on Sun Aug 05 06:41:55 2018 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

public class NumberFunctor
{ /* ************************************************************************ */
  
  /**
   * Numerical <tt>double</tt> value of this functor when it is a number
   * constant.
   */
  protected double value = Double.NaN;

  /**
   * Returns the <tt>double</tt> value of this number functor.
   */
  public double value ()
  {
    return this.value;
  }

  /**
   * Sets the number value of this number functor to the given
   * <tt>double</tt> and returns this number functor.
   */
  public NumberFunctor setValue (double value)
  {
    this.value = value;
    return this;
  }

  protected boolean isInteger = false;

  /**
   * Sets the number value of this number functor to the given
   * <tt>int</tt> and returns this number functor.
   */
  public NumberFunctor setValue (int value)
  {
    isInteger = true;
    return setValue((double)value);
  }

  /**
   * Returns <tt>true</tt> when this functor numerical value is an
   * <tt>int</tt>.
   */
  public boolean isInteger ()
  {
    return isInteger;
  }

  /* ************************************************************************ */
  
  public String toString ()
  {
    return isInteger() ? Integer.toString((int)value) : Double.toString(value);
  }
  
}
