Top Description Inners Fields Constructors Methods
com.ibm.icu.impl.number

public Class LongNameHandler

extends Object
implements MicroPropsGenerator, ModifierStore, ParentlessMicroPropsGenerator
Class Inheritance
All Implemented Interfaces
com.ibm.icu.impl.number.LongNameMultiplexer.ParentlessMicroPropsGenerator, com.ibm.icu.impl.number.ModifierStore, com.ibm.icu.impl.number.MicroPropsGenerator
Imports
java.util.ArrayList, .EnumMap, .Map, .MissingResourceException, com.ibm.icu.impl.CurrencyData, .ICUData, .ICUResourceBundle, .PatternProps, .SimpleFormatterImpl, .StandardPlural, .UResource, com.ibm.icu.impl.number.Modifier.Signum, com.ibm.icu.impl.units.MeasureUnitImpl, .SingleUnitImpl, com.ibm.icu.lang.UCharacter, com.ibm.icu.number.NumberFormatter.UnitWidth, com.ibm.icu.text.NumberFormat, .PluralRules, com.ibm.icu.util.Currency, .ICUException, .MeasureUnit, .MeasureUnit.Complexity, .MeasureUnit.MeasurePrefix, .ULocale, .UResourceBundle

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
LongNameHandler.DerivedComponents

Loads and applies deriveComponent rules from CLDR's grammaticalFeatures.xml.

private static class
private static class
private static enum
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
private static final int
private String
private static final int
private static int
i

private final Map<StandardPlural, SimpleModifier>
private final MicroPropsGenerator
private static final int
private final PluralRules

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String

Returns:

