IndexParser.java
jmud-0.11/src/IndexParser.java · 1.1 KB
From the archive jmud-0_11.tgz
Download the archive « Back to the archive contents
import java.util.StringTokenizer;
class IndexParser {
static final String ALL = "tudo";
static final String DOT = ".";
private int index = 0;
private String word = "";
private String type = null;
IndexParser(String w, int i) {
index = i;
word = w;
}
IndexParser(String str) {
StringTokenizer tok = new StringTokenizer(str, DOT);
word = tok.nextToken();
if (ALL.equals(word)) {
if (tok.hasMoreTokens()) {
word = tok.nextToken();
if (tok.hasMoreTokens())
type = tok.nextToken();
}
}
else {
try {
index = Integer.parseInt(word);
if (tok.hasMoreTokens()) {
word = tok.nextToken();
if (tok.hasMoreTokens())
type = tok.nextToken();
}
else
word = "";
}
catch(NumberFormatException e) {
index = 1;
if (tok.hasMoreTokens())
type = tok.nextToken();
}
}
}
boolean isAll() {
return index == 0;
}
boolean hasType() {
return type != null;
}
String getWord() {
return word;
}
int getIndex() {
return index;
}
String getType() {
return type;
}
}