File: BasicSourcedToken.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 (31 lines) | stat: -rw-r--r-- 872 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
package com.wcohen.ss.tokens;

import com.wcohen.ss.api.*;


/**
 * An interned version of a string, with provinance information
 *
 */

public class BasicSourcedToken extends BasicToken implements SourcedToken
{
    private final String source;
	
    BasicSourcedToken(int index,String value,String source) {
        super(index,value);
        this.source = source;
    }
    public String getSource() { return source; }
    public int compareTo(Object o) {
        SourcedToken t = (SourcedToken)o;
        int d = t.getValue().compareTo(value);
        if (d!=0) return d;
        return t.getSource().compareTo(source);
    } 
    public boolean equals(Object o) {
        return compareTo(o)==0;
    }
    public int hashCode() { return (value+"@"+source).hashCode(); }
    public String toString() { return "[tok "+getIndex()+":"+getValue()+" src:"+source+"]"; }
}