summaryrefslogtreecommitdiff
path: root/st/TokenKey.java
blob: 23199179bd7757113a014d1ffa211a73bbaaab5f (plain)
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
35
36
37
38
39
40
41
42
43
44
45
package st;

/**
 * This class is a data structure used to distinguish tokens in
 * a given program. Tokens are considered unique if their "beginLine"
 * and name are different.
 */
public class TokenKey {

    private String name;
    private int beginLine;

    public TokenKey(String name, int beginLine) {
        // classes CANNOT collide, so CALLEES ARE EXPECTED TO USE ZERO!
        this.name = name;
        this.beginLine = beginLine;
    }

    @Override public String toString() {
        return String.format("%s (%d)",
                             this.name,
                             this.beginLine);
    }


    @Override public boolean equals(Object other) {
        boolean ret = false;
        TokenKey o;
        if (other instanceof TokenKey &&
            (o = (TokenKey) other).name == this.name &&
            o.beginLine == this.beginLine) {
            ret = true;
        }
        return ret;
    }

    @Override public int hashCode() {
        return this.name.hashCode();
    }

    public String getName() {
        return this.name;
    }

}