001    package org.hackystat.telemetry.analyzer.language.ast;
002    
003    /**
004     * String constant in telemetry language.
005     * 
006     * @author (Cedric) Qin ZHANG
007     * @version $Id$
008     */
009    public class StringConstant extends Constant {
010    
011      /** The string value. */
012      private String value;
013      
014      /**
015       * Constructs this instance.
016       * 
017       * @param value The string value of this constant.
018       */
019      public StringConstant(String value) {
020        if (value == null) {
021          throw new NullPointerException("Value cannot be null in StringConstant.");
022        }
023        this.value = value;  
024      }
025      
026      /**
027       * Gets the string this constant represents.
028       * 
029       * @return The string value.
030       */
031      public String getValue() {
032        return this.value;
033      }
034    
035      /**
036       * Gets the string this constant represents. The return value is the same as getValue() method.
037       * 
038       * @return The string value.
039       */
040      @Override
041      public String getValueString() {
042        return this.value;
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 StringConstant)
055            && (this.value.equals(((StringConstant) 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    }