Top Description Fields Constructors Methods
org.joda.money.format

public final Class MoneyParseContext

extends Object
Class Inheritance
Imports
java.math.BigDecimal, java.text.ParsePosition, java.util.Locale, org.joda.money.BigMoney, .CurrencyUnit

Context used when parsing money.

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 BigDecimal
amount

The parsed amount.

private CurrencyUnit
currency

The parsed currency.

private Locale
locale

The locale to parse using.

private CharSequence
text

The text to parse.

private int
textErrorIndex

The text error index.

private int
textIndex

The text index.

Constructor Summary

AccessConstructor and Description
pack-priv
MoneyParseContext(Locale
the locale, not null
locale
,
CharSequence
the text to parse, not null
text
,
int
the current text index
index
)

Constructor.

pack-priv
MoneyParseContext(Locale
the locale, not null
locale
,
CharSequence
the text to parse, not null
text
,
int
the current text index
index
,
int
the error index
errorIndex
,
CurrencyUnit
the currency
currency
,
BigDecimal
the parsed amount
amount
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv MoneyParseContext

Returns:

the child context, never null
createChild
()

Creates a child context.

public BigDecimal

Returns:

the parsed amount, null if not parsed yet
getAmount
()

Gets the parsed amount.

public CurrencyUnit

Returns:

the parsed currency, null if not parsed yet
getCurrency
()

Gets the parsed currency.

public int

Returns:

the error index, negative if no error
getErrorIndex
()

Gets the error index.

public int

Returns:

the current parse position index
getIndex
()

Gets the current parse position index.

public Locale

Returns:

the locale, not null
getLocale
()

Gets the locale.

public CharSequence

Returns:

the text being parsed, never null
getText
()

Gets the text being parsed.

public int

Returns:

the length of the text being parsed
getTextLength
()

Gets the length of the text being parsed.

public String

Returns:

the substring, not null
getTextSubstring
(int
the start index
start
,
int
the end index
end
)

Gets a substring of the text being parsed.

public boolean

Returns:

true if able to create a monetary value
isComplete
()

Checks if the context contains a currency and amount suitable for creating a monetary value.

public boolean

Returns:

whether a parse error has occurred
isError
()

Checks if the parse has found an error.

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.

pack-priv void
mergeChild(MoneyParseContext
the child context, not null
child
)

Merges the child context back into this instance.

public void
setAmount(BigDecimal
the parsed amount, may be null
amount
)

Sets the parsed currency.

public void
setCurrency(CurrencyUnit
the parsed currency, may be null
currency
)

Sets the parsed currency.

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
setIndex(int
the current parse position index
index
)

Sets the current parse position index.

public void
setLocale(Locale
the locale, not null
locale
)

Sets the locale.

public void
setText(CharSequence
the text being parsed, not null
text
)

Sets the text.

public BigMoney

Returns:

the monetary value, never null
toBigMoney
()

Converts the context to a BigMoney.

public ParsePosition

Returns:

the parse position, never null
toParsePosition
()

Converts the indexes to a parse position.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

amountback to summary
private BigDecimal amount

The parsed amount.

currencyback to summary
private CurrencyUnit currency

The parsed currency.

localeback to summary
private Locale locale

The locale to parse using.

textback to summary
private CharSequence text

The text to parse.

textErrorIndexback to summary
private int textErrorIndex

The text error index.

textIndexback to summary
private int textIndex

The text index.

Constructor Detail

MoneyParseContextback to summary
pack-priv MoneyParseContext(Locale locale, CharSequence text, int index)

Constructor.

Parameters
locale:Locale

the locale, not null

text:CharSequence

the text to parse, not null

index:int

the current text index

MoneyParseContextback to summary
pack-priv MoneyParseContext(Locale locale, CharSequence text, int index, int errorIndex, CurrencyUnit currency, BigDecimal amount)

Constructor.

Parameters
locale:Locale

the locale, not null

text:CharSequence

the text to parse, not null

index:int

the current text index

errorIndex:int

the error index

currency:CurrencyUnit

the currency

amount:BigDecimal

the parsed amount

Method Detail

createChildback to summary
pack-priv MoneyParseContext createChild()

Creates a child context.

Returns:MoneyParseContext

the child context, never null

getAmountback to summary
public BigDecimal getAmount()

Gets the parsed amount.

Returns:BigDecimal

the parsed amount, null if not parsed yet

getCurrencyback to summary
public CurrencyUnit getCurrency()

Gets the parsed currency.

Returns:CurrencyUnit

the parsed currency, null if not parsed yet

getErrorIndexback to summary
public int getErrorIndex()

Gets the error index.

Returns:int

the error index, negative if no error

getIndexback to summary
public int getIndex()

Gets the current parse position index.

Returns:int

the current parse position index

getLocaleback to summary
public Locale getLocale()

Gets the locale.

Returns:Locale

the locale, not null

getTextback to summary
public CharSequence getText()

Gets the text being parsed.

Returns:CharSequence

the text being parsed, never null

getTextLengthback to summary
public int getTextLength()

Gets the length of the text being parsed.

Returns:int

the length of the text being parsed

getTextSubstringback to summary
public String getTextSubstring(int start, int end)

Gets a substring of the text being parsed.

Parameters
start:int

the start index

end:int

the end index

Returns:String

the substring, not null

isCompleteback to summary
public boolean isComplete()

Checks if the context contains a currency and amount suitable for creating a monetary value.

Returns:boolean

true if able to create a monetary value

isErrorback to summary
public boolean isError()

Checks if the parse has found an error.

Returns:boolean

whether a parse error has occurred

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

mergeChildback to summary
pack-priv void mergeChild(MoneyParseContext child)

Merges the child context back into this instance.

Parameters
child:MoneyParseContext

the child context, not null

setAmountback to summary
public void setAmount(BigDecimal amount)

Sets the parsed currency.

Parameters
amount:BigDecimal

the parsed amount, may be null

setCurrencyback to summary
public void setCurrency(CurrencyUnit currency)

Sets the parsed currency.

Parameters
currency:CurrencyUnit

the parsed currency, may be null

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

setIndexback to summary
public void setIndex(int index)

Sets the current parse position index.

Parameters
index:int

the current parse position index

setLocaleback to summary
public void setLocale(Locale locale)

Sets the locale.

Parameters
locale:Locale

the locale, not null

setTextback to summary
public void setText(CharSequence text)

Sets the text.

Parameters
text:CharSequence

the text being parsed, not null

toBigMoneyback to summary
public BigMoney toBigMoney()

Converts the context to a BigMoney.

Returns:BigMoney

the monetary value, never null

Exceptions
MoneyFormatException:
if either the currency or amount is missing
toParsePositionback to summary
public ParsePosition toParsePosition()

Converts the indexes to a parse position.

Returns:ParsePosition

the parse position, never null