Package org.joda.money.format
Class MoneyParseContext
- java.lang.Object
-
- org.joda.money.format.MoneyParseContext
-
public final class MoneyParseContext extends java.lang.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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.math.BigDecimal
amount
The parsed amount.private CurrencyUnit
currency
The parsed currency.private java.util.Locale
locale
The locale to parse using.private java.lang.CharSequence
text
The text to parse.private int
textErrorIndex
The text error index.private int
textIndex
The text index.
-
Constructor Summary
Constructors Constructor Description MoneyParseContext(java.util.Locale locale, java.lang.CharSequence text, int index)
Constructor.MoneyParseContext(java.util.Locale locale, java.lang.CharSequence text, int index, int errorIndex, CurrencyUnit currency, java.math.BigDecimal amount)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) MoneyParseContext
createChild()
Creates a child context.java.math.BigDecimal
getAmount()
Gets the parsed amount.CurrencyUnit
getCurrency()
Gets the parsed currency.int
getErrorIndex()
Gets the error index.int
getIndex()
Gets the current parse position index.java.util.Locale
getLocale()
Gets the locale.java.lang.CharSequence
getText()
Gets the text being parsed.int
getTextLength()
Gets the length of the text being parsed.java.lang.String
getTextSubstring(int start, int end)
Gets a substring of the text being parsed.boolean
isComplete()
Checks if the context contains a currency and amount suitable for creating a monetary value.boolean
isError()
Checks if the parse has found an error.boolean
isFullyParsed()
Checks if the text has been fully parsed such that there is no more text to parse.(package private) void
mergeChild(MoneyParseContext child)
Merges the child context back into this instance.void
setAmount(java.math.BigDecimal amount)
Sets the parsed currency.void
setCurrency(CurrencyUnit currency)
Sets the parsed currency.void
setError()
Sets the error index from the current index.void
setErrorIndex(int index)
Sets the error index.void
setIndex(int index)
Sets the current parse position index.void
setLocale(java.util.Locale locale)
Sets the locale.void
setText(java.lang.CharSequence text)
Sets the text.BigMoney
toBigMoney()
Converts the context to aBigMoney
.java.text.ParsePosition
toParsePosition()
Converts the indexes to a parse position.
-
-
-
Field Detail
-
locale
private java.util.Locale locale
The locale to parse using.
-
text
private java.lang.CharSequence text
The text to parse.
-
textIndex
private int textIndex
The text index.
-
textErrorIndex
private int textErrorIndex
The text error index.
-
currency
private CurrencyUnit currency
The parsed currency.
-
amount
private java.math.BigDecimal amount
The parsed amount.
-
-
Constructor Detail
-
MoneyParseContext
MoneyParseContext(java.util.Locale locale, java.lang.CharSequence text, int index)
Constructor.- Parameters:
locale
- the locale, not nulltext
- the text to parse, not nullindex
- the current text index
-
MoneyParseContext
MoneyParseContext(java.util.Locale locale, java.lang.CharSequence text, int index, int errorIndex, CurrencyUnit currency, java.math.BigDecimal amount)
Constructor.- Parameters:
locale
- the locale, not nulltext
- the text to parse, not nullindex
- the current text indexerrorIndex
- the error indexcurrency
- the currencyamount
- the parsed amount
-
-
Method Detail
-
getLocale
public java.util.Locale getLocale()
Gets the locale.- Returns:
- the locale, not null
-
setLocale
public void setLocale(java.util.Locale locale)
Sets the locale.- Parameters:
locale
- the locale, not null
-
getText
public java.lang.CharSequence getText()
Gets the text being parsed.- Returns:
- the text being parsed, never null
-
setText
public void setText(java.lang.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 java.lang.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 java.math.BigDecimal getAmount()
Gets the parsed amount.- Returns:
- the parsed amount, null if not parsed yet
-
setAmount
public void setAmount(java.math.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
-
createChild
MoneyParseContext createChild()
Creates a child context.- Returns:
- the child context, never null
-
mergeChild
void mergeChild(MoneyParseContext child)
Merges the child context back into this instance.- Parameters:
child
- the child context, not null
-
toParsePosition
public java.text.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
-
-