Package com.ibm.icu.number
Class NumberFormatterImpl
java.lang.Object
com.ibm.icu.number.NumberFormatterImpl
This is the "brain" of the number formatting pipeline. It ties all the pieces together, taking in a
MacroProps and a DecimalQuantity and outputting a properly formatted number string.
This class, as well as NumberPropertyMapper, could go into the impl package, but they depend on too many package-private members of the public APIs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Currency
(package private) final MicroPropsGenerator
(package private) final MicroProps
-
Constructor Summary
ConstructorsConstructorDescriptionNumberFormatterImpl
(MacroProps macros) Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly. -
Method Summary
Modifier and TypeMethodDescriptionformat
(DecimalQuantity inValue, FormattedStringBuilder outString) Evaluates the "safe" MicroPropsGenerator created by "fromMacros".static MicroProps
formatStatic
(MacroProps macros, DecimalQuantity inValue, FormattedStringBuilder outString) Builds and evaluates an "unsafe" MicroPropsGenerator, which is cheaper but can be used only once.int
getPrefixSuffix
(byte signum, StandardPlural plural, FormattedStringBuilder output) private static int
getPrefixSuffixImpl
(MicroPropsGenerator generator, byte signum, FormattedStringBuilder output) static int
getPrefixSuffixStatic
(MacroProps macros, byte signum, StandardPlural plural, FormattedStringBuilder output) Prints only the prefix and suffix; used for DecimalFormat getters.private static MicroPropsGenerator
macrosToMicroGenerator
(MacroProps macros, MicroProps micros, boolean safe) Synthesizes the MacroProps into a MicroPropsGenerator.preProcess
(DecimalQuantity inValue) Like format(), but saves the result into an output MicroProps without additional processing.private static MicroProps
preProcessUnsafe
(MacroProps macros, DecimalQuantity inValue) private static boolean
unitIsBaseUnit
(MeasureUnit unit) private static boolean
unitIsCurrency
(MeasureUnit unit) private static boolean
unitIsPercent
(MeasureUnit unit) private static boolean
unitIsPermille
(MeasureUnit unit) static int
writeAffixes
(MicroProps micros, FormattedStringBuilder string, int start, int end) Adds the affixes.private static int
writeFractionDigits
(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) private static int
writeIntegerDigits
(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) static int
writeNumber
(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) Synthesizes the output string from a MicroProps and DecimalQuantity.
-
Field Details
-
DEFAULT_CURRENCY
-
micros
-
microPropsGenerator
-
-
Constructor Details
-
NumberFormatterImpl
Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly.
-
-
Method Details
-
formatStatic
public static MicroProps formatStatic(MacroProps macros, DecimalQuantity inValue, FormattedStringBuilder outString) Builds and evaluates an "unsafe" MicroPropsGenerator, which is cheaper but can be used only once. -
getPrefixSuffixStatic
public static int getPrefixSuffixStatic(MacroProps macros, byte signum, StandardPlural plural, FormattedStringBuilder output) Prints only the prefix and suffix; used for DecimalFormat getters.- Returns:
- The index into the output at which the prefix ends and the suffix starts; in other words, the prefix length.
-
format
Evaluates the "safe" MicroPropsGenerator created by "fromMacros". -
preProcess
Like format(), but saves the result into an output MicroProps without additional processing. -
preProcessUnsafe
-
getPrefixSuffix
-
getPrefixSuffixImpl
private static int getPrefixSuffixImpl(MicroPropsGenerator generator, byte signum, FormattedStringBuilder output) -
getRawMicroProps
-
unitIsCurrency
-
unitIsBaseUnit
-
unitIsPercent
-
unitIsPermille
-
macrosToMicroGenerator
private static MicroPropsGenerator macrosToMicroGenerator(MacroProps macros, MicroProps micros, boolean safe) Synthesizes the MacroProps into a MicroPropsGenerator. All information, including the locale, is encoded into the MicroPropsGenerator, except for the quantity itself, which is left abstract and must be provided to the returned MicroPropsGenerator instance.- Parameters:
macros
- TheMacroProps
to consume. This method does not mutate the MacroProps instance.safe
- If true, the returned MicroPropsGenerator will be thread-safe. If false, the returned value will not be thread-safe, intended for a single "one-shot" use only. Building the thread-safe object is more expensive.- See Also:
-
writeAffixes
public static int writeAffixes(MicroProps micros, FormattedStringBuilder string, int start, int end) Adds the affixes. Intended to be called immediately after formatNumber. -
writeNumber
public static int writeNumber(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) Synthesizes the output string from a MicroProps and DecimalQuantity. This method formats only the main number, not affixes. -
writeIntegerDigits
private static int writeIntegerDigits(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) -
writeFractionDigits
private static int writeFractionDigits(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index)
-