1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package com.wcohen.ss.tokens;
import java.io.Serializable;
import com.wcohen.ss.api.*;
/**
* An interned version of a string.
*
*/
public class BasicToken implements Token, Comparable, Serializable
{
protected final int index;
protected final String value;
BasicToken(int index,String value) {
this.index = index;
this.value = value;
}
public String getValue() { return value; }
public int getIndex() { return index; }
public int compareTo(Object o) {
Token t = (Token)o;
return index - t.getIndex();
}
public int hashCode() { return value.hashCode(); }
public String toString() { return "[tok "+getIndex()+":"+getValue()+"]"; }
public boolean equals(Object t) {
if (t instanceof BasicToken) return this.hashCode() == (t.hashCode());
return super.equals(t);
}
}
|