The gender string for the unit, or an empty string if unknown or ungendered.
calculateGenderForUnit
(ULocale
The desired locale.
locale
,
MeasureUnit
The measure unit to calculate the gender for.
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.

private static LongNameHandler.ExtractCorePatternResult
extractCorePattern(String
is extracted as per Extract(...) in the spec: https://unicode.org/reports/tr35/tr35-general.html#compound-units
pattern
)

Returns three outputs extracted from pattern.

private static LongNameHandler
public static LongNameHandler
public static LongNameHandler
forMeasureUnit(ULocale
The desired locale.
locale
,
MeasureUnit
The measure unit to construct a LongNameHandler for.
unit
,
NumberFormatter.UnitWidth
Specifies the desired unit rendering.
width
,
String
Specifies the desired grammatical case. If the specified case is not found, we fall back to nominative or no-case.
unitDisplayCase
,
PluralRules
Plural rules.
rules
,
MicroPropsGenerator
Plural rules.
parent
)

Construct a localized LongNameHandler for the specified MeasureUnit.

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

private static String
getDeriveCompoundRule(ULocale locale, String feature, String structure)

Loads and returns the value in rules that look like these: <deriveCompound feature="gender" structure="per" value="0"/> <deriveCompound feature="gender" structure="times" value="1"/> Currently a fake example, but spec compliant: <deriveCompound feature="gender" structure="power" value="feminine"/> NOTE: If U_FAILURE(status), returns an empty string.

private static String
getDerivedGender(ULocale locale, String structure, String[] data0, String[] data1)

private static String
private static int
getIndex(String pluralKeyword)

pack-priv static void
getInflectedMeasureData(String subKey, ULocale locale, NumberFormatter.UnitWidth width, String gender, String caseVariant, String[] outArray)

pack-priv static void
getMeasureData(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width, String unitDisplayCase, String[] outArray)

public Modifier
getModifier(Modifier.Signum signum, StandardPlural plural)

Implements com.ibm.icu.impl.number.ModifierStore.getModifier.

Returns a Modifier with the given parameters (best-effort).
public static String
pack-priv static String
getWithPlural(String[] strings, StandardPlural plural)

private static void
maybeCalculateGender(ULocale locale, MeasureUnit unit, String[] outArray)

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.

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

public MicroProps
processQuantity(DecimalQuantity
The quantity for consideration and optional mutation.
quantity
)

Implements com.ibm.icu.impl.number.MicroPropsGenerator.processQuantity.

Deprecated as a consequence of DecimalQuantity being deprecated.
Considers the given DecimalQuantity, optionally mutates it, and returns a MicroProps.
public MicroProps
processQuantityWithMicros(DecimalQuantity quantity, MicroProps micros)

Implements com.ibm.icu.impl.number.LongNameMultiplexer.ParentlessMicroPropsGenerator.processQuantityWithMicros.

Deprecated as a consequence of DecimalQuantity being deprecated.
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.
private void
simpleFormatsToModifiers(String[] simpleFormats, NumberFormat.Field field)

Sets modifiers to use the patterns from simpleFormats.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ARRAY_LENGTHback to summary
pack-priv static final int ARRAY_LENGTH
DNAM_INDEXback to summary
private static final int DNAM_INDEX
genderback to summary
private String gender
GENDER_INDEXback to summary
private static final int GENDER_INDEX
iback to summary
private static int i
modifiersback to summary
private final Map<StandardPlural, SimpleModifier> modifiers
parentback to summary
private final MicroPropsGenerator parent
PER_INDEXback to summary
private static final int PER_INDEX
rulesback to summary
private final PluralRules rules

Constructor Detail

LongNameHandlerback to summary
private LongNameHandler(Map<StandardPlural, SimpleModifier> modifiers, PluralRules rules, MicroPropsGenerator parent)

Method Detail

calculateGenderForUnitback to summary
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:ULocale

The desired locale.

unit:MeasureUnit

The measure unit to calculate the gender for.

Returns:String

The gender string for the unit, or an empty string if unknown or ungendered.

extractCorePatternback to summary
private static LongNameHandler.ExtractCorePatternResult extractCorePattern(String pattern)

Returns three outputs extracted from pattern.

Parameters
pattern:String

is extracted as per Extract(...) in the spec: https://unicode.org/reports/tr35/tr35-general.html#compound-units

forArbitraryUnitback to summary
private static LongNameHandler forArbitraryUnit(ULocale loc, MeasureUnit unit, NumberFormatter.UnitWidth width, String unitDisplayCase, PluralRules rules, MicroPropsGenerator parent)
forCurrencyLongNamesback to summary
public static LongNameHandler forCurrencyLongNames(ULocale locale, Currency currency, PluralRules rules, MicroPropsGenerator parent)
forMeasureUnitback to summary
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:ULocale

The desired locale.

unit:MeasureUnit

The measure unit to construct a LongNameHandler for.

width:NumberFormatter.UnitWidth

Specifies the desired unit rendering.

unitDisplayCase:String

Specifies the desired grammatical case. If the specified case is not found, we fall back to nominative or no-case.

rules:PluralRules

Plural rules.

parent:MicroPropsGenerator

Plural rules.

getCompoundValueback to summary
private static String getCompoundValue(String compoundKey, ULocale locale, NumberFormatter.UnitWidth width)
getCurrencyLongNameDataback to summary
private static void getCurrencyLongNameData(ULocale locale, Currency currency, String[] outArray)
getDeriveCompoundRuleback to summary
private static String getDeriveCompoundRule(ULocale locale, String feature, String structure)

Loads and returns the value in rules that look like these: <deriveCompound feature="gender" structure="per" value="0"/> <deriveCompound feature="gender" structure="times" value="1"/> Currently a fake example, but spec compliant: <deriveCompound feature="gender" structure="power" value="feminine"/> NOTE: If U_FAILURE(status), returns an empty string.

getDerivedGenderback to summary
private static String getDerivedGender(ULocale locale, String structure, String[] data0, String[] data1)
getGenderForBuiltinback to summary
private static String getGenderForBuiltin(ULocale locale, MeasureUnit builtinUnit)
getIndexback to summary
private static int getIndex(String pluralKeyword)
getInflectedMeasureDataback to summary
pack-priv static void getInflectedMeasureData(String subKey, ULocale locale, NumberFormatter.UnitWidth width, String gender, String caseVariant, String[] outArray)
getMeasureDataback to summary
pack-priv static void getMeasureData(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width, String unitDisplayCase, String[] outArray)
getModifierback to summary
public Modifier getModifier(Modifier.Signum signum, StandardPlural plural)

Implements com.ibm.icu.impl.number.ModifierStore.getModifier.

Doc from com.ibm.icu.impl.number.ModifierStore.getModifier.

Returns a Modifier with the given parameters (best-effort).

Annotations
@Override
getUnitDisplayNameback to summary
public static String getUnitDisplayName(ULocale locale, MeasureUnit unit, NumberFormatter.UnitWidth width)
getWithPluralback to summary
pack-priv static String getWithPlural(String[] strings, StandardPlural plural)
maybeCalculateGenderback to summary
private static void maybeCalculateGender(ULocale locale, MeasureUnit unit, String[] outArray)
multiSimpleFormatsToModifiersback to summary
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.

processPatternTimesback to summary
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

processQuantityback to summary
public MicroProps processQuantity(DecimalQuantity quantity)

Implements com.ibm.icu.impl.number.MicroPropsGenerator.processQuantity.

Doc from com.ibm.icu.impl.number.MicroPropsGenerator.processQuantity.

Deprecated

as a consequence of DecimalQuantity being deprecated. See corresponding docs for further information.

Considers the given DecimalQuantity, optionally mutates it, and returns a MicroProps.

Parameters
quantity:DecimalQuantity

The quantity for consideration and optional mutation.

Returns:MicroProps

A MicroProps instance resolved for the quantity.

Annotations
@Override
processQuantityWithMicrosback to summary
public MicroProps processQuantityWithMicros(DecimalQuantity quantity, MicroProps micros)

Implements com.ibm.icu.impl.number.LongNameMultiplexer.ParentlessMicroPropsGenerator.processQuantityWithMicros.

Deprecated

as a consequence of DecimalQuantity being deprecated. See corresponding docs for further information.

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.

Annotations
@Override
simpleFormatsToModifiersback to summary
private void simpleFormatsToModifiers(String[] simpleFormats, NumberFormat.Field field)

Sets modifiers to use the patterns from simpleFormats.

com.ibm.icu.impl.number back to summary

private final Class LongNameHandler.AliasSink

extends Sink
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
put(UResource.Key
Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.
key
,
UResource.Value
Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.
value
,
boolean
true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.
noFallback
)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root).

