1 20 21 package JFlex; 22 23 24 30 public final class Interval { 31 32 33 public char start, end; 34 35 36 42 public Interval(char start, char end) { 43 this.start = start; 44 this.end = end; 45 } 46 47 48 51 public Interval(Interval other) { 52 this.start = other.start; 53 this.end = other.end; 54 } 55 56 57 62 public boolean contains(char point) { 63 return start <= point && end >= point; 64 } 65 66 67 73 public boolean contains(Interval other) { 74 return this.start <= other.start && this.end >= other.end; 75 } 76 77 78 84 public boolean equals(Object o) { 85 if ( o == this ) return true; 86 if ( !(o instanceof Interval) ) return false; 87 88 Interval other = (Interval) o; 89 return other.start == this.start && other.end == this.end; 90 } 91 92 93 98 public void setEnd(char end) { 99 this.end = end; 100 } 101 102 103 108 public void setStart(char start) { 109 this.start = start; 110 } 111 112 113 118 private static boolean isPrintable(char c) { 119 return c > 31 && c < 127; 121 } 122 123 124 133 public String toString() { 134 StringBuffer result = new StringBuffer ("["); 135 136 if ( isPrintable(start) ) 137 result.append("'"+start+"'"); 138 else 139 result.append( (int) start ); 140 141 if (start != end) { 142 result.append("-"); 143 144 if ( isPrintable(end) ) 145 result.append("'"+end+"'"); 146 else 147 result.append( (int) end ); 148 } 149 150 result.append("]"); 151 return result.toString(); 152 } 153 154 155 160 public Interval copy() { 161 return new Interval(start,end); 162 } 163 } 164 | Popular Tags |