public static final class TestAmountFormatProvider.TestFormat extends java.lang.Object implements MonetaryAmountFormat
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(MonetaryAmount amount)
Formats the given
MonetaryAmount to a String. |
AmountStyle |
getAmountStyle()
The
AmountStyle to be applied when a MonetaryAmount is formatted. |
CurrencyUnit |
getDefaultCurrency()
The
CurrencyUnit to be applied when a MonetaryAmount is parsed and no
CurrencyUnit is provided within the pattern. |
MonetaryContext |
getMonetaryContext()
The
MonetaryContext to be applied when a MonetaryAmount is parsed. |
MonetaryAmount |
parse(java.lang.CharSequence text)
Fully parses the text into an instance of
MonetaryAmount . |
void |
print(java.lang.Appendable appendable,
MonetaryAmount amount)
Formats the given
MonetaryAmount to a Appendable . |
java.lang.String |
queryFrom(MonetaryAmount amount)
Queries the specified monetary amount.
|
void |
setAmountStyle(AmountStyle style)
Set the
AmountStyle to be used. |
void |
setDefaultCurrency(CurrencyUnit currency)
Set the
CurrencyUnit to be used. |
void |
setMonetaryContext(MonetaryContext context)
Set the
MonetaryContext to be used. |
public java.lang.String queryFrom(MonetaryAmount amount)
MonetaryQuery
This queries the specified monetary amount to return an object using the logic encapsulated in the implementing class. Examples might be a query that checks if the amount is positive, or one that extracts the currency as a symbol.
There are two equivalent ways of using a MonetaryQuery
. The first
is to invoke the method on this interface. The second is to use
MonetaryAmount.query(MonetaryQuery)
:
// these two lines are equivalent, but the second approach is recommended monetary = thisQuery.queryFrom(monetary); monetary = monetary.query(thisQuery);It is recommended to use the second approach,
query(MonetaryQuery)
, as it is a lot clearer to read in code.
MonetaryAmount
to determine the result. The input object must not be altered.
This method may be called from multiple threads in parallel. It must be thread-safe when invoked.
queryFrom
in interface MonetaryQuery<java.lang.String>
amount
- the monetary amount to query, not nullpublic AmountStyle getAmountStyle()
MonetaryAmountFormat
AmountStyle
to be applied when a MonetaryAmount
is formatted.getAmountStyle
in interface MonetaryAmountFormat
AmountStyle
used, never null
.public CurrencyUnit getDefaultCurrency()
MonetaryAmountFormat
CurrencyUnit
to be applied when a MonetaryAmount
is parsed and no
CurrencyUnit
is provided within the pattern.getDefaultCurrency
in interface MonetaryAmountFormat
CurrencyUnit
used, or null
, if no such default
CurrencyUnit
is set.public java.lang.String format(MonetaryAmount amount)
MonetaryAmountFormat
MonetaryAmount
to a String.format
in interface MonetaryAmountFormat
amount
- the amount to format, not null
public void print(java.lang.Appendable appendable, MonetaryAmount amount) throws java.io.IOException
MonetaryAmountFormat
MonetaryAmount
to a Appendable
.
Example implementations of Appendable
are StringBuilder
, StringBuffer
or Writer
. Note that StringBuilder
and StringBuffer
never throw an
IOException
.
print
in interface MonetaryAmountFormat
appendable
- the appendable to add to, not nullamount
- the amount to print, not nulljava.io.IOException
- if an IO error occurs, thrown by the appendable
public MonetaryAmount parse(java.lang.CharSequence text) throws MonetaryParseException
MonetaryAmountFormat
MonetaryAmount
.
The parse must complete normally and parse the entire text. If the parse completes without reading the entire length of the text, an exception is thrown. If any other problem occurs during parsing, an exception is thrown.
This method uses a mainly delegates to contained AmountStyle
. Additionally when no
currency is on the input stream, the value of MonetaryAmountFormat.getDefaultCurrency()
is used instead
of.
Additionally the effective implementation type returned can be determined by the
MonetaryContext
applied to the MonetaryAmountFormat
. This formatter will call
MonetaryAmounts.getDefaultAmountType()
and will use the result returned
to access a corresponding MonetaryAmountFactory
to create the instance
returned.
parse
in interface MonetaryAmountFormat
text
- the text to parse, not nullnull
MonetaryParseException
- if there is a problem while parsingpublic MonetaryContext getMonetaryContext()
MonetaryAmountFormat
MonetaryContext
to be applied when a MonetaryAmount
is parsed.getMonetaryContext
in interface MonetaryAmountFormat
MonetaryContext
used, or null
, when the defaults should be used.MonetaryAmount.getMonetaryContext()
public void setDefaultCurrency(CurrencyUnit currency)
MonetaryAmountFormat
CurrencyUnit
to be used.setDefaultCurrency
in interface MonetaryAmountFormat
currency
- the currency. When set to null, parsing of an amount without any parseable
currency information will fail, creating a MonetaryParseException
.public void setAmountStyle(AmountStyle style)
MonetaryAmountFormat
AmountStyle
to be used.setAmountStyle
in interface MonetaryAmountFormat
style
- the style, not null.public void setMonetaryContext(MonetaryContext context)
MonetaryAmountFormat
MonetaryContext
to be used.setMonetaryContext
in interface MonetaryAmountFormat
context
- the context, or null
for using the default MonetaryContext
as
returned by MonetaryAmountFactory.getDefaultMonetaryContext()
returned
from the MonetaryAmountFactory
as returned by
MonetaryAmounts.getAmountFactory()
.