KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > cpd > TokenEntry


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.cpd;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 public class TokenEntry implements Comparable JavaDoc {
10
11     public static final TokenEntry EOF = new TokenEntry();
12
13     private String JavaDoc tokenSrcID;
14     private int beginLine;
15     private int index;
16     private int identifier;
17     private int hashCode;
18
19     private final static Map JavaDoc Tokens = new HashMap JavaDoc();
20     private static int TokenCount = 0;
21
22     private TokenEntry() {
23         this.identifier = 0;
24         this.tokenSrcID = "EOFMarker";
25     }
26
27     public TokenEntry(String JavaDoc image, String JavaDoc tokenSrcID, int beginLine) {
28         Integer JavaDoc i = (Integer JavaDoc) Tokens.get(image);
29         if (i == null) {
30             i = new Integer JavaDoc(Tokens.size() + 1);
31             Tokens.put(image, i);
32         }
33         this.identifier = i.intValue();
34         this.tokenSrcID = tokenSrcID;
35         this.beginLine = beginLine;
36         this.index = TokenCount++;
37     }
38
39     public static TokenEntry getEOF() {
40         TokenCount++;
41         return EOF;
42     }
43
44     public static void clearImages() {
45         Tokens.clear();
46         TokenCount = 0;
47     }
48
49     public String JavaDoc getTokenSrcID() {
50         return tokenSrcID;
51     }
52
53     public int getBeginLine() {
54         return beginLine;
55     }
56
57     public int getIdentifier() {
58         return this.identifier;
59     }
60
61     public int getIndex() {
62         return this.index;
63     }
64
65     public int hashCode() {
66         return hashCode;
67     }
68
69     public void setHashCode(int hashCode) {
70         this.hashCode = hashCode;
71     }
72
73     public boolean equals(Object JavaDoc o) {
74         if (!(o instanceof TokenEntry)) {
75             return false;
76         }
77         TokenEntry other = (TokenEntry) o;
78         return other.hashCode == hashCode;
79     }
80
81     public int compareTo(Object JavaDoc o) {
82         TokenEntry other = (TokenEntry) o;
83         return getIndex() - other.getIndex();
84     }
85 }
Popular Tags