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 MicroPropsformatStatic(MacroProps macros, DecimalQuantity inValue, FormattedStringBuilder outString) Builds and evaluates an "unsafe" MicroPropsGenerator, which is cheaper but can be used only once.intgetPrefixSuffix(byte signum, StandardPlural plural, FormattedStringBuilder output) private static intgetPrefixSuffixImpl(MicroPropsGenerator generator, byte signum, FormattedStringBuilder output) static intgetPrefixSuffixStatic(MacroProps macros, byte signum, StandardPlural plural, FormattedStringBuilder output) Prints only the prefix and suffix; used for DecimalFormat getters.private static MicroPropsGeneratormacrosToMicroGenerator(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 MicroPropspreProcessUnsafe(MacroProps macros, DecimalQuantity inValue) private static booleanunitIsBaseUnit(MeasureUnit unit) private static booleanunitIsCurrency(MeasureUnit unit) ///////private static booleanunitIsPercent(MeasureUnit unit) private static booleanunitIsPermille(MeasureUnit unit) static intwriteAffixes(MicroProps micros, FormattedStringBuilder string, int start, int end) Adds the affixes.private static intwriteFractionDigits(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) private static intwriteIntegerDigits(MicroProps micros, DecimalQuantity quantity, FormattedStringBuilder string, int index) static intwriteNumber(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- TheMacroPropsto 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)
-