Class LongNameHandler

java.lang.Object
com.ibm.icu.impl.number.LongNameHandler
All Implemented Interfaces:
LongNameMultiplexer.ParentlessMicroPropsGenerator, MicroPropsGenerator, ModifierStore

Takes care of formatting currency and measurement unit names, as well as populating the gender of measure units.
  • Field Details

    • 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
    • modifiers

      private final Map<StandardPlural,SimpleModifier> modifiers
    • rules

      private final PluralRules rules
    • parent

      private final MicroPropsGenerator parent
    • gender

      private String gender
  • Constructor Details

  • Method Details

    • getIndex

      private static int getIndex(String pluralKeyword)
    • getWithPlural

      static String getWithPlural(String[] strings, StandardPlural plural)
    • extractCorePattern

      private static LongNameHandler.ExtractCorePatternResult extractCorePattern(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 String getGenderForBuiltin(ULocale locale, MeasureUnit builtinUnit)
    • getInflectedMeasureData

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

      static void getMeasureData(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width, String unitDisplayCase, String[] outArray)
    • getCurrencyLongNameData

      private static void getCurrencyLongNameData(ULocale locale, Currency currency, String[] outArray)
    • getCompoundValue

      private static String getCompoundValue(String compoundKey, ULocale locale, NumberFormatter.UnitWidth width)
    • getDeriveCompoundRule

      private static String getDeriveCompoundRule(ULocale locale, String feature, 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 String getDerivedGender(ULocale locale, String structure, String[] data0, String[] data1)
    • calculateGenderForUnit

      private static 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, String[] outArray)
    • getUnitDisplayName

      public static String getUnitDisplayName(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width)
    • forCurrencyLongNames

      public static LongNameHandler forCurrencyLongNames(ULocale locale, Currency currency, PluralRules rules, MicroPropsGenerator parent)
    • forMeasureUnit

      public static LongNameHandler forMeasureUnit(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width, 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.
    • forArbitraryUnit

      private static LongNameHandler forArbitraryUnit(ULocale loc, MeasureUnit unit, NumberFormatter.UnitWidth width, String unitDisplayCase, PluralRules rules, MicroPropsGenerator parent)
    • processPatternTimes

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

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

      private void multiSimpleFormatsToModifiers(String[] leadFormats, 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.
    • processQuantity

      public MicroProps processQuantity(DecimalQuantity quantity)
      Description copied from interface: MicroPropsGenerator
      Considers the given DecimalQuantity, optionally mutates it, and returns a MicroProps.
      Specified by:
      processQuantity in interface MicroPropsGenerator
      Parameters:
      quantity - The quantity for consideration and optional mutation.
      Returns:
      A MicroProps instance resolved for the quantity.
    • processQuantityWithMicros

      public MicroProps processQuantityWithMicros(DecimalQuantity quantity, MicroProps micros)
      Produces a plural-appropriate Modifier for a unit: quantity is taken as the final smallest unit, while the larger unit values must be provided via micros.mixedMeasures. Does not call parent.processQuantity, so cannot get a MicroProps instance that way. Instead, the instance is passed in as a parameter.
      Specified by:
      processQuantityWithMicros in interface LongNameMultiplexer.ParentlessMicroPropsGenerator
    • getModifier

      public Modifier getModifier(Modifier.Signum signum, StandardPlural plural)
      Description copied from interface: ModifierStore
      Returns a Modifier with the given parameters (best-effort).
      Specified by:
      getModifier in interface ModifierStore