- java.lang.Object
-
- org.joda.money.format.MoneyParseContext
-
public final class MoneyParseContext extends Object
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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BigDecimalgetAmount()Gets the parsed amount.CurrencyUnitgetCurrency()Gets the parsed currency.intgetErrorIndex()Gets the error index.intgetIndex()Gets the current parse position index.LocalegetLocale()Gets the locale.CharSequencegetText()Gets the text being parsed.intgetTextLength()Gets the length of the text being parsed.StringgetTextSubstring(int start, int end)Gets a substring of the text being parsed.booleanisComplete()Checks if the context contains a currency and amount suitable for creating a monetary value.booleanisError()Checks if the parse has found an error.booleanisFullyParsed()Checks if the text has been fully parsed such that there is no more text to parse.voidsetAmount(BigDecimal amount)Sets the parsed currency.voidsetCurrency(CurrencyUnit currency)Sets the parsed currency.voidsetError()Sets the error index from the current index.voidsetErrorIndex(int index)Sets the error index.voidsetIndex(int index)Sets the current parse position index.voidsetLocale(Locale locale)Sets the locale.voidsetText(CharSequence text)Sets the text.BigMoneytoBigMoney()Converts the context to aBigMoney.ParsePositiontoParsePosition()Converts the indexes to a parse position.
-
-
-
Method Detail
-
getLocale
public Locale getLocale()
Gets the locale.- Returns:
- the locale, not null
-
setLocale
public void setLocale(Locale locale)
Sets the locale.- Parameters:
locale- the locale, not null
-
getText
public CharSequence getText()
Gets the text being parsed.- Returns:
- the text being parsed, never null
-
setText
public void setText(CharSequence text)
Sets the text.- Parameters:
text- the text being parsed, not null
-
getTextLength
public int getTextLength()
Gets the length of the text being parsed.- Returns:
- the length of the text being parsed
-
getTextSubstring
public String getTextSubstring(int start, int end)
Gets a substring of the text being parsed.- Parameters:
start- the start indexend- the end index- Returns:
- the substring, not null
-
getIndex
public int getIndex()
Gets the current parse position index.- Returns:
- the current parse position index
-
setIndex
public void setIndex(int index)
Sets the current parse position index.- Parameters:
index- the current parse position index
-
getErrorIndex
public int getErrorIndex()
Gets the error index.- Returns:
- the error index, negative if no error
-
setErrorIndex
public void setErrorIndex(int index)
Sets the error index.- Parameters:
index- the error index
-
setError
public void setError()
Sets the error index from the current index.
-
getCurrency
public CurrencyUnit getCurrency()
Gets the parsed currency.- Returns:
- the parsed currency, null if not parsed yet
-
setCurrency
public void setCurrency(CurrencyUnit currency)
Sets the parsed currency.- Parameters:
currency- the parsed currency, may be null
-
getAmount
public BigDecimal getAmount()
Gets the parsed amount.- Returns:
- the parsed amount, null if not parsed yet
-
setAmount
public void setAmount(BigDecimal amount)
Sets the parsed currency.- Parameters:
amount- the parsed amount, may be null
-
isError
public boolean isError()
Checks if the parse has found an error.- Returns:
- whether a parse error has occurred
-
isFullyParsed
public boolean isFullyParsed()
Checks if the text has been fully parsed such that there is no more text to parse.- Returns:
- true if fully parsed
-
isComplete
public boolean isComplete()
Checks if the context contains a currency and amount suitable for creating a monetary value.- Returns:
- true if able to create a monetary value
-
toParsePosition
public ParsePosition toParsePosition()
Converts the indexes to a parse position.- Returns:
- the parse position, never null
-
toBigMoney
public BigMoney toBigMoney()
Converts the context to aBigMoney.- Returns:
- the monetary value, never null
- Throws:
MoneyFormatException- if either the currency or amount is missing
-
-