File: BasicToken.java

package info (click to toggle)
libsecondstring-java 0.1~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 764 kB
  • sloc: java: 9,592; xml: 114; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 802 bytes parent folder | download
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);
	}
}