1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Copyright (C) 1998-2004 Gerwin Klein <lsf@jflex.de> *
4
* All rights reserved. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License. See the file *
8
* COPYRIGHT for more information. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License along *
16
* with this program; if not, write to the Free Software Foundation, Inc., *
17
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
package weka.core.parser.JFlex;
25
* An intervall of characters with basic operations.
27
* @author Gerwin Klein
28
* @version JFlex 1.4.1, $Revision: 1.1 $, $Date: 2008/05/09 09:14:11 $
30
public final class Interval {
32
/* start and end of the intervall */
33
public char start, end;
37
* Constuct a new intervall from <code>start</code> to <code>end</code>.
39
* @param start first character the intervall should contain
40
* @param end last character the intervall should contain
42
public Interval(char start, char end) {
51
public Interval(Interval other) {
52
this.start = other.start;
58
* Return <code>true</code> iff <code>point</code> is contained in this intervall.
60
* @param point the character to check
62
public boolean contains(char point) {
63
return start <= point && end >= point;
68
* Return <code>true</code> iff this intervall completely contains the
71
* @param other the other intervall
73
public boolean contains(Interval other) {
74
return this.start <= other.start && this.end >= other.end;
79
* Return <code>true</code> if <code>o</code> is an intervall
80
* with the same borders.
82
* @param o the object to check equality with
84
public boolean equals(Object o) {
85
if ( o == this ) return true;
86
if ( !(o instanceof Interval) ) return false;
88
Interval other = (Interval) o;
89
return other.start == this.start && other.end == this.end;
94
* Set a new last character
96
* @param end the new last character of this intervall
98
public void setEnd(char end) {
104
* Set a new first character
106
* @param start the new first character of this intervall
108
public void setStart(char start) {
114
* Check wether a character is printable.
116
* @param c the character to check
118
private static boolean isPrintable(char c) {
119
// fixme: should make unicode test here
120
return c > 31 && c < 127;
125
* Get a String representation of this intervall.
127
* @return a string <code>"[start-end]"</code> or
128
* <code>"[start]"</code> (if there is only one character in
129
* the intervall) where <code>start</code> and
130
* <code>end</code> are either a number (the character code)
131
* or something of the from <code>'a'</code>.
133
public String toString() {
134
StringBuffer result = new StringBuffer("[");
136
if ( isPrintable(start) )
137
result.append("'"+start+"'");
139
result.append( (int) start );
144
if ( isPrintable(end) )
145
result.append("'"+end+"'");
147
result.append( (int) end );
151
return result.toString();
156
* Make a copy of this interval.
160
public Interval copy() {
161
return new Interval(start,end);