Class NumberFormatterImpl

java.lang.Object
com.ibm.icu.number.NumberFormatterImpl

class NumberFormatterImpl extends 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 Details

  • Constructor Details

    • NumberFormatterImpl

      public NumberFormatterImpl(MacroProps macros)
      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

      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 - The MacroProps 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)