001 /* 002 * Created on Aug 30, 2003 by Ravi Mohan 003 * 004 */ 005 package aima.logic.common; 006 007 /** 008 * @author Ravi Mohan 009 * 010 */ 011 012 public class Token { 013 private String text; 014 015 private int type; 016 017 public Token(int type, String text) { 018 this.type = type; 019 this.text = text; 020 } 021 022 public String getText() { 023 return text; 024 } 025 026 public int getType() { 027 return type; 028 } 029 030 @Override 031 public boolean equals(Object o) { 032 033 if (this == o) { 034 return true; 035 } 036 if ((o == null) || (this.getClass() != o.getClass())) { 037 return false; 038 } 039 Token other = (Token) o; 040 return ((other.type == type) && (other.text.equals(text))); 041 } 042 043 @Override 044 public int hashCode() { 045 int result = 17; 046 result = 37 * result + type; 047 result = 37 * result + text.hashCode(); 048 return 17; 049 } 050 051 @Override 052 public String toString() { 053 return "[ " + type + " " + text + " ]"; 054 } 055 056 }