public class MutablePatternModifier extends Object implements Modifier, AffixUtils.SymbolProvider, MicroPropsGenerator
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:
MutablePatternModifier.setPatternInfo(org.graalvm.shadowed.com.ibm.icu.impl.number.AffixPatternProvider, org.graalvm.shadowed.com.ibm.icu.text.NumberFormat.Field), MutablePatternModifier.setPatternAttributes(org.graalvm.shadowed.com.ibm.icu.number.NumberFormatter.SignDisplay, boolean, boolean), MutablePatternModifier.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
MutablePatternModifier.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 MutablePatternModifier.createImmutable(), in effect treating this
instance as a builder for the immutable variant.
| Modifier and Type | Class and Description |
|---|---|
static class |
MutablePatternModifier.ImmutablePatternModifier |
Modifier.Parameters, Modifier.Signum| Constructor and Description |
|---|
MutablePatternModifier(boolean isStrong) |
| Modifier and Type | Method and Description |
|---|---|
MicroPropsGenerator |
addToChain(MicroPropsGenerator parent)
Used by the unsafe code path.
|
int |
apply(FormattedStringBuilder output,
int leftIndex,
int rightIndex)
Apply this Modifier to the string builder.
|
boolean |
containsField(Format.Field field)
Whether the modifier contains at least one occurrence of the given field.
|
MutablePatternModifier.ImmutablePatternModifier |
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.
|
int |
getCodePointCount()
Returns the number of code points in the modifier, prefix plus suffix.
|
String |
getCurrencySymbolForUnitWidth()
Returns the currency symbol for the unit width specified in setSymbols()
|
Modifier.Parameters |
getParameters()
Gets a set of "parameters" for this Modifier.
|
int |
getPrefixLength()
Gets the length of the prefix.
|
CharSequence |
getSymbol(int type)
Returns the string that substitutes a given symbol type in a pattern.
|
boolean |
isStrong()
Whether this modifier is strong.
|
boolean |
needsPlurals()
Returns true if the pattern represented by this MurkyModifier requires a plural keyword in order
to localize.
|
MicroProps |
processQuantity(DecimalQuantity fq)
Considers the given
DecimalQuantity, optionally mutates it, and returns a
MicroProps. |
boolean |
semanticallyEquivalent(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.
|
void |
setNumberProperties(Modifier.Signum signum,
StandardPlural plural)
Sets attributes of the current number being processed.
|
void |
setPatternAttributes(NumberFormatter.SignDisplay signDisplay,
boolean perMille,
boolean approximately)
Sets attributes that imply changes to the literal interpretation of the pattern string affixes.
|
void |
setPatternInfo(AffixPatternProvider patternInfo,
NumberFormat.Field field)
Sets a reference to the parsed decimal format pattern, usually obtained from
PatternStringParser.parseToPatternInfo(String), but any implementation of
AffixPatternProvider is accepted. |
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.
|
public MutablePatternModifier(boolean isStrong)
isStrong - Whether the modifier should be considered strong. For more information, see
Modifier.isStrong(). Most of the time, decimal format pattern modifiers should
be considered as non-strong.public void setPatternInfo(AffixPatternProvider patternInfo, NumberFormat.Field field)
PatternStringParser.parseToPatternInfo(String), but any implementation of
AffixPatternProvider is accepted.field - Which field to use for literal characters in the pattern.public void setPatternAttributes(NumberFormatter.SignDisplay signDisplay, boolean perMille, boolean approximately)
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 signpublic void setSymbols(DecimalFormatSymbols symbols, Currency currency, NumberFormatter.UnitWidth unitWidth, PluralRules rules)
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 method MutablePatternModifier.needsPlurals().public void setNumberProperties(Modifier.Signum signum, StandardPlural plural)
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 by MutablePatternModifier.needsPlurals()).public boolean needsPlurals()
public MutablePatternModifier.ImmutablePatternModifier createImmutable()
The resulting modifier cannot be used in a QuantityChain.
public MicroPropsGenerator addToChain(MicroPropsGenerator parent)
public MicroProps processQuantity(DecimalQuantity fq)
MicroPropsGeneratorDecimalQuantity, optionally mutates it, and returns a
MicroProps.processQuantity in interface MicroPropsGeneratorfq - The quantity for consideration and optional mutation.public int apply(FormattedStringBuilder output, int leftIndex, int rightIndex)
Modifierapply in interface Modifieroutput - 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.public int getPrefixLength()
ModifierModifier.apply(org.graalvm.shadowed.com.ibm.icu.impl.FormattedStringBuilder, int, int) to
extract the prefix and suffix strings.getPrefixLength in interface Modifierpublic int getCodePointCount()
ModifiergetCodePointCount in interface Modifierpublic boolean isStrong()
Modifierpublic boolean containsField(Format.Field field)
ModifiercontainsField in interface Modifierpublic Modifier.Parameters getParameters()
ModifiergetParameters in interface Modifierpublic boolean semanticallyEquivalent(Modifier other)
ModifiersemanticallyEquivalent in interface Modifierpublic CharSequence getSymbol(int type)
getSymbol in interface AffixUtils.SymbolProviderpublic String getCurrencySymbolForUnitWidth()