001    package org.hackystat.telemetry.analyzer.language.ast;
002    
003    /**
004     * A constant in telemetry language. Since telemetry language is dynamically typed language 
005     * (type information can only be determined at run time), there is no type information 
006     * associated with variable.
007     * 
008     * @author (Cedric) Qin ZHANG
009     * @version $Id$
010     */
011    public class Variable implements Expression {
012    
013      /** Variable name. */
014      private String name;
015      
016      /**
017       * Constructs this instance.
018       * 
019       * @param name The name of this variable.
020       */
021      public Variable(String name) {
022        if (name == null) {
023          throw new NullPointerException("Name cannot be null in Variable.");
024        }
025        this.name = name;
026      }
027      
028      /**
029       * Gets the name of this variable.
030       * 
031       * @return The variable name.
032       */
033      public String getName() {
034        return this.name;
035      }
036      
037      /**
038       * Tests for equality of two instances.
039       * 
040       * @param another The other object to be tested with this object.
041       * 
042       * @return True if two instances are equal.
043       */
044      @Override
045      public boolean equals(Object another) {
046        return (another instanceof Variable)
047            && (this.name.equals(((Variable) another).name));
048      }
049    
050      /**
051       * Gets the hash code for this instance.
052       * 
053       * @return The hash code.
054       */
055      @Override
056      public int hashCode() {
057        return this.name.hashCode();
058      }
059    }