1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2017 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 package ohos.global.icu.impl.number; 5 6 import ohos.global.icu.impl.StandardPlural; 7 import ohos.global.icu.impl.number.Modifier.Signum; 8 9 /** 10 * This implementation of ModifierStore adopts references to Modifiers. 11 * 12 * (This is named "adopting" because in C++, this class takes ownership of the Modifiers.) 13 * @hide exposed on OHOS 14 */ 15 public class AdoptingModifierStore implements ModifierStore { 16 private final Modifier positive; 17 private final Modifier posZero; 18 private final Modifier negZero; 19 private final Modifier negative; 20 final Modifier[] mods; 21 boolean frozen; 22 23 /** 24 * This constructor populates the ParameterizedModifier with a single positive and negative form. 25 * 26 * <p> 27 * If this constructor is used, a plural form CANNOT be passed to {@link #getModifier}. 28 */ AdoptingModifierStore(Modifier positive, Modifier posZero, Modifier negZero, Modifier negative)29 public AdoptingModifierStore(Modifier positive, Modifier posZero, Modifier negZero, Modifier negative) { 30 this.positive = positive; 31 this.posZero = posZero; 32 this.negZero = negZero; 33 this.negative = negative; 34 this.mods = null; 35 this.frozen = true; 36 } 37 38 /** 39 * This constructor prepares the ParameterizedModifier to be populated with a positive and negative 40 * Modifier for multiple plural forms. 41 * 42 * <p> 43 * If this constructor is used, a plural form MUST be passed to {@link #getModifier}. 44 */ AdoptingModifierStore()45 public AdoptingModifierStore() { 46 this.positive = null; 47 this.posZero = null; 48 this.negZero = null; 49 this.negative = null; 50 this.mods = new Modifier[4 * StandardPlural.COUNT]; 51 this.frozen = false; 52 } 53 setModifier(Signum signum, StandardPlural plural, Modifier mod)54 public void setModifier(Signum signum, StandardPlural plural, Modifier mod) { 55 assert !frozen; 56 mods[getModIndex(signum, plural)] = mod; 57 } 58 freeze()59 public void freeze() { 60 frozen = true; 61 } 62 getModifierWithoutPlural(Signum signum)63 public Modifier getModifierWithoutPlural(Signum signum) { 64 assert frozen; 65 assert mods == null; 66 assert signum != null; 67 switch (signum) { 68 case POS: 69 return positive; 70 case POS_ZERO: 71 return posZero; 72 case NEG_ZERO: 73 return negZero; 74 case NEG: 75 return negative; 76 default: 77 throw new AssertionError("Unreachable"); 78 } 79 } 80 81 @Override getModifier(Signum signum, StandardPlural plural)82 public Modifier getModifier(Signum signum, StandardPlural plural) { 83 assert frozen; 84 assert positive == null; 85 return mods[getModIndex(signum, plural)]; 86 } 87 getModIndex(Signum signum, StandardPlural plural)88 private static int getModIndex(Signum signum, StandardPlural plural) { 89 assert signum != null; 90 assert plural != null; 91 return plural.ordinal() * Signum.COUNT + signum.ordinal(); 92 } 93 } 94