Class MutablePatternModifier
- All Implemented Interfaces:
AffixUtils.SymbolProvider,MicroPropsGenerator,Modifier
Modifier that wraps a decimal format pattern. It applies the pattern's affixes
in Modifier.apply(org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, int).
In addition to being a Modifier, this class contains the business logic for substituting the correct locale symbols into the affixes of the decimal format pattern.
In order to use this class, create a new instance and call the following four setters:
setPatternInfo(org.graalvm.shadowed.com.ibm.icu.impl.number.AffixPatternProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field), setPatternAttributes(org.graalvm.shadowed.com.ibm.icu.number.NumberFormatter.SignDisplay, boolean, boolean), setSymbols(org.graalvm.shadowed.com.ibm.icu.text.DecimalFormatSymbols, org.graalvm.shadowed.com.ibm.icu.util.Currency, org.graalvm.shadowed.com.ibm.icu.number.NumberFormatter.UnitWidth, org.graalvm.shadowed.com.ibm.icu.text.PluralRules), and
setNumberProperties(org.graalvm.shadowed.com.ibm.icu.impl.number.Modifier.Signum, org.graalvm.shadowed.com.ibm.icu.impl.StandardPlural). After calling these four setters, the instance will be ready for use as
a Modifier.
This is a MUTABLE, NON-THREAD-SAFE class designed for performance. Do NOT save references to this or
attempt to use it from multiple threads! Instead, you can obtain a safe, immutable decimal format
pattern modifier by calling createImmutable(), in effect treating this
instance as a builder for the immutable variant.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.graalvm.shadowed.com.ibm.icu.impl.number.Modifier
Modifier.Parameters, Modifier.Signum -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddToChain(MicroPropsGenerator parent) Used by the unsafe code path.intapply(FormattedStringBuilder output, int leftIndex, int rightIndex) Apply this Modifier to the string builder.booleancontainsField(Format.Field field) Whether the modifier contains at least one occurrence of the given field.Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable and can be saved for future use.intReturns the number of code points in the modifier, prefix plus suffix.Returns the currency symbol for the unit width specified in setSymbols()Gets a set of "parameters" for this Modifier.intGets the length of the prefix.getSymbol(int type) Returns the string that substitutes a given symbol type in a pattern.booleanisStrong()Whether this modifier is strong.booleanReturns true if the pattern represented by this MurkyModifier requires a plural keyword in order to localize.Considers the givenDecimalQuantity, optionally mutates it, and returns aMicroProps.booleansemanticallyEquivalent(Modifier other) Returns whether this Modifier is *semantically equivalent* to the other Modifier; in many cases, this is the same as equal, but parameters should be ignored.voidsetNumberProperties(Modifier.Signum signum, StandardPlural plural) Sets attributes of the current number being processed.voidsetPatternAttributes(NumberFormatter.SignDisplay signDisplay, boolean perMille, boolean approximately) Sets attributes that imply changes to the literal interpretation of the pattern string affixes.voidsetPatternInfo(AffixPatternProvider patternInfo, NumberFormat.Field field) Sets a reference to the parsed decimal format pattern, usually obtained fromPatternStringParser.parseToPatternInfo(String), but any implementation ofAffixPatternProvideris accepted.voidsetSymbols(DecimalFormatSymbols symbols, Currency currency, NumberFormatter.UnitWidth unitWidth, PluralRules rules) Sets locale-specific details that affect the symbols substituted into the pattern string affixes.
-
Constructor Details
-
MutablePatternModifier
public MutablePatternModifier(boolean isStrong) - Parameters:
isStrong- Whether the modifier should be considered strong. For more information, seeModifier.isStrong(). Most of the time, decimal format pattern modifiers should be considered as non-strong.
-
-
Method Details
-
setPatternInfo
Sets a reference to the parsed decimal format pattern, usually obtained fromPatternStringParser.parseToPatternInfo(String), but any implementation ofAffixPatternProvideris accepted.- Parameters:
field- Which field to use for literal characters in the pattern.
-
setPatternAttributes
public void setPatternAttributes(NumberFormatter.SignDisplay signDisplay, boolean perMille, boolean approximately) Sets attributes that imply changes to the literal interpretation of the pattern string affixes.- Parameters:
signDisplay- Whether to force a plus sign on positive numbers.perMille- Whether to substitute the percent sign in the pattern with a permille sign.approximately- Whether to prepend approximately to the sign
-
setSymbols
public void setSymbols(DecimalFormatSymbols symbols, Currency currency, NumberFormatter.UnitWidth unitWidth, PluralRules rules) Sets locale-specific details that affect the symbols substituted into the pattern string affixes.- Parameters:
symbols- The desired instance of DecimalFormatSymbols.currency- The currency to be used when substituting currency values into the affixes.unitWidth- The width used to render currencies.rules- Required if the triple currency sign, "¤¤¤", appears in the pattern, which can be determined from the convenience methodneedsPlurals().
-
setNumberProperties
Sets attributes of the current number being processed.- Parameters:
signum- -1 if negative; +1 if positive; or 0 if zero.plural- The plural form of the number, required only if the pattern contains the triple currency sign, "¤¤¤" (and as indicated byneedsPlurals()).
-
needsPlurals
public boolean needsPlurals()Returns true if the pattern represented by this MurkyModifier requires a plural keyword in order to localize. This is currently true only if there is a currency long name placeholder in the pattern ("¤¤¤"). -
createImmutable
Creates a new quantity-dependent Modifier that behaves the same as the current instance, but which is immutable and can be saved for future use. The number properties in the current instance are mutated; all other properties are left untouched.The resulting modifier cannot be used in a QuantityChain.
- Returns:
- An immutable that supports both positive and negative numbers.
-
addToChain
Used by the unsafe code path. -
processQuantity
Description copied from interface:MicroPropsGeneratorConsiders the givenDecimalQuantity, optionally mutates it, and returns aMicroProps.- Specified by:
processQuantityin interfaceMicroPropsGenerator- Parameters:
fq- The quantity for consideration and optional mutation.- Returns:
- A MicroProps instance resolved for the quantity.
-
apply
Description copied from interface:ModifierApply this Modifier to the string builder.- Specified by:
applyin interfaceModifier- Parameters:
output- The string builder to which to apply this modifier.leftIndex- The left index of the string within the builder. Equal to 0 when only one number is being formatted.rightIndex- The right index of the string within the string builder. Equal to length when only one number is being formatted.- Returns:
- The number of characters (UTF-16 code units) that were added to the string builder.
-
getPrefixLength
public int getPrefixLength()Description copied from interface:ModifierGets the length of the prefix. This information can be used in combination withModifier.apply(org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, int)to extract the prefix and suffix strings.- Specified by:
getPrefixLengthin interfaceModifier- Returns:
- The number of characters (UTF-16 code units) in the prefix.
-
getCodePointCount
public int getCodePointCount()Description copied from interface:ModifierReturns the number of code points in the modifier, prefix plus suffix.- Specified by:
getCodePointCountin interfaceModifier
-
isStrong
public boolean isStrong()Description copied from interface:ModifierWhether this modifier is strong. If a modifier is strong, it should always be applied immediately and not allowed to bubble up. With regard to padding, strong modifiers are considered to be on the inside of the prefix and suffix. -
containsField
Description copied from interface:ModifierWhether the modifier contains at least one occurrence of the given field.- Specified by:
containsFieldin interfaceModifier
-
getParameters
Description copied from interface:ModifierGets a set of "parameters" for this Modifier.- Specified by:
getParametersin interfaceModifier
-
semanticallyEquivalent
Description copied from interface:ModifierReturns whether this Modifier is *semantically equivalent* to the other Modifier; in many cases, this is the same as equal, but parameters should be ignored.- Specified by:
semanticallyEquivalentin interfaceModifier
-
getSymbol
Returns the string that substitutes a given symbol type in a pattern.- Specified by:
getSymbolin interfaceAffixUtils.SymbolProvider
-
getCurrencySymbolForUnitWidth
Returns the currency symbol for the unit width specified in setSymbols()
-