Class SplittingNumberFormatter
- All Implemented Interfaces:
Comparable<Handled>,Handled,NumberFormatter
A NumberFormatter that splits a number into multiple parts in order of magnitude and outputs them in a list.
The most common use case is formatting a period of time. A SplittingNumberFormatter.Split consists of a BigDecimal multiplier
and a singular and plural forms of a suffix. Splits are stored in an array and configured with SPLITS. The
array must have the splits in ascending order based on the multiplier, and the first split is recommended (but not
required) to be BigDecimal.ONE.
Each part of the output will be formatted by a different NumberFormatter which can be configured with
FORMATTER. The least significant part of the output can be in decimal form or rounded down, configured with
ROUND_SMALLEST. When formatting the parts either ConfigurationKeys.DELIMITER, or
ConfigurationKeys.LIST_DELIMITER and ConfigurationKeys.LIST_LAST_DELIMITER can be used, configured
with USE_LIST_DELIMITER.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefines a single part to be used withSplittingNumberFormatter. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConfigurationKey<Handle> Handleof theNumberFormatterto be used for the splits.static final ConfigurationKey<Boolean> Iftrue, the last split will be rounded down.static final ConfigurationKey<SplittingNumberFormatter.Split[]> Splitsto be used.static final SplittingNumberFormatter.Split[]Array ofSplitsfor formatting time with singular and plural names of different units of time, from seconds to years.static final SplittingNumberFormatter.Split[]Array ofSplitsfor formatting time with abbreviations of different units of time, from seconds to years.static final ConfigurationKey<Boolean> Iftrue,ConfigurationKeys.LIST_DELIMITERandConfigurationKeys.LIST_LAST_DELIMITERwill be used instead ofConfigurationKeys.DELIMITER. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat(BigDecimal number, TextFactory factory, TextConfiguration configuration)
-
Field Details
-
TIME_SHORT
Array ofSplitsfor formatting time with abbreviations of different units of time, from seconds to years. A month is assumed to be 30 days and a year is assumed to be 365 days. -
TIME_LONG
Array ofSplitsfor formatting time with singular and plural names of different units of time, from seconds to years. A month is assumed to be 30 days and a year is assumed to be 365 days. -
SPLITS
Splitsto be used. The elements must be in ascending order by the multiplier, and the first element is recommended to beBigDecimal.ONE. The default value isTIME_LONG. -
FORMATTER
-
ROUND_SMALLEST
Iftrue, the last split will be rounded down. The default value istrue. -
USE_LIST_DELIMITER
Iftrue,ConfigurationKeys.LIST_DELIMITERandConfigurationKeys.LIST_LAST_DELIMITERwill be used instead ofConfigurationKeys.DELIMITER. The default value istrue.
-
-
Constructor Details
-
SplittingNumberFormatter
- Parameters:
logger-Loggerfor this formatterhandles-TextHandlesto be used for this formatter'sHandle
-
-
Method Details
-
format
- Specified by:
formatin interfaceNumberFormatter- Parameters:
number- number to be formatterfactory-TextFactoryfor formattingconfiguration-TextConfigurationfor formatting- Returns:
Stringrepresentation of the number- Throws:
TextConfigurationException- if theTextConfigurationis not valid for this formatter
-