1 17 18 package org.sablecc.sablecc.structure; 19 20 import org.sablecc.sablecc.exception.InternalException; 21 22 public class Token 23 implements Comparable <Token> { 24 25 private final String name; 26 27 private final Group group; 28 29 Token( 30 String name, 31 Group group) { 32 33 if (name == null) { 34 throw new InternalException("name may not be null"); 35 } 36 37 if (group == null) { 38 throw new InternalException("group may not be null"); 39 } 40 41 this.name = name; 42 this.group = group; 43 44 group.addToken(this); 45 } 46 47 public String getName() { 48 49 return this.name; 50 } 51 52 public Group getGroup() { 53 54 return this.group; 55 } 56 57 @Override 58 public boolean equals( 59 Object obj) { 60 61 if (this == obj) { 62 return true; 63 } 64 65 if (obj == null) { 66 return false; 67 } 68 69 if (getClass() != obj.getClass()) { 70 return false; 71 } 72 73 Token token = (Token) obj; 74 75 return this.name.equals(token.name); 76 } 77 78 @Override 79 public int hashCode() { 80 81 return this.name.hashCode(); 82 } 83 84 public int compareTo( 85 Token token) { 86 87 return this.name.compareTo(token.name); 88 } 89 90 } 91 | Popular Tags |