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.
When parsing currencies this format supports an optional currencyProviderName
context parameter on the AmountFormatContext. This name will be passed as a currency trarget provider when
resolving currency codes and symbols.
| Modifier and Type | Field and Description |
|---|---|
| private AmountFormatContext | amountFormatContext
The current |
| private static final char | CURRENCY_SIGN
The international Unicode currency sign. |
| private List | negativeTokens
The tokens to be used for formatting/parsing of negative numbers. |
| private List | positiveTokens
The tokens to be used for formatting/parsing of positive and zero numbers. |
| private static final char | SUBPATTERN_BOUNDARY
Separates positive and negative subpatterns |
| Access | Constructor and Description |
|---|---|
| pack-priv | DefaultMonetaryAmountFormat(AmountFormatContext
the amountFormatContext)javax. to be used, not null.Creates a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the string printed using the settings of this formatterthe amount to print, not amount)nullOverrides default javax. Formats a value of |
| public AmountFormatContext | getContext()
Implements javax. The |
| private String | |
| private List | |
| private boolean | |
| private boolean | |
| public MonetaryAmount | Returns: the parsed value, nevernullthe text to parse, not null text)Implements javax. Fully parses the text into an instance of |
| public void | print(Appendable
the appendable to add to, not null appendable, MonetaryAmount the amount to print, not null amount)Implements javax. Prints a item value to an |
| public String | queryFrom(MonetaryAmount amount)
Implements javax. Queries the specified monetary amount. |
| private String | |
| private void | |
| private String[] | splitIntoPlusMinusPatterns(AmountFormatContext amountFormatContext, String pattern)
Split into (potential) plus, minus patterns |
| private List | Returns: the tokenized list.the token identified so far. tokens, DecimalFormat the target locale. format)Splits away the number pattern for targeting an AmountToken, if possible. |
| private List | splitPatternForCurrency(String pattern)
Splits the given pattern into a prefix, a currency token and a postfix token. |
| private List |
| amountFormatContext | back to summary |
|---|---|
| private AmountFormatContext amountFormatContext The current | |
| CURRENCY_SIGN | back to summary |
|---|---|
| private static final char CURRENCY_SIGN The international Unicode currency sign. | |
| negativeTokens | back to summary |
|---|---|
| private List<FormatToken> negativeTokens The tokens to be used for formatting/parsing of negative numbers. | |
| positiveTokens | back to summary |
|---|---|
| private List<FormatToken> positiveTokens The tokens to be used for formatting/parsing of positive and zero numbers. | |
| SUBPATTERN_BOUNDARY | back to summary |
|---|---|
| private static final char SUBPATTERN_BOUNDARY Separates positive and negative subpatterns | |
| DefaultMonetaryAmountFormat | back to summary |
|---|---|
| pack-priv DefaultMonetaryAmountFormat(AmountFormatContext amountFormatContext) Creates a new instance.
| |
| format | back to summary |
|---|---|
| public String format(MonetaryAmount amount) Overrides default javax. Formats a value of
| |
| getContext | back to summary |
|---|---|
| public AmountFormatContext getContext() Implements javax. Doc from javax. The
| |
| getNumberPattern | back to summary |
|---|---|
| private String getNumberPattern(String token, DecimalFormat format) | |
| initPattern | back to summary |
|---|---|
| private List | |
| isCurrencyToken | back to summary |
|---|---|
| private boolean isCurrencyToken(String token) | |
| isNumberToken | back to summary |
|---|---|
| private boolean isNumberToken(String token) | |
| parse | back to summary |
|---|---|
| public MonetaryAmount parse(CharSequence text) throws MonetaryParseException Implements javax. Fully parses the text into an instance of 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.
| |
| back to summary | |
|---|---|
| public void print(Appendable appendable, MonetaryAmount amount) throws IOException Implements javax. Prints a item value to an
Example implementations of
| |
| queryFrom | back to summary |
|---|---|
| public String queryFrom(MonetaryAmount amount) Implements javax. Doc from javax. Queries the specified monetary amount. 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 // 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.
Implementation specificationThe implementation must take the input object and query it. The implementation defines the logic of the query and is responsible for documenting that logic. It may use any method onMonetaryAmount
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.
| |
| resolvePattern | back to summary |
|---|---|
| private String resolvePattern(AmountFormatContext amountFormatContext) | |
| setAmountFormatContext | back to summary |
|---|---|
| private void setAmountFormatContext(AmountFormatContext amountFormatContext) | |
| splitIntoPlusMinusPatterns | back to summary |
|---|---|
| private String[] splitIntoPlusMinusPatterns(AmountFormatContext amountFormatContext, String pattern) Split into (potential) plus, minus patterns | |
| splitNumberPattern | back to summary |
|---|---|
| private List Splits away the number pattern for targeting an AmountToken, if possible.
| |
| splitPatternForCurrency | back to summary |
|---|---|
| private List Splits the given pattern into a prefix, a currency token and a postfix token. | |
| tokenizePattern | back to summary |
|---|---|
| private List | |