Top Description Fields Constructors Methods
org.javamoney.moneta.spi.format

pack-priv final Class CurrencyToken

extends Object
implements FormatToken
Class Inheritance
All Implemented Interfaces
org.javamoney.moneta.spi.format.FormatToken
Imports
org.javamoney.moneta.format.CurrencyStyle, javax.money.CurrencyUnit, .MonetaryAmount, .Monetary, javax.money.format.AmountFormatContext, .MonetaryParseException, java.io.IOException, java.util.Currency, .Locale, .Objects, .ResourceBundle, java.util.logging.Logger

Implements a FormatToken that adds a localizable String, read by key from a ResourceBundle.
Author
Anatole Tresch

Field Summary

Modifier and TypeField and Description
private final AmountFormatContext
context

The current conversion context.

private final Locale
locale

The target locale.

private CurrencyStyle
style

The style defining, how the currency should be localized.

Constructor Summary

AccessConstructor and Description
pack-priv
CurrencyToken(CurrencyStyle
The style defining, how the currency should be localized, not null.
style
,
AmountFormatContext
The target context, not null.
context
)

Creates a new CurrencyToken.

Method Summary

Modifier and TypeMethod and Description
private Currency

Returns:

the corresponding currency instance, or null.
getCurrency
(String
the currency code , not null.
currencyCode
)

Method to safely access a java.util.Currency.

private String

Returns:

the formatted currency name.
getCurrencyName
(CurrencyUnit
The currency, not null
currency
)

This method tries to evaluate the localized display name for a CurrencyUnit.

public CurrencyStyle

Returns:

the current CurrencyStyle, never null.
getCurrencyStyle
()

Access the CurrencyStyle used for formatting.

private String

Returns:

the formatted currency symbol.
getCurrencySymbol
(CurrencyUnit
The currency, not null
currency
)

This method tries to evaluate the localized symbol name for a CurrencyUnit.

private String

Returns:

the formatted currency.
getToken
(MonetaryAmount
the MonetaryAmount containing the CurrencyUnit to be formatted.
amount
)

Evaluate the formatted(localized) token.

public void
parse(ParseContext context)

Implements org.javamoney.moneta.spi.format.FormatToken.parse.

Parses a currency from the given ParseContext.

private String

Returns:

the first letter based part, or the full token.
parseCurrencyCode
(String
the input token
token
)

Tries to split up a letter based first part, e.g. for evaluating a ISO currency code from an input as 'CHF100.34'.

public CurrencyToken

Returns:

this token instance, for chaining.
setCurrencyStyle
(CurrencyStyle
the CurrencyStyle, not null.
style
)

Explicitly configure the CurrencyStyle to be used.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

contextback to summary
private final AmountFormatContext context

The current conversion context.

localeback to summary
private final Locale locale

The target locale.

styleback to summary
private CurrencyStyle style

The style defining, how the currency should be localized.

Constructor Detail

CurrencyTokenback to summary
pack-priv CurrencyToken(CurrencyStyle style, AmountFormatContext context)

Creates a new CurrencyToken.

Parameters
style:CurrencyStyle

The style defining, how the currency should be localized, not null.

context:AmountFormatContext

The target context, not null.

Method Detail

getCurrencyback to summary
private Currency getCurrency(String currencyCode)

Method to safely access a java.util.Currency. If no such currency exists, null is returned.

Parameters
currencyCode:String

the currency code , not null.

Returns:Currency

the corresponding currency instance, or null.

getCurrencyNameback to summary
private String getCurrencyName(CurrencyUnit currency)

This method tries to evaluate the localized display name for a CurrencyUnit. It uses Currency#getDisplayName(Locale) if the given currency code maps to a JDK Currency instance.

If not found currency.getCurrencyCode() is returned.

Parameters
currency:CurrencyUnit

The currency, not null

Returns:String

the formatted currency name.

getCurrencyStyleback to summary
public CurrencyStyle getCurrencyStyle()

Access the CurrencyStyle used for formatting.

Returns:CurrencyStyle

the current CurrencyStyle, never null.

getCurrencySymbolback to summary
private String getCurrencySymbol(CurrencyUnit currency)

This method tries to evaluate the localized symbol name for a CurrencyUnit. It uses Currency#getSymbol(Locale) if the given currency code maps to a JDK Currency instance.

If not found currency.getCurrencyCode() is returned.

Parameters
currency:CurrencyUnit

The currency, not null

Returns:String

the formatted currency symbol.

getTokenback to summary
private String getToken(MonetaryAmount amount)

Evaluate the formatted(localized) token.

Parameters
amount:MonetaryAmount

the MonetaryAmount containing the CurrencyUnit to be formatted.

Returns:String

the formatted currency.

parseback to summary
public void parse(ParseContext context) throws MonetaryParseException

Implements org.javamoney.moneta.spi.format.FormatToken.parse.

Parses a currency from the given ParseContext. Depending on the current CurrencyStyle it interprets the next non empty token, either as

  • currency code
  • currency symbol
Parsing of localized currency names or numeric code is not supported.
Annotations
@Override
Exceptions
MonetaryParseException:
on an error or if the CurrencyStyle is configured to non implemented currency name (NAME), or numeric codes (NUMERIC_CODE).
parseCurrencyCodeback to summary
private String parseCurrencyCode(String token)

Tries to split up a letter based first part, e.g. for evaluating a ISO currency code from an input as 'CHF100.34'.

Parameters
token:String

the input token

Returns:String

the first letter based part, or the full token.

setCurrencyStyleback to summary
public CurrencyToken setCurrencyStyle(CurrencyStyle style)

Explicitly configure the CurrencyStyle to be used.

Parameters
style:CurrencyStyle

the CurrencyStyle, not null.

Returns:CurrencyToken

this token instance, for chaining.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override