- java.lang.Object
-
- 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:
- character used for zero, which defined all the numbers from zero to nine
- character used for positive and negative symbols
- character used for the decimal point
- whether and how to group the amount
- character used for grouping, such as grouping thousands
- size for each group, such as 3 for thousands
- whether to always use a decimal point
The style can be used in three basic ways.
- set all the fields manually, resulting in the same amount style for all locales
- call
localize(java.util.Locale)
manually and optionally adjust to set as required - leave the localized fields as
null
and let the locale in the formatter to determine the style
This class is immutable and thread-safe.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
Compares this style with another.Character
getDecimalPointCharacter()
Gets the character used for the decimal point.Integer
getExtendedGroupingSize()
Gets the size of each group, not typically used.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
isAbsValue()
Returns true if the absolute value setting.boolean
isForcedDecimalPoint()
Gets whether to always use the decimal point, even if there is no fraction.MoneyAmountStyle
localize(Locale locale)
Returns aMoneyAmountStyle
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
withAbsValue(boolean absValue)
Returns a copy of this style with the specified absolute value setting.MoneyAmountStyle
withDecimalPointCharacter(Character decimalPointCharacter)
Returns a copy of this style with the specified decimal point character.MoneyAmountStyle
withExtendedGroupingSize(Integer extendedGroupingSize)
Returns a copy of this style with the specified extended grouping size.MoneyAmountStyle
withForcedDecimalPoint(boolean forceDecimalPoint)
Returns a copy of this style with the specified decimal point setting.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.
-
-
-
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, absolute values will be disabled.
- Parameters:
locale
- the locale to use, not null- Returns:
- the new instance, never null
-
localize
public MoneyAmountStyle localize(Locale locale)
Returns aMoneyAmountStyle
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
andDecimalFormat
.- 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
-
getExtendedGroupingSize
public Integer getExtendedGroupingSize()
Gets the size of each group, not typically used.This is primarily used to enable the Indian Number System, where the group closest to the decimal point is of size 3 and other groups are of size 2. The extended grouping size is used for groups that are not next to the decimal point. The value zero is used to indicate that extended grouping is not needed.
- Returns:
- the size of each group, null if to be determined by locale
-
withExtendedGroupingSize
public MoneyAmountStyle withExtendedGroupingSize(Integer extendedGroupingSize)
Returns a copy of this style with the specified extended grouping size.- Parameters:
extendedGroupingSize
- 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
-
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
-
isAbsValue
public boolean isAbsValue()
Returns true if the absolute value setting.If this is set to true, the absolute (unsigned) value will be output. If this is set to false, the signed value will be output. Note that when parsing, signs are accepted.
- Returns:
- true to output the absolute value, false for the signed value
-
withAbsValue
public MoneyAmountStyle withAbsValue(boolean absValue)
Returns a copy of this style with the specified absolute value setting.If this is set to true, the absolute (unsigned) value will be output. If this is set to false, the signed value will be output. Note that when parsing, signs are accepted.
- Parameters:
absValue
- true to output the absolute value, false for the signed value- Returns:
- the new instance for chaining, never null
-
equals
public boolean equals(Object other)
Compares this style with another.
-
hashCode
public int hashCode()
A suitable hash code.
-
-