- All Implemented Interfaces:
Serializable
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a dot.static final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal comma and groups large amounts in 3's using a space.static final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.static final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a comma.static final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal point and groups large amounts in 3's using a space.static final MoneyAmountStyle
A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts.static final MoneyAmountStyle
A style that will be filled in with localized values using the locale of the formatter.static final MoneyAmountStyle
A style that will be filled in with localized values using the locale of the formatter. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares this style with another.Gets the character used for the decimal point.Gets the size of each group, not typically used.Gets the character used to separate groups, typically thousands.Gets the size of each group, typically 3 for thousands.Gets the style of grouping required.Gets the character used for the negative sign character.Gets the character used for the positive sign character.Gets the character used for zero, and defining the characters zero to nine.int
hashCode()
A suitable hash code.boolean
Returns true if the absolute value setting.boolean
Gets whether to always use the decimal point, even if there is no fraction.Returns aMoneyAmountStyle
instance configured for the specified locale.static MoneyAmountStyle
Gets a localized style.toString()
Gets a string summary of the style.withAbsValue
(boolean absValue) Returns a copy of this style with the specified absolute value setting.withDecimalPointCharacter
(Character decimalPointCharacter) Returns a copy of this style with the specified decimal point character.withExtendedGroupingSize
(Integer extendedGroupingSize) Returns a copy of this style with the specified extended grouping size.withForcedDecimalPoint
(boolean forceDecimalPoint) Returns a copy of this style with the specified decimal point setting.withGroupingCharacter
(Character groupingCharacter) Returns a copy of this style with the specified grouping character.withGroupingSize
(Integer groupingSize) Returns a copy of this style with the specified grouping size.withGroupingStyle
(GroupingStyle groupingStyle) Returns a copy of this style with the specified grouping setting.withNegativeSignCharacter
(Character negativeCharacter) Returns a copy of this style with the specified negative sign character.withPositiveSignCharacter
(Character positiveCharacter) Returns a copy of this style with the specified positive sign character.withZeroCharacter
(Character zeroCharacter) Returns a copy of this style with the specified zero character.
-
Field Details
-
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
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
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
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
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
A style that uses ASCII digits/negative sign, the decimal point and no grouping of large amounts. Forced decimal point is disabled. -
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
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 Details
-
of
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
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
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
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
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
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
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
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
Gets the character used for the decimal point.- Returns:
- the decimal point character, null if to be determined by locale
-
withDecimalPointCharacter
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
Gets the character used to separate groups, typically thousands.- Returns:
- the grouping character, null if to be determined by locale
-
withGroupingCharacter
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
Gets the size of each group, typically 3 for thousands.- Returns:
- the size of each group, null if to be determined by locale
-
withGroupingSize
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
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
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
Gets the style of grouping required.- Returns:
- the grouping style, not null
-
withGroupingStyle
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
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
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
Compares this style with another. -
hashCode
public int hashCode()A suitable hash code. -
toString
Gets a string summary of the style.
-