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

public Class MonetaryAmountDecimalFormat

extends Object
implements MonetaryAmountFormat
Class Inheritance
All Implemented Interfaces
javax.money.format.MonetaryAmountFormat, javax.money.MonetaryQuery
Static Imports
java.util.Objects.requireNonNull

The implementation that uses the DecimalFormat as formatter.
Author
Otavio Santana
Since
1.0.1

Field Summary

Modifier and TypeField and Description
private static final AmountFormatContext
private final CurrencyUnit
private final DecimalFormat
private static final MonetaryAmountFormat
private final MonetaryAmountProducer
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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

public AmountFormatContext
pack-priv CurrencyUnit
pack-priv DecimalFormat
pack-priv MonetaryAmountProducer
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public static MonetaryAmountFormat
of()

Get the default formatter based on the current default locale.

public MonetaryAmount
parse(CharSequence text)

Implements javax.money.format.MonetaryAmountFormat.parse.

Fully parses the text into an instance of MonetaryAmount.

public String
queryFrom(MonetaryAmount amount)

Implements javax.money.MonetaryQuery.queryFrom.

Queries the specified monetary amount.

public String
public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CONTEXTback to summary
private static final AmountFormatContext CONTEXT
currencyUnitback to summary
private final CurrencyUnit currencyUnit
decimalFormatback to summary
private final DecimalFormat decimalFormat
DEFAULT_INSTANCEback to summary
private static final MonetaryAmountFormat DEFAULT_INSTANCE
producerback to summary
private final MonetaryAmountProducer producer
STYLEback to summary
pack-priv static final String STYLE

Constructor Detail

MonetaryAmountDecimalFormatback to summary
public MonetaryAmountDecimalFormat(DecimalFormat decimalFormat, MonetaryAmountProducer producer, CurrencyUnit currencyUnit)

Method Detail

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 AmountFormatContext getContext()

Implements javax.money.format.MonetaryAmountFormat.getContext.

Doc from javax.money.format.MonetaryAmountFormat.getContext.

The AmountFormatContext to be applied when a MonetaryAmount is formatted.

Annotations
@Override
getCurrencyUnitback to summary
pack-priv CurrencyUnit getCurrencyUnit()
getDecimalFormatback to summary
pack-priv DecimalFormat getDecimalFormat()
getProducerback to summary
pack-priv MonetaryAmountProducer getProducer()
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
ofback to summary
public static MonetaryAmountFormat of()

Get the default formatter based on the current default locale.

parseback to summary
public MonetaryAmount parse(CharSequence text) throws MonetaryParseException

Implements javax.money.format.MonetaryAmountFormat.parse.

Doc from javax.money.format.MonetaryAmountFormat.parse.

Fully parses the text into an instance of MonetaryAmount.

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.

Additionally the effective implementation type returned can be determined by the MonetaryContext applied to the MonetaryAmountFormat. This formatter will call javax.money.Monetary#getDefaultAmountType() and will use the result returned to access a corresponding javax.money.MonetaryAmountFactory to of the instance returned.

Annotations
@Override
Exceptions
MonetaryParseException:
if there is a problem while parsing
queryFromback to summary
public String queryFrom(MonetaryAmount amount)

Implements javax.money.MonetaryQuery.queryFrom.

Doc from javax.money.MonetaryQuery.queryFrom.

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 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.

Implementation specification

The 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 on 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.

Annotations
@Override
toLocalizedPatternback to summary
public String toLocalizedPattern()
toPatternback to summary
public String toPattern()
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