Field Detail

replacementback to summary
pack-priv String replacement

Constructor Detail

AliasSinkback to summary
private AliasSink()

Method Detail

putback to summary
public void put(UResource.Key key, UResource.Value value, boolean noFallback)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Doc from com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root). The value is normally an array or table resource, and implementations of this method normally iterate over the tree of resource items stored there.

Parameters
key:UResource.Key

Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.

value:UResource.Value

Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.

noFallback:boolean

true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.

Annotations
@Override
com.ibm.icu.impl.number back to summary

private Class LongNameHandler.DerivedComponents

extends Object
Class Inheritance

Loads and applies deriveComponent rules from CLDR's grammaticalFeatures.xml.

Consider a deriveComponent rule that looks like this:

  <deriveComponent feature="case" structure="per" value0="compound" value1="nominative"/>
Instantiating an instance as follows:
  DerivedComponents d(loc, "case", "per");

Applying the rule in the XML element above, d.value0("foo") will be "foo", and d.value1("foo") will be "nominative".

In case of any kind of failure, value0() and value1() will simply return "".

Field Summary

Modifier and TypeField and Description
private String
private String

Constructor Summary

AccessConstructor and Description
pack-priv
DerivedComponents(ULocale locale, String feature, String structure)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv String
value0(String compoundValue)

pack-priv String
value1(String compoundValue)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

value0back to summary
private String value0
value1back to summary
private String value1

Constructor Detail

DerivedComponentsback to summary
pack-priv DerivedComponents(ULocale locale, String feature, String structure)

Constructor.

Method Detail

value0back to summary
pack-priv String value0(String compoundValue)
value1back to summary
pack-priv String value1(String compoundValue)
com.ibm.icu.impl.number back to summary

private Class LongNameHandler.ExtractCorePatternResult

extends Object
Class Inheritance
  • java.lang.Object
  • com.ibm.icu.impl.number.LongNameHandler.ExtractCorePatternResult

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv char
pack-priv LongNameHandler.PlaceholderPosition

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

