Class MutablePatternModifier

    • Constructor Detail

      • MutablePatternModifier

        public MutablePatternModifier​(boolean isStrong)
        Parameters:
        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.
    • Method Detail

      • 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 method needsPlurals().
      • setNumberProperties

        public void setNumberProperties​(Modifier.Signum signum,
                                        StandardPlural plural)
        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 by needsPlurals()).
      • 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

        public 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. 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.
      • createConstantModifier

        private ConstantMultiFieldModifier createConstantModifier​(FormattedStringBuilder a,
                                                                  FormattedStringBuilder b)
        Uses the current properties to create a single ConstantMultiFieldModifier with currency spacing support if required.
        Parameters:
        a - A working FormattedStringBuilder object; passed from the outside to prevent the need to create many new instances if this method is called in a loop.
        b - Another working FormattedStringBuilder object.
        Returns:
        The constant modifier object.
      • apply

        public int apply​(FormattedStringBuilder output,
                         int leftIndex,
                         int rightIndex)
        Description copied from interface: Modifier
        Apply this Modifier to the string builder.
        Specified by:
        apply in interface Modifier
        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.
      • getCodePointCount

        public int getCodePointCount()
        Description copied from interface: Modifier
        Returns the number of code points in the modifier, prefix plus suffix.
        Specified by:
        getCodePointCount in interface Modifier
      • isStrong

        public boolean isStrong()
        Description copied from interface: Modifier
        Whether 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.
        Specified by:
        isStrong in interface Modifier
        Returns:
        Whether the modifier is strong.
      • containsField

        public boolean containsField​(java.text.Format.Field field)
        Description copied from interface: Modifier
        Whether the modifier contains at least one occurrence of the given field.
        Specified by:
        containsField in interface Modifier
      • strictEquals

        public boolean strictEquals​(Modifier other)
        Description copied from interface: Modifier
        Returns whether this Modifier equals another Modifier.
        Specified by:
        strictEquals in interface Modifier
      • prepareAffix

        private void prepareAffix​(boolean isPrefix)
        Pre-processes the prefix or suffix into the currentAffix field, creating and mutating that field if necessary. Calls down to PatternStringUtils#affixPatternProviderToStringBuilder.
        Parameters:
        isPrefix - true to prepare the prefix; false to prepare the suffix.
      • getSymbol

        public java.lang.CharSequence getSymbol​(int type)
        Returns the string that substitutes a given symbol type in a pattern.
        Specified by:
        getSymbol in interface AffixUtils.SymbolProvider
      • getCurrencySymbolForUnitWidth

        public java.lang.String getCurrencySymbolForUnitWidth()
        Returns the currency symbol for the unit width specified in setSymbols()