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