coreUnitback to summary
pack-priv String coreUnit
joinerCharback to summary
pack-priv char joinerChar
placeholderPositionback to summary
pack-priv LongNameHandler.PlaceholderPosition placeholderPosition

Constructor Detail

ExtractCorePatternResultback to summary
private ExtractCorePatternResult()
com.ibm.icu.impl.number back to summary

private final Class LongNameHandler.InflectedPluralSink

extends Sink
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv String
pack-priv String[]

Constructor Summary

AccessConstructor and Description
public
InflectedPluralSink(String gender, String caseVariant, String[] outArray)

Method Summary

Modifier and TypeMethod and Description
private boolean
loadForCase(UResource.Table caseTable, String caseValue, UResource.Value value)

private boolean
loadForGender(UResource.Table genderTable, String genderVal, UResource.Value value)

private boolean
public void
put(UResource.Key
Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.
key
,
UResource.Value
Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.
value
,
boolean
true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.
noFallback
)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root).

Field Detail

caseVariantback to summary
pack-priv String caseVariant
genderback to summary
pack-priv String gender
outArrayback to summary
pack-priv String[] outArray

Constructor Detail

InflectedPluralSinkback to summary
public InflectedPluralSink(String gender, String caseVariant, String[] outArray)

Method Detail

loadForCaseback to summary
private boolean loadForCase(UResource.Table caseTable, String caseValue, UResource.Value value)
loadForGenderback to summary
private boolean loadForGender(UResource.Table genderTable, String genderVal, UResource.Value value)
loadForPluralFormback to summary
private boolean loadForPluralForm(UResource.Table genderTable, UResource.Value value)
putback to summary
public void put(UResource.Key key, UResource.Value value, boolean noFallback)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Doc from com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root). The value is normally an array or table resource, and implementations of this method normally iterate over the tree of resource items stored there.

Parameters
key:UResource.Key

Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.

value:UResource.Value

Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.

noFallback:boolean

true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.

Annotations
@Override
com.ibm.icu.impl.number back to summary

private final Enum LongNameHandler.PlaceholderPosition

extends Enum<LongNameHandler.PlaceholderPosition>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final LongNameHandler.PlaceholderPosition
public static final LongNameHandler.PlaceholderPosition
public static final LongNameHandler.PlaceholderPosition
public static final LongNameHandler.PlaceholderPosition

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LongNameHandler.PlaceholderPosition
public static LongNameHandler.PlaceholderPosition[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BEGINNINGback to summary
public static final LongNameHandler.PlaceholderPosition BEGINNING
ENDback to summary
public static final LongNameHandler.PlaceholderPosition END
MIDDLEback to summary
public static final LongNameHandler.PlaceholderPosition MIDDLE
NONEback to summary
public static final LongNameHandler.PlaceholderPosition NONE

Constructor Detail

PlaceholderPositionback to summary
private PlaceholderPosition()

Method Detail

valueOfback to summary
public static LongNameHandler.PlaceholderPosition valueOf(String name)
valuesback to summary
public static LongNameHandler.PlaceholderPosition[] values()
com.ibm.icu.impl.number back to summary

private final Class LongNameHandler.PluralTableSink

extends Sink
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String[]

Constructor Summary

AccessConstructor and Description
public
PluralTableSink(String[] outArray)

Method Summary

Modifier and TypeMethod and Description
public void
put(UResource.Key
Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.
key
,
UResource.Value
Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.
value
,
boolean
true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.
noFallback
)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root).

Field Detail

outArrayback to summary
pack-priv String[] outArray

Constructor Detail

PluralTableSinkback to summary
public PluralTableSink(String[] outArray)

Method Detail

putback to summary
public void put(UResource.Key key, UResource.Value value, boolean noFallback)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Doc from com.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root). The value is normally an array or table resource, and implementations of this method normally iterate over the tree of resource items stored there.

Parameters
key:UResource.Key

Initially the key string of the enumeration-start resource. Empty if the enumeration starts at the top level of the bundle. Reuse for output values from Array and Table getters.

value:UResource.Value

Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.

noFallback:boolean

true if the bundle has no parent; that is, its top-level table has the nofallback attribute, or it is the root bundle of a locale tree.

Annotations
@Override