Class 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.

    • Constructor Detail

      • NumberFormatterImpl

        public NumberFormatterImpl​(MacroProps macros)
        Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly.
    • Method Detail

      • 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.
      • preProcess

        public MicroProps preProcess​(DecimalQuantity inValue)
        Like format(), but saves the result into an output MicroProps without additional processing.
      • 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:
        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.