Package com.ibm.icu.number
Class NumberFormatterImpl
- java.lang.Object
-
- com.ibm.icu.number.NumberFormatterImpl
-
class NumberFormatterImpl extends java.lang.Object
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
Fields Modifier and Type Field Description private static Currency
DEFAULT_CURRENCY
(package private) MicroPropsGenerator
microPropsGenerator
(package private) MicroProps
micros
-
Constructor Summary
Constructors Constructor Description NumberFormatterImpl(MacroProps macros)
Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MicroProps
format(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.MicroProps
getRawMicroProps()
private static MicroPropsGenerator
macrosToMicroGenerator(MacroProps macros, MicroProps micros, boolean safe)
Synthesizes the MacroProps into a MicroPropsGenerator.MicroProps
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 Detail
-
DEFAULT_CURRENCY
private static final Currency DEFAULT_CURRENCY
-
micros
final MicroProps micros
-
microPropsGenerator
final MicroPropsGenerator microPropsGenerator
-
-
Constructor Detail
-
NumberFormatterImpl
public NumberFormatterImpl(MacroProps macros)
Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly.
-
-
Method Detail
-
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
public MicroProps format(DecimalQuantity inValue, FormattedStringBuilder outString)
Evaluates the "safe" MicroPropsGenerator created by "fromMacros".
-
preProcess
public MicroProps preProcess(DecimalQuantity inValue)
Like format(), but saves the result into an output MicroProps without additional processing.
-
preProcessUnsafe
private static MicroProps preProcessUnsafe(MacroProps macros, DecimalQuantity inValue)
-
getPrefixSuffix
public int getPrefixSuffix(byte signum, StandardPlural plural, FormattedStringBuilder output)
-
getPrefixSuffixImpl
private static int getPrefixSuffixImpl(MicroPropsGenerator generator, byte signum, FormattedStringBuilder output)
-
getRawMicroProps
public MicroProps getRawMicroProps()
-
unitIsCurrency
private static boolean unitIsCurrency(MeasureUnit unit)
-
unitIsBaseUnit
private static boolean unitIsBaseUnit(MeasureUnit unit)
-
unitIsPercent
private static boolean unitIsPercent(MeasureUnit unit)
-
unitIsPermille
private static boolean unitIsPermille(MeasureUnit unit)
-
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:
MicroPropsGenerator
-
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)
-
-