org.joda.money.format
Class MoneyAmountStyle

java.lang.Object
  extended by org.joda.money.format.MoneyAmountStyle
All Implemented Interfaces:
Serializable

public final class MoneyAmountStyle
extends Object
implements Serializable

Defines the style that the amount of a monetary value will be formatted with.

The style contains a number of fields that may be configured based on the locale:

The style can be used in three basic ways.

This class is immutable and thread-safe.

See Also:
Serialized Form

Field Summary
static MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_DOT
          A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a dot.
static MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_SPACE
          A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a space.
static MoneyAmountStyle ASCII_DECIMAL_COMMA_NO_GROUPING
          A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.
static MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_COMMA
          A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a comma.
static MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_SPACE
          A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a space.
static MoneyAmountStyle ASCII_DECIMAL_POINT_NO_GROUPING
          A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.
static MoneyAmountStyle LOCALIZED_GROUPING
          A style that will be filled in with localized values using the locale of the formatter.
static MoneyAmountStyle LOCALIZED_NO_GROUPING
          A style that will be filled in with localized values using the locale of the formatter.
 
Method Summary
 boolean equals(Object other)
          Compares this style with another.
 Character getDecimalPointCharacter()
          Gets the character used for the decimal point.
 Character getGroupingCharacter()
          Gets the character used to separate groups, typically thousands.
 Integer getGroupingSize()
          Gets the size of each group, typically 3 for thousands.
 GroupingStyle getGroupingStyle()
          Gets the style of grouping required.
 Character getNegativeSignCharacter()
          Gets the character used for the negative sign character.
 Character getPositiveSignCharacter()
          Gets the character used for the positive sign character.
 Character getZeroCharacter()
          Gets the character used for zero, and defining the characters zero to nine.
 int hashCode()
          A suitable hash code.
 boolean isForcedDecimalPoint()
          Gets whether to always use the decimal point, even if there is no fraction.
 boolean isGrouping()
          Deprecated. Use getGroupingStyle()
 MoneyAmountStyle localize(Locale locale)
          Returns a MoneyAmountStyle instance configured for the specified locale.
static MoneyAmountStyle of(Locale locale)
          Gets a localized style.
 String toString()
          Gets a string summary of the style.
 MoneyAmountStyle withDecimalPointCharacter(Character decimalPointCharacter)
          Returns a copy of this style with the specified decimal point character.
 MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint)
          Returns a copy of this style with the specified decimal point setting.
 MoneyAmountStyle withGrouping(boolean grouping)
          Deprecated. Use withGroupingStyle(GroupingStyle.FULL)
 MoneyAmountStyle withGroupingCharacter(Character groupingCharacter)
          Returns a copy of this style with the specified grouping character.
 MoneyAmountStyle withGroupingSize(Integer groupingSize)
          Returns a copy of this style with the specified grouping size.
 MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle)
          Returns a copy of this style with the specified grouping setting.
 MoneyAmountStyle withNegativeSignCharacter(Character negativeCharacter)
          Returns a copy of this style with the specified negative sign character.
 MoneyAmountStyle withPositiveSignCharacter(Character positiveCharacter)
          Returns a copy of this style with the specified positive sign character.
 MoneyAmountStyle withZeroCharacter(Character zeroCharacter)
          Returns a copy of this style with the specified zero character.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ASCII_DECIMAL_POINT_GROUP3_COMMA

public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_COMMA
A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a comma. Forced decimal point is disabled.


ASCII_DECIMAL_POINT_GROUP3_SPACE

public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_SPACE
A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a space. Forced decimal point is disabled.


ASCII_DECIMAL_POINT_NO_GROUPING

public static final MoneyAmountStyle ASCII_DECIMAL_POINT_NO_GROUPING
A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts. Forced decimal point is disabled.


ASCII_DECIMAL_COMMA_GROUP3_DOT

public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_DOT
A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a dot. Forced decimal point is disabled.


ASCII_DECIMAL_COMMA_GROUP3_SPACE

public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_SPACE
A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a space. Forced decimal point is disabled.


ASCII_DECIMAL_COMMA_NO_GROUPING

public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_NO_GROUPING
A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts. Forced decimal point is disabled.


LOCALIZED_GROUPING

public static final MoneyAmountStyle LOCALIZED_GROUPING
A style that will be filled in with localized values using the locale of the formatter. Grouping is enabled. Forced decimal point is disabled.


LOCALIZED_NO_GROUPING

public static final MoneyAmountStyle LOCALIZED_NO_GROUPING
A style that will be filled in with localized values using the locale of the formatter. Grouping is disabled. Forced decimal point is disabled.

Method Detail

of

public static MoneyAmountStyle of(Locale locale)
Gets a localized style.

This creates a localized style for the specified locale. Grouping will be enabled, forced decimal point will be disabled.

Parameters:
locale - the locale to use, not null
Returns:
the new instance, never null

localize

public MoneyAmountStyle localize(Locale locale)
Returns a MoneyAmountStyle instance configured for the specified locale.

This method will return a new instance where each field that was defined to be localized (by being set to null) is filled in. If this instance is fully defined (with all fields non-null), then this method has no effect. Once this method is called, no method will return null.

The settings for the locale are pulled from DecimalFormatSymbols and DecimalFormat.

