Top Description Fields Constructors Methods
org.javamoney.moneta.spi.format

pack-priv final Class ParseContext

extends Object
Class Inheritance
Imports
java.text.ParsePosition, java.util.Objects, javax.money.CurrencyUnit, .MonetaryAmount, javax.money.format.MonetaryAmountFormat

Context passed along to each 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.

Field Summary

Modifier and TypeField and Description
private int
errorIndex

The error index position.

private String
errorMessage

The parse error message.

private int
index

The current position of parsing.

private final CharSequence
originalInput

The full input.

private CurrencyUnit
parsedCurrency

The currency parsed, used for creation of the MonetaryAmount.

private Number
parsedNumber

The numeric part of the MonetaryAmount parsed.

Constructor Summary

AccessConstructor and Description
pack-priv
ParseContext(CharSequence
The test to be parsed.
text
)

Creates a new ParseContext with the given input.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true, if the token could be consumed and the index was increased by token.size().
consume
(String
The token expected.
token
)

Consumes the given token.

public boolean

Returns:

true, if the character matched and the index could be increased by one.
consume
(char
the next character being expected.
c
)

Tries to consume one single character.

public int

Returns:

the error index, negative if no error
getErrorIndex
()

Gets the error index.

public String

Returns:

the stored error message, or null.
getErrorMessage
()

Get the stored error message.

public int

Returns:

the current parse position within the input.
getIndex
()

Gets the current parse position.

public CharSequence

Returns:

the residual input text
getInput
()

Gets the residual input text starting from the current parse position.

public String

Returns:

the full input.
getOriginalInput
()

Gets the full input text.

public CurrencyUnit
public Number

Returns:

the item parsed.
getParsedNumber
()

Get the parsed item.

public boolean

Returns:

whether a parse error has occurred
hasError
()

Checks if the parse has found an error.

public boolean

Returns:

true, if the item is available.
isComplete
()

Method allows to determine if the item being parsed is available from the ParseContext.

public boolean

Returns:

true if fully parsed
isFullyParsed
()

Checks if the text has been fully parsed such that there is no more text to parse.

public String

Returns:

the next token found, or null.
lookupNextToken
()

This method skips all whitespaces and returns the full text, until another whitespace area or the end of the input is reached.

public void
reset()

Resets this instance; this will resetToFallback the parsing position, the error index and also all containing results.

public void
setError()

Sets the error index from the current index.

public void
setErrorIndex(int
the error index
index
)

Sets the error index.

public void
public void
setParsedCurrency(CurrencyUnit
The parsed currency
currency
)

Set the parsed currency into the context.

public void
setParsedNumber(Number
The result number
number
)

Sets the parsed numeric value into the context.

public int

Returns:

the new parse index after skipping any whitespaces.
skipWhitespace
()

Skips all whitespaces until a non whitespace character is occurring.

public ParsePosition

Returns:

the parse position, never null
toParsePosition
()

Converts the indexes to a parse position.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

errorIndexback to summary
private int errorIndex

The error index position.

errorMessageback to summary
private String errorMessage

The parse error message.

indexback to summary
private int index

The current position of parsing.

originalInputback to summary
private final CharSequence originalInput

The full input.

parsedCurrencyback to summary
private CurrencyUnit parsedCurrency

The currency parsed, used for creation of the MonetaryAmount.

parsedNumberback to summary
private Number parsedNumber

The numeric part of the MonetaryAmount parsed.

Constructor Detail

ParseContextback to summary
pack-priv ParseContext(CharSequence text)

Creates a new ParseContext with the given input.

Parameters
text:CharSequence

The test to be parsed.

Method Detail

consumeback to summary
public boolean consume(String token)

Consumes the given token. If the current residual text to be parsed starts with the parsing index is increased by token.size().

Parameters
token:String

The token expected.

Returns:boolean

true, if the token could be consumed and the index was increased by token.size().

consumeback to summary
public boolean consume(char c)

Tries to consume one single character.

Parameters
c:char

the next character being expected.

Returns:boolean

true, if the character matched and the index could be increased by one.

getErrorIndexback to summary
public int getErrorIndex()

Gets the error index.

Returns:int

the error index, negative if no error

getErrorMessageback to summary
public String getErrorMessage()

Get the stored error message.

Returns:String

the stored error message, or null.

getIndexback to summary
public int getIndex()

Gets the current parse position.

Returns:int

the current parse position within the input.

getInputback to summary
public CharSequence getInput()

Gets the residual input text starting from the current parse position.

Returns:CharSequence

the residual input text

getOriginalInputback to summary
public String getOriginalInput()

Gets the full input text.

Returns:String

the full input.

getParsedCurrencyback to summary
public CurrencyUnit getParsedCurrency()
getParsedNumberback to summary
public Number getParsedNumber()

Get the parsed item.

Returns:Number

the item parsed.

hasErrorback to summary
public boolean hasError()

Checks if the parse has found an error.

Returns:boolean

whether a parse error has occurred

isCompleteback to summary
public boolean isComplete()

Method allows to determine if the item being parsed is available from the ParseContext.

Returns:boolean

true, if the item is available.

isFullyParsedback to summary
public boolean isFullyParsed()

Checks if the text has been fully parsed such that there is no more text to parse.

Returns:boolean

true if fully parsed

lookupNextTokenback to summary
public String lookupNextToken()

This method skips all whitespaces and returns the full text, until another whitespace area or the end of the input is reached. The method will not update any index pointers.

Returns:String

the next token found, or null.

resetback to summary
public void reset()

Resets this instance; this will resetToFallback the parsing position, the error index and also all containing results.

setErrorback to summary
public void setError()

Sets the error index from the current index.

setErrorIndexback to summary
public void setErrorIndex(int index)

Sets the error index.

Parameters
index:int

the error index

setErrorMessageback to summary
public void setErrorMessage(String message)
setParsedCurrencyback to summary
public void setParsedCurrency(CurrencyUnit currency)

Set the parsed currency into the context.

Parameters
currency:CurrencyUnit

The parsed currency

setParsedNumberback to summary
public void setParsedNumber(Number number)

Sets the parsed numeric value into the context.

Parameters
number:Number

The result number

skipWhitespaceback to summary
public int skipWhitespace()

Skips all whitespaces until a non whitespace character is occurring. If the next character is not whitespace this method does nothing.

Returns:int

the new parse index after skipping any whitespaces.

See Also
Character#isWhitespace(char)
toParsePositionback to summary
public ParsePosition toParsePosition()

Converts the indexes to a parse position.

Returns:ParsePosition

the parse position, never null

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override