1 // © 2017 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 package com.ibm.icu.impl.number; 4 5 import java.text.Format.Field; 6 7 import com.ibm.icu.impl.FormattedStringBuilder; 8 import com.ibm.icu.impl.StandardPlural; 9 10 /** 11 * A Modifier is an object that can be passed through the formatting pipeline until it is finally applied 12 * to the string builder. A Modifier usually contains a prefix and a suffix that are applied, but it 13 * could contain something else, like a {@link com.ibm.icu.text.SimpleFormatter} pattern. 14 * 15 * A Modifier is usually immutable, except in cases such as {@link MutablePatternModifier}, which are 16 * mutable for performance reasons. 17 */ 18 public interface Modifier { 19 20 /** 21 * Apply this Modifier to the string builder. 22 * 23 * @param output 24 * The string builder to which to apply this modifier. 25 * @param leftIndex 26 * The left index of the string within the builder. Equal to 0 when only one number is 27 * being formatted. 28 * @param rightIndex 29 * The right index of the string within the string builder. Equal to length when only one 30 * number is being formatted. 31 * @return The number of characters (UTF-16 code units) that were added to the string builder. 32 */ apply(FormattedStringBuilder output, int leftIndex, int rightIndex)33 public int apply(FormattedStringBuilder output, int leftIndex, int rightIndex); 34 35 /** 36 * Gets the length of the prefix. This information can be used in combination with {@link #apply} to 37 * extract the prefix and suffix strings. 38 * 39 * @return The number of characters (UTF-16 code units) in the prefix. 40 */ getPrefixLength()41 public int getPrefixLength(); 42 43 /** 44 * Returns the number of code points in the modifier, prefix plus suffix. 45 */ getCodePointCount()46 public int getCodePointCount(); 47 48 /** 49 * Whether this modifier is strong. If a modifier is strong, it should always be applied immediately 50 * and not allowed to bubble up. With regard to padding, strong modifiers are considered to be on the 51 * inside of the prefix and suffix. 52 * 53 * @return Whether the modifier is strong. 54 */ isStrong()55 public boolean isStrong(); 56 57 /** 58 * Whether the modifier contains at least one occurrence of the given field. 59 */ containsField(Field currency)60 public boolean containsField(Field currency); 61 62 /** 63 * A fill-in for getParameters(). obj will always be set; if non-null, the other 64 * two fields are also safe to read. 65 */ 66 public static class Parameters { 67 public ModifierStore obj; 68 public int signum; 69 public StandardPlural plural; 70 } 71 72 /** 73 * Gets a set of "parameters" for this Modifier. 74 */ getParameters()75 public Parameters getParameters(); 76 77 /** 78 * Returns whether this Modifier is *semantically equivalent* to the other Modifier; 79 * in many cases, this is the same as equal, but parameters should be ignored. 80 */ semanticallyEquivalent(Modifier other)81 public boolean semanticallyEquivalent(Modifier other); 82 } 83