LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.impl.number; | 3 package com.ibm.icu.impl.number; |
4 | 4 |
5 import com.ibm.icu.impl.StandardPlural; | 5 import com.ibm.icu.impl.StandardPlural; |
6 | 6 |
7 /** | 7 /** |
8 * A ParameterizedModifier by itself is NOT a Modifier. Rather, it wraps a data
structure containing two or more | 8 * A ParameterizedModifier by itself is NOT a Modifier. Rather, it wraps a data
structure containing two |
9 * Modifiers and returns the modifier appropriate for the current situation. | 9 * or more Modifiers and returns the modifier appropriate for the current situat
ion. |
10 */ | 10 */ |
11 public class ParameterizedModifier { | 11 public class ParameterizedModifier { |
12 private final Modifier positive; | 12 private final Modifier positive; |
13 private final Modifier negative; | 13 private final Modifier negative; |
14 final Modifier[] mods; | 14 final Modifier[] mods; |
15 boolean frozen; | 15 boolean frozen; |
16 | 16 |
17 /** | 17 /** |
18 * This constructor populates the ParameterizedModifier with a single positi
ve and negative form. | 18 * This constructor populates the ParameterizedModifier with a single positi
ve and negative form. |
19 * | 19 * |
20 * <p> | 20 * <p> |
21 * If this constructor is used, a plural form CANNOT be passed to {@link #ge
tModifier}. | 21 * If this constructor is used, a plural form CANNOT be passed to {@link #ge
tModifier}. |
22 */ | 22 */ |
23 public ParameterizedModifier(Modifier positive, Modifier negative) { | 23 public ParameterizedModifier(Modifier positive, Modifier negative) { |
24 this.positive = positive; | 24 this.positive = positive; |
25 this.negative = negative; | 25 this.negative = negative; |
26 this.mods = null; | 26 this.mods = null; |
27 this.frozen = true; | 27 this.frozen = true; |
28 } | 28 } |
29 | 29 |
30 /** | 30 /** |
31 * This constructor prepares the ParameterizedModifier to be populated with
a positive and negative Modifier for | 31 * This constructor prepares the ParameterizedModifier to be populated with
a positive and negative |
32 * multiple plural forms. | 32 * Modifier for multiple plural forms. |
33 * | 33 * |
34 * <p> | 34 * <p> |
35 * If this constructor is used, a plural form MUST be passed to {@link #getM
odifier}. | 35 * If this constructor is used, a plural form MUST be passed to {@link #getM
odifier}. |
36 */ | 36 */ |
37 public ParameterizedModifier() { | 37 public ParameterizedModifier() { |
38 this.positive = null; | 38 this.positive = null; |
39 this.negative = null; | 39 this.negative = null; |
40 this.mods = new Modifier[2 * StandardPlural.COUNT]; | 40 this.mods = new Modifier[2 * StandardPlural.COUNT]; |
41 this.frozen = false; | 41 this.frozen = false; |
42 } | 42 } |
(...skipping 16 matching lines...) Expand all Loading... |
59 public Modifier getModifier(boolean isNegative, StandardPlural plural) { | 59 public Modifier getModifier(boolean isNegative, StandardPlural plural) { |
60 assert frozen; | 60 assert frozen; |
61 assert positive == null; | 61 assert positive == null; |
62 return mods[getModIndex(isNegative, plural)]; | 62 return mods[getModIndex(isNegative, plural)]; |
63 } | 63 } |
64 | 64 |
65 private static int getModIndex(boolean isNegative, StandardPlural plural) { | 65 private static int getModIndex(boolean isNegative, StandardPlural plural) { |
66 return plural.ordinal() * 2 + (isNegative ? 1 : 0); | 66 return plural.ordinal() * 2 + (isNegative ? 1 : 0); |
67 } | 67 } |
68 } | 68 } |
LEFT | RIGHT |