public final class ParseContext
extends java.lang.Object
FormatToken
in-line, when parsing an
input stream using a MonetaryAmountFormat
. It allows to inspect the
next tokens, the whole input String, or just the current input substring,
based on the current parsing position etc.
This class is mutable and intended for use by a single thread. A new instance is created for each parse.
Constructor and Description |
---|
ParseContext(java.lang.CharSequence text)
Creates a new
ParseContext with the given input. |
Modifier and Type | Method and Description |
---|---|
boolean |
consume(char c)
Tries to consume one single character.
|
boolean |
consume(java.lang.String token)
Consumes the given token.
|
int |
getErrorIndex()
Gets the error index.
|
java.lang.String |
getErrorMessage()
Get the stored error message.
|
int |
getIndex()
Gets the current parse position.
|
java.lang.CharSequence |
getInput()
Gets the residual input text starting from the current parse position.
|
java.lang.String |
getOriginalInput()
Gets the full input text.
|
javax.money.CurrencyUnit |
getParsedCurrency() |
java.lang.Number |
getParsedNumber()
Get the parsed item.
|
boolean |
hasError()
Checks if the parse has found an error.
|
boolean |
isComplete()
Method allows to determine if the item being parsed is available from the
ParseContext . |
boolean |
isFullyParsed()
Checks if the text has been fully parsed such that there is no more text
to parse.
|
java.lang.String |
lookupNextToken()
This method skips all whitespaces and returns the full text, until
another whitespace area or the end of the input is reached.
|
void |
reset()
Resets this instance; this will reset the parsing position, the error
index and also all containing results.
|
void |
setError()
Sets the error index from the current index.
|
void |
setErrorIndex(int index)
Sets the error index.
|
void |
setErrorMessage(java.lang.String message) |
void |
setParsedCurrency(javax.money.CurrencyUnit currency)
Set the parsed currency into the context.
|
void |
setParsedNumber(java.lang.Number number)
Sets the parsed numeric value into the context.
|
int |
skipWhitespace()
Skips all whitespaces until a non whitespace character is occurring.
|
java.text.ParsePosition |
toParsePosition()
Converts the indexes to a parse position.
|
java.lang.String |
toString() |
public ParseContext(java.lang.CharSequence text)
ParseContext
with the given input.text
- The test to be parsed.public boolean consume(char c)
c
- the next character being expected.public boolean consume(java.lang.String token)
token.size()
.token
- The token expected.token.size()
.public int getErrorIndex()
public java.lang.String getErrorMessage()
public int getIndex()
public java.lang.CharSequence getInput()
public java.lang.String getOriginalInput()
public javax.money.CurrencyUnit getParsedCurrency()
public java.lang.Number getParsedNumber()
public boolean hasError()
public boolean isComplete()
ParseContext
.public boolean isFullyParsed()
public java.lang.String lookupNextToken()
public void reset()
public void setError()
public void setErrorIndex(int index)
index
- the error indexpublic void setErrorMessage(java.lang.String message)
public void setParsedCurrency(javax.money.CurrencyUnit currency)
currency
- The parsed currencypublic void setParsedNumber(java.lang.Number number)
number
- The result numberpublic int skipWhitespace()
Character.isWhitespace(char)
public java.text.ParsePosition toParsePosition()
public java.lang.String toString()
toString
in class java.lang.Object