• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
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     static enum Signum {
21         NEG,
22         NEG_ZERO,
23         POS_ZERO,
24         POS;
25 
26         static final int COUNT = Signum.values().length;
27     };
28 
29     /**
30      * Apply this Modifier to the string builder.
31      *
32      * @param output
33      *            The string builder to which to apply this modifier.
34      * @param leftIndex
35      *            The left index of the string within the builder. Equal to 0 when only one number is
36      *            being formatted.
37      * @param rightIndex
38      *            The right index of the string within the string builder. Equal to length when only one
39      *            number is being formatted.
40      * @return The number of characters (UTF-16 code units) that were added to the string builder.
41      */
apply(FormattedStringBuilder output, int leftIndex, int rightIndex)42     public int apply(FormattedStringBuilder output, int leftIndex, int rightIndex);
43 
44     /**
45      * Gets the length of the prefix. This information can be used in combination with {@link #apply} to
46      * extract the prefix and suffix strings.
47      *
48      * @return The number of characters (UTF-16 code units) in the prefix.
49      */
getPrefixLength()50     public int getPrefixLength();
51 
52     /**
53      * Returns the number of code points in the modifier, prefix plus suffix.
54      */
getCodePointCount()55     public int getCodePointCount();
56 
57     /**
58      * Whether this modifier is strong. If a modifier is strong, it should always be applied immediately
59      * and not allowed to bubble up. With regard to padding, strong modifiers are considered to be on the
60      * inside of the prefix and suffix.
61      *
62      * @return Whether the modifier is strong.
63      */
isStrong()64     public boolean isStrong();
65 
66     /**
67      * Whether the modifier contains at least one occurrence of the given field.
68      */
containsField(Field currency)69     public boolean containsField(Field currency);
70 
71     /**
72      * A fill-in for getParameters(). obj will always be set; if non-null, the other
73      * two fields are also safe to read.
74      */
75     public static class Parameters {
76         public ModifierStore obj;
77         public Signum signum;
78         public StandardPlural plural;
79     }
80 
81     /**
82      * Gets a set of "parameters" for this Modifier.
83      */
getParameters()84     public Parameters getParameters();
85 
86     /**
87      * Returns whether this Modifier is *semantically equivalent* to the other Modifier;
88      * in many cases, this is the same as equal, but parameters should be ignored.
89      */
semanticallyEquivalent(Modifier other)90     public boolean semanticallyEquivalent(Modifier other);
91 }
92