Class ConstantAffixModifier

  • All Implemented Interfaces:
    Modifier

    public class ConstantAffixModifier
    extends java.lang.Object
    implements Modifier
    The canonical implementation of Modifier, containing a prefix and suffix string.
    • Field Detail

      • prefix

        private final java.lang.String prefix
      • suffix

        private final java.lang.String suffix
      • field

        private final java.text.Format.Field field
      • strong

        private final boolean strong
    • Constructor Detail

      • ConstantAffixModifier

        public ConstantAffixModifier​(java.lang.String prefix,
                                     java.lang.String suffix,
                                     java.text.Format.Field field,
                                     boolean strong)
        Constructs an instance with the given strings.

        The arguments need to be Strings, not CharSequences, because Strings are immutable but CharSequences are not.

        Parameters:
        prefix - The prefix string.
        suffix - The suffix string.
        field - The field type to be associated with this modifier. Can be null.
        strong - Whether this modifier should be strongly applied.
        See Also:
        Format.Field
      • ConstantAffixModifier

        public ConstantAffixModifier()
        Constructs a new instance with an empty prefix, suffix, and field.
    • Method Detail

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object