public final class MonetaryAmountFormat extends Object
MonetaryAmount to a String or an
Appendable.
Instances of this class are not thread-safe. Basically when using
MonetaryAmountFormat instances a new instance should be created on
each access.
| Modifier and Type | Class and Description |
|---|---|
static class |
MonetaryAmountFormat.Builder
This class implements a builder that allows creating of
MonetaryFormat instances programmatically using a fluent API. |
static class |
MonetaryAmountFormat.CurrencyStyle |
| Modifier and Type | Method and Description |
|---|---|
String |
format(javax.money.MonetaryAmount amount)
Formats a value of
T to a String. |
AmountStyle |
getAmountStyle() |
javax.money.CurrencyUnit |
getDefaultCurrency() |
javax.money.MonetaryAmount |
parse(CharSequence text)
Fully parses the text into an instance of
T. |
void |
print(Appendable appendable,
javax.money.MonetaryAmount amount)
Prints a item value to an
Appendable. |
public AmountStyle getAmountStyle()
public javax.money.CurrencyUnit getDefaultCurrency()
public String format(javax.money.MonetaryAmount amount)
T to a String. The Locale
passed defines the overall target Locale, whereas the
LocalizationStyle attached with the instances configures, how the
MonetaryFormat should generally behave. The
LocalizationStyle allows to configure the formatting and parsing
in arbitrary details. The attributes that are supported are determined by
the according MonetaryFormat implementation:
MonetaryFormat was created using the MonetaryAmountFormat.Builder
, all the FormatToken, that model the overall format, and the
ItemFactory, that is responsible for extracting the final parsing
result, returned from a parsing call, are all possible recipients for
attributes of the configuring LocalizationStyle.
MonetaryFormat was provided by an instance of
ItemFormatFactorySpi the MonetaryFormat returned
determines the capabilities that can be configured.
MonetaryFormat is created using the fluent
style MonetaryAmountFormat.Builder pattern, or provided as preconfigured
implementation, LocalizationStyles allow to configure them both
effectively.amount - the amount to print, not nullUnsupportedOperationException - if the formatter is unable to printpublic void print(Appendable appendable, javax.money.MonetaryAmount amount) throws IOException
Appendable.
Example implementations of Appendable are StringBuilder,
StringBuffer or Writer. Note that StringBuilder
and StringBuffer never throw an IOException.
appendable - the appendable to add to, not nullitem - the item to print, not nulllocale - the main target Locale to be used, not nullUnsupportedOperationException - if the formatter is unable to printItemFormatException - if there is a problem while printingIOException - if an IO error occurspublic javax.money.MonetaryAmount parse(CharSequence text) throws ParseException
T.
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 Locale as an input parameter. Additionally the
ItemFormatException instance is configured by a
LocalizationStyle. LocalizationStyles allows to configure
formatting input in detail. This allows to implement complex formatting
requirements using this interface.
text - the text to parse, not nulllocale - the main target Locale to be used, not nullnullUnsupportedOperationException - if the formatter is unable to parseItemParseException - if there is a problem while parsingParseExceptionCopyright © 2012–2013 JSR 354 - Expert Group. All rights reserved.