Parameters:
locale - the locale to use, not null
Returns:
the new instance for chaining, never null

getZeroCharacter

public Character getZeroCharacter()
Gets the character used for zero, and defining the characters zero to nine.

The UTF-8 standard supports a number of different numeric scripts. Each script has the characters in order from zero to nine. This method returns the zero character, which therefore also defines one to nine.

Returns:
the zero character, null if to be determined by locale

withZeroCharacter

public MoneyAmountStyle withZeroCharacter(Character zeroCharacter)
Returns a copy of this style with the specified zero character.

The UTF-8 standard supports a number of different numeric scripts. Each script has the characters in order from zero to nine. This method sets the zero character, which therefore also defines one to nine.

For English, this is a '0'. Some other scripts use different characters for the numbers zero to nine.

Parameters:
zeroCharacter - the zero character, null if to be determined by locale
Returns:
the new instance for chaining, never null

getPositiveSignCharacter

public Character getPositiveSignCharacter()
Gets the character used for the positive sign character.

The standard ASCII symbol is '+'.

Returns:
the format for positive amounts, null if to be determined by locale

withPositiveSignCharacter

public MoneyAmountStyle withPositiveSignCharacter(Character positiveCharacter)
Returns a copy of this style with the specified positive sign character.

The standard ASCII symbol is '+'.

Parameters:
positiveCharacter - the positive character, null if to be determined by locale
Returns:
the new instance for chaining, never null

getNegativeSignCharacter

public Character getNegativeSignCharacter()
Gets the character used for the negative sign character.

The standard ASCII symbol is '-'.

Returns:
the format for negative amounts, null if to be determined by locale

withNegativeSignCharacter

public MoneyAmountStyle withNegativeSignCharacter(Character negativeCharacter)
Returns a copy of this style with the specified negative sign character.

The standard ASCII symbol is '-'.

Parameters:
negativeCharacter - the negative character, null if to be determined by locale
Returns:
the new instance for chaining, never null

getDecimalPointCharacter

public Character getDecimalPointCharacter()
Gets the character used for the decimal point.

Returns:
the decimal point character, null if to be determined by locale

withDecimalPointCharacter

public MoneyAmountStyle withDecimalPointCharacter(Character decimalPointCharacter)
Returns a copy of this style with the specified decimal point character.

For English, this is a dot.

Parameters:
decimalPointCharacter - the decimal point character, null if to be determined by locale
Returns:
the new instance for chaining, never null

getGroupingCharacter

public Character getGroupingCharacter()
Gets the character used to separate groups, typically thousands.

Returns:
the grouping character, null if to be determined by locale

withGroupingCharacter

public MoneyAmountStyle withGroupingCharacter(Character groupingCharacter)
Returns a copy of this style with the specified grouping character.

For English, this is a comma.

Parameters:
groupingCharacter - the grouping character, null if to be determined by locale
Returns:
the new instance for chaining, never null

getGroupingSize

public Integer getGroupingSize()
Gets the size of each group, typically 3 for thousands.

Returns:
the size of each group, null if to be determined by locale

withGroupingSize

public MoneyAmountStyle withGroupingSize(Integer groupingSize)
Returns a copy of this style with the specified grouping size.

Parameters:
groupingSize - the size of each group, such as 3 for thousands, not zero or negative, null if to be determined by locale
Returns:
the new instance for chaining, never null
Throws:
IllegalArgumentException - if the grouping size is zero or less

isGrouping

@Deprecated
public boolean isGrouping()
Deprecated. Use getGroupingStyle()

Gets whether to use the grouping separator, typically for thousands.

Returns:
whether to use the grouping separator

withGrouping

@Deprecated
public MoneyAmountStyle withGrouping(boolean grouping)
Deprecated. Use withGroupingStyle(GroupingStyle.FULL)

Returns a copy of this style with the specified grouping setting.

Parameters:
grouping - true to use the grouping separator, false to not use it
Returns:
the new instance for chaining, never null

getGroupingStyle

public GroupingStyle getGroupingStyle()
Gets the style of grouping required.

Returns:
the grouping style, not null

withGroupingStyle

public MoneyAmountStyle withGroupingStyle(GroupingStyle groupingStyle)
Returns a copy of this style with the specified grouping setting.

Parameters:
groupingStyle - the grouping style, not null
Returns:
the new instance for chaining, never null

isForcedDecimalPoint

public boolean isForcedDecimalPoint()
Gets whether to always use the decimal point, even if there is no fraction.

Returns:
whether to force the decimal point on output

withForcedDecimalPoint

public MoneyAmountStyle withForcedDecimalPoint(boolean forceDecimalPoint)
Returns a copy of this style with the specified decimal point setting.

Parameters:
forceDecimalPoint - true to force the use of the decimal point, false to use it if required
Returns:
the new instance for chaining, never null

equals

public boolean equals(Object other)
Compares this style with another.

Overrides:
equals in class Object
Parameters:
other - the other style, null returns false
Returns:
true if equal

hashCode

public int hashCode()
A suitable hash code.

Overrides:
hashCode in class Object
Returns:
a hash code

toString

public String toString()
Gets a string summary of the style.

Overrides:
toString in class Object
Returns:
a string summarising the style, never null


Copyright © 2009–2013 Joda.org. All rights reserved.