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)
MonetaryQueryThis 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()
MonetaryAmountFormatAmountStyle to be applied when a MonetaryAmount is formatted.getAmountStyle in interface MonetaryAmountFormatAmountStyle used, never null.public CurrencyUnit getDefaultCurrency()
MonetaryAmountFormatCurrencyUnit to be applied when a MonetaryAmount is parsed and no
CurrencyUnit is provided within the pattern.getDefaultCurrency in interface MonetaryAmountFormatCurrencyUnit used, or null, if no such default
CurrencyUnit is set.public java.lang.String format(MonetaryAmount amount)
MonetaryAmountFormatMonetaryAmount to a String.format in interface MonetaryAmountFormatamount - the amount to format, not nullpublic void print(java.lang.Appendable appendable,
MonetaryAmount amount)
throws java.io.IOException
MonetaryAmountFormatMonetaryAmount to a Appendable.
Example implementations of Appendable are StringBuilder, StringBuffer
or Writer. Note that StringBuilder and StringBuffer never throw an
IOException.
print in interface MonetaryAmountFormatappendable - the appendable to add to, not nullamount - the amount to print, not nulljava.io.IOException - if an IO error occurs, thrown by the appendablepublic MonetaryAmount parse(java.lang.CharSequence text) throws MonetaryParseException
MonetaryAmountFormatMonetaryAmount.
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 MonetaryAmountFormattext - the text to parse, not nullnullMonetaryParseException - if there is a problem while parsingpublic MonetaryContext getMonetaryContext()
MonetaryAmountFormatMonetaryContext to be applied when a MonetaryAmount is parsed.getMonetaryContext in interface MonetaryAmountFormatMonetaryContext used, or null, when the defaults should be used.MonetaryAmount.getMonetaryContext()public void setDefaultCurrency(CurrencyUnit currency)
MonetaryAmountFormatCurrencyUnit to be used.setDefaultCurrency in interface MonetaryAmountFormatcurrency - 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)
MonetaryAmountFormatAmountStyle to be used.setAmountStyle in interface MonetaryAmountFormatstyle - the style, not null.public void setMonetaryContext(MonetaryContext context)
MonetaryAmountFormatMonetaryContext to be used.setMonetaryContext in interface MonetaryAmountFormatcontext - the context, or null for using the default MonetaryContext as
returned by MonetaryAmountFactory.getDefaultMonetaryContext() returned
from the MonetaryAmountFactory as returned by
MonetaryAmounts.getAmountFactory().