001    package org.hackystat.telemetry.analyzer.language.ast;
002    
003    /**
004     * Number constant in telemetry language.
005     * 
006     * @author (Cedric) Qin ZHANG
007     * @version $Id$
008     */
009    public class NumberConstant extends Constant {
010      
011      /** The number value. */
012      private Number value;
013      
014      /**
015       * Constructs this instance with supplied number value.
016       * 
017       * @param value The number value.
018       */
019      public NumberConstant(Number value) {
020        if (value == null) {
021          throw new NullPointerException("Value cannot be null in NumberConstant.");
022        }
023        this.value = value;
024      }
025      
026      /**
027       * Gets the value of this number.
028       * 
029       * @return The value.
030       */
031      public Number getValue() {
032        return this.value;
033      }
034      
035      /**
036       * Gets the string representation of this number.
037       * 
038       * @return The string representation of this number.
039       */
040      @Override
041      public String getValueString() {
042        return this.value.toString();
043      }
044    
045      /**
046       * Tests for equality of two instances.
047       * 
048       * @param another The other object to be tested with this object.
049       * 
050       * @return True if two instances are equal.
051       */
052      @Override
053      public boolean equals(Object another) {
054        return (another instanceof NumberConstant)
055            && (this.value.equals(((NumberConstant) another).value));
056      }
057    
058      /**
059       * Gets the hash code for this instance.
060       * 
061       * @return The hash code.
062       */
063      @Override
064      public int hashCode() {
065        return this.value.hashCode();
066      }
067    }