|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mckoi.util.GeneralParser
public class GeneralParser
This class provides several static convenience functions for parsing various types of character sequences. In most cases, we use a CharacterIterator to represent the sequence of characters being parsed.
Constructor Summary | |
---|---|
GeneralParser()
|
Method Summary | |
---|---|
static java.math.BigDecimal |
parseBigDecimal(java.text.CharacterIterator i)
This assumes there is a decimal number waiting on the iterator. |
static void |
parseDigitString(java.text.CharacterIterator i,
java.lang.StringBuffer digit_str)
Parses a string of 0 or more digits and appends the digits into the string buffer. |
static java.math.BigDecimal |
parseTimeMeasure(java.text.CharacterIterator i)
Parses a time grammer waiting on the character iterator. |
static void |
parseWordString(java.text.CharacterIterator i,
java.lang.StringBuffer word_buffer)
Parses a string of 0 or more words and appends the characters into the string buffer. |
static void |
skipWhiteSpace(java.text.CharacterIterator i)
Moves the iterator past any white space. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GeneralParser()
Method Detail |
---|
public static void parseDigitString(java.text.CharacterIterator i, java.lang.StringBuffer digit_str)
public static void parseWordString(java.text.CharacterIterator i, java.lang.StringBuffer word_buffer)
public static void skipWhiteSpace(java.text.CharacterIterator i)
public static java.math.BigDecimal parseBigDecimal(java.text.CharacterIterator i) throws java.text.ParseException
java.text.ParseException
public static java.math.BigDecimal parseTimeMeasure(java.text.CharacterIterator i) throws java.text.ParseException
To construct a valid time measure, you must supply a sequence of time measurements. The valid time measurements are 'week(s)', 'day(s)', 'hour(s)', 'minute(s)', 'second(s)', 'millisecond(s)'. To construct a time, we simply concatinate the measurements together. For example, '3 days 22 hours 9.5 minutes'
It accepts any number of time measurements, but not duplicates of the same.
The time measures are case insensitive. It is a little lazy how it reads the grammer. We could for example enter '1 hours 40 second' or even more extreme, '1 houraboutit 90 secondilianit' both of which are acceptable!
This method will keep on parsing the string until the end of the iterator is reached or a non-numeric time measure is found. It throws a ParseException if an invalid time measure is found or a number is invalid (eg. -3 days).
LOCALE ISSUE: This will likely be a difficult method to localise.
java.text.ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |