m_UpperBoundIsOpen = false;
if (rangeString == null) return;
// set up a tokenzier to parse the string
StreamTokenizer tokenizer =
new StreamTokenizer(new StringReader(rangeString));
tokenizer.resetSyntax();
tokenizer.whitespaceChars(0, ' ');
tokenizer.wordChars(' '+1,'\u00FF');
tokenizer.ordinaryChar('[');
tokenizer.ordinaryChar('(');
tokenizer.ordinaryChar(',');
tokenizer.ordinaryChar(']');
tokenizer.ordinaryChar(')');
try {
// get opening brace
tokenizer.nextToken();
if (tokenizer.ttype == '[') m_LowerBoundIsOpen = false;
else if (tokenizer.ttype == '(') m_LowerBoundIsOpen = true;
else throw new IllegalArgumentException("Expected opening brace on range,"
+ " found: "
+ tokenizer.toString());
// get lower bound
tokenizer.nextToken();
if (tokenizer.ttype != tokenizer.TT_WORD)
throw new IllegalArgumentException("Expected lower bound in range,"
+ " found: "
+ tokenizer.toString());
if (tokenizer.sval.compareToIgnoreCase("-inf") == 0)
m_LowerBound = Double.NEGATIVE_INFINITY;
else if (tokenizer.sval.compareToIgnoreCase("+inf") == 0)
m_LowerBound = Double.POSITIVE_INFINITY;
else if (tokenizer.sval.compareToIgnoreCase("inf") == 0)
m_LowerBound = Double.NEGATIVE_INFINITY;
else try {
m_LowerBound = Double.valueOf(tokenizer.sval).doubleValue();
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Expected lower bound in range,"
+ " found: '" + tokenizer.sval + "'");
}
// get separating comma
if (tokenizer.nextToken() != ',')
throw new IllegalArgumentException("Expected comma in range,"
+ " found: "
+ tokenizer.toString());
// get upper bound
tokenizer.nextToken();
if (tokenizer.ttype != tokenizer.TT_WORD)
throw new IllegalArgumentException("Expected upper bound in range,"
+ " found: "
+ tokenizer.toString());
if (tokenizer.sval.compareToIgnoreCase("-inf") == 0)
m_UpperBound = Double.NEGATIVE_INFINITY;
else if (tokenizer.sval.compareToIgnoreCase("+inf") == 0)
m_UpperBound = Double.POSITIVE_INFINITY;
else if (tokenizer.sval.compareToIgnoreCase("inf") == 0)
m_UpperBound = Double.POSITIVE_INFINITY;
else try {
m_UpperBound = Double.valueOf(tokenizer.sval).doubleValue();
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Expected upper bound in range,"
+ " found: '" + tokenizer.sval + "'");
}
// get closing brace
tokenizer.nextToken();
if (tokenizer.ttype == ']') m_UpperBoundIsOpen = false;
else if (tokenizer.ttype == ')') m_UpperBoundIsOpen = true;
else throw new IllegalArgumentException("Expected closing brace on range,"
+ " found: "
+ tokenizer.toString());
// check for rubbish on end
if (tokenizer.nextToken() != tokenizer.TT_EOF)
throw new IllegalArgumentException("Expected end of range string,"
+ " found: "
+ tokenizer.toString());
} catch (IOException e) {
throw new IllegalArgumentException("IOException reading attribute range"
+ " string: " + e.getMessage());
}