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

public final Class JDKCurrencyAdapter

extends Object
implements CurrencyUnit, Serializable, Comparable<CurrencyUnit>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.io.Serializable, javax.money.CurrencyUnit
Imports
java.io.Serializable, java.util.Currency, .Objects, javax.money.CurrencyContext, .CurrencyContextBuilder, .CurrencyUnit

Default implementation of a CurrencyUnit based on the using the JDK's Currency.
Authors
Anatole Tresch, Werner Keil
Version
1.0

Field Summary

Modifier and TypeField and Description
private final Currency
baseCurrency

JDK currency instance.

private final CurrencyContext
private static final long
serialVersionUID

serialVersionUID.

Constructor Summary

AccessConstructor and Description
pack-priv
JDKCurrencyAdapter(Currency
the Currency instance, not null.
currency
)

Private constructor, uses a java.util.Currency for creating new instances.

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(CurrencyUnit
The instance to be compared with.
currency
)

Implements java.lang.Comparable.compareTo.

Compares two instances, based on getCurrencyCode().

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public CurrencyContext
public String

Returns:

the currency code, never null. For ISO-4217 this this will be the three letter ISO-4217 code. However, alternate currencies can have different codes. Also there is no constraint about the formatting of alternate codes, despite they fact that the currency codes must be unique.
getCurrencyCode
()

Implements javax.money.CurrencyUnit.getCurrencyCode.

Gets the unique currency code, the effective code depends on the currency.

public int

Returns:

the fractional digits, from 0 to 9 (normally 0, 2 or 3), or 0 for pseudo-currencies.
getDefaultFractionDigits
()

Implements javax.money.CurrencyUnit.getDefaultFractionDigits.

Gets the number of fractional digits typically used by this currency.

public int

Returns:

the numeric currency code
getNumericCode
()

Implements javax.money.CurrencyUnit.getNumericCode.

Gets a numeric currency code.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

baseCurrencyback to summary
private final Currency baseCurrency

JDK currency instance.

contextback to summary
private final CurrencyContext context
serialVersionUIDback to summary
private static final long serialVersionUID

serialVersionUID.

Constructor Detail

JDKCurrencyAdapterback to summary
pack-priv JDKCurrencyAdapter(Currency currency)

Private constructor, uses a java.util.Currency for creating new instances.

Parameters
currency:Currency

the Currency instance, not null.

Method Detail

compareToback to summary
public int compareTo(CurrencyUnit currency)

Implements java.lang.Comparable.compareTo.

Compares two instances, based on getCurrencyCode().

Parameters
currency:CurrencyUnit

The instance to be compared with.

Annotations
@Override
See Also
java.lang.Comparable#compareTo(java.lang.Object)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getContextback to summary
public CurrencyContext getContext()

Implements javax.money.CurrencyUnit.getContext.

Doc from javax.money.CurrencyUnit.getContext.

Returns the javax.money.CurrencyContext of a currency. This context contains additional information about the type and capabilities of a CurrencyUnit, e.g. its provider and more.

Annotations
@Override
getCurrencyCodeback to summary
public String getCurrencyCode()

Implements javax.money.CurrencyUnit.getCurrencyCode.

Gets the unique currency code, the effective code depends on the currency.

Since each currency is identified by this code, the currency code is required to be defined for every CurrencyUnit and not null or empty.

For ISO codes the 3-letter ISO code should be returned. For non ISO currencies no constraints are defined.

Returns:String

the currency code, never null. For ISO-4217 this this will be the three letter ISO-4217 code. However, alternate currencies can have different codes. Also there is no constraint about the formatting of alternate codes, despite they fact that the currency codes must be unique.

See Also
javax.money.CurrencyUnit#getCurrencyCode()
getDefaultFractionDigitsback to summary
public int getDefaultFractionDigits()

Implements javax.money.CurrencyUnit.getDefaultFractionDigits.

Gets the number of fractional digits typically used by this currency.

Different currencies have different numbers of fractional digits by default. * For example, 'GBP' has 2 fractional digits, but 'JPY' has zero. * virtual currencies or those with no applicable fractional are indicated by -1. *

This method matches the API of java.util.Currency.

Returns:int

the fractional digits, from 0 to 9 (normally 0, 2 or 3), or 0 for pseudo-currencies.

getNumericCodeback to summary
public int getNumericCode()

Implements javax.money.CurrencyUnit.getNumericCode.

Gets a numeric currency code. Within the ISO-4217 name space, this equals to the ISO numeric code. In other currency name spaces this number may be different, or even undefined (-1).

The numeric code is an optional alternative to the standard currency code. If defined, the numeric code is required to be unique.

This method matches the API of java.util.Currency.

Returns:int

the numeric currency code

See Also
CurrencyUnit#getNumericCode()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns getCurrencyCode()

Annotations
@Override
See Also
java.lang.Object#toString()