Class LongNameHandler

    • Field Detail

      • i

        private static int i
      • DNAM_INDEX

        private static final int DNAM_INDEX
      • PER_INDEX

        private static final int PER_INDEX
      • GENDER_INDEX

        private static final int GENDER_INDEX
      • ARRAY_LENGTH

        static final int ARRAY_LENGTH
      • gender

        private java.lang.String gender
    • Method Detail

      • getIndex

        private static int getIndex​(java.lang.String pluralKeyword)
      • getWithPlural

        static java.lang.String getWithPlural​(java.lang.String[] strings,
                                              StandardPlural plural)
      • extractCorePattern

        private static LongNameHandler.ExtractCorePatternResult extractCorePattern​(java.lang.String pattern)
        Returns three outputs extracted from pattern.
        Parameters:
        coreUnit - is extracted as per Extract(...) in the spec: https://unicode.org/reports/tr35/tr35-general.html#compound-units
        PlaceholderPosition - indicates where in the string the placeholder was found.
        joinerChar - Iff the placeholder was at the beginning or end, joinerChar contains the space character (if any) that separated the placeholder from the rest of the pattern. Otherwise, joinerChar is set to NUL. Only one space character is considered.
      • getGenderForBuiltin

        private static java.lang.String getGenderForBuiltin​(ULocale locale,
                                                            MeasureUnit builtinUnit)
      • getInflectedMeasureData

        static void getInflectedMeasureData​(java.lang.String subKey,
                                            ULocale locale,
                                            NumberFormatter.UnitWidth width,
                                            java.lang.String gender,
                                            java.lang.String caseVariant,
                                            java.lang.String[] outArray)
      • getCurrencyLongNameData

        private static void getCurrencyLongNameData​(ULocale locale,
                                                    Currency currency,
                                                    java.lang.String[] outArray)
      • getDeriveCompoundRule

        private static java.lang.String getDeriveCompoundRule​(ULocale locale,
                                                              java.lang.String feature,
                                                              java.lang.String structure)
        Loads and returns the value in rules that look like these: Currently a fake example, but spec compliant: NOTE: If U_FAILURE(status), returns an empty string.
      • getDerivedGender

        private static java.lang.String getDerivedGender​(ULocale locale,
                                                         java.lang.String structure,
                                                         java.lang.String[] data0,
                                                         java.lang.String[] data1)
      • calculateGenderForUnit

        private static java.lang.String calculateGenderForUnit​(ULocale locale,
                                                               MeasureUnit unit)
        Calculates the gender of an arbitrary unit: this is the *second* implementation of an algorithm to do this: Gender is also calculated in "processPatternTimes": that code path is "bottom up", loading the gender for every component of a compound unit (at the same time as loading the Long Names formatting patterns), even if the gender is unneeded, then combining the single units' genders into the compound unit's gender, according to the rules. This algorithm does a lazier "top-down" evaluation, starting with the compound unit, calculating which single unit's gender is needed by breaking it down according to the rules, and then loading only the gender of the one single unit who's gender is needed. For future refactorings: 1. we could drop processPatternTimes' gender calculation and just call this function: for UNUM_UNIT_WIDTH_FULL_NAME, the unit gender is in the very same table as the formatting patterns, so loading it then may be efficient. For other unit widths however, it needs to be explicitly looked up anyway. 2. alternatively, if CLDR is providing all the genders we need such that we don't need to calculate them in ICU anymore, we could drop this function and keep only processPatternTimes' calculation. (And optimise it a bit?)
        Parameters:
        locale - The desired locale.
        unit - The measure unit to calculate the gender for.
        Returns:
        The gender string for the unit, or an empty string if unknown or ungendered.
      • maybeCalculateGender

        private static void maybeCalculateGender​(ULocale locale,
                                                 MeasureUnit unit,
                                                 java.lang.String[] outArray)
      • forMeasureUnit

        public static LongNameHandler forMeasureUnit​(ULocale locale,
                                                     MeasureUnit unit,
                                                     NumberFormatter.UnitWidth width,
                                                     java.lang.String unitDisplayCase,
                                                     PluralRules rules,
                                                     MicroPropsGenerator parent)
        Construct a localized LongNameHandler for the specified MeasureUnit.

        Mixed units are not supported, use MixedUnitLongNameHandler.forMeasureUnit.

        Parameters:
        locale - The desired locale.
        unit - The measure unit to construct a LongNameHandler for.
        width - Specifies the desired unit rendering.
        unitDisplayCase - Specifies the desired grammatical case. If the specified case is not found, we fall back to nominative or no-case.
        rules - Plural rules.
        parent - Plural rules.
      • processPatternTimes

        private static void processPatternTimes​(MeasureUnitImpl productUnit,
                                                ULocale loc,
                                                NumberFormatter.UnitWidth width,
                                                java.lang.String caseVariant,
                                                java.lang.String[] outArray)
        Roughly corresponds to patternTimes(...) in the spec: https://unicode.org/reports/tr35/tr35-general.html#compound-units
      • simpleFormatsToModifiers

        private void simpleFormatsToModifiers​(java.lang.String[] simpleFormats,
                                              NumberFormat.Field field)
        Sets modifiers to use the patterns from simpleFormats.
      • multiSimpleFormatsToModifiers

        private void multiSimpleFormatsToModifiers​(java.lang.String[] leadFormats,
                                                   java.lang.String trailFormat,
                                                   NumberFormat.Field field)
        Sets modifiers to a combination of leadFormats (one per plural form) and trailFormat appended to each. With a leadFormat of "{0}m" and a trailFormat of "{0}/s", it produces a pattern of "{0}m/s" by inserting each leadFormat pattern into trailFormat.