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