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 4package android.icu.impl.number; 5 6import android.icu.impl.StandardPlural; 7 8/** 9 * A ParameterizedModifier by itself is NOT a Modifier. Rather, it wraps a data structure containing two or more 10 * Modifiers and returns the modifier appropriate for the current situation. 11 * @hide Only a subset of ICU is exposed in Android 12 */ 13public class ParameterizedModifier { 14 private final Modifier positive; 15 private final Modifier negative; 16 final Modifier[] mods; 17 boolean frozen; 18 19 /** 20 * This constructor populates the ParameterizedModifier with a single positive and negative form. 21 * 22 * <p> 23 * If this constructor is used, a plural form CANNOT be passed to {@link #getModifier}. 24 */ 25 public ParameterizedModifier(Modifier positive, Modifier negative) { 26 this.positive = positive; 27 this.negative = negative; 28 this.mods = null; 29 this.frozen = true; 30 } 31 32 /** 33 * This constructor prepares the ParameterizedModifier to be populated with a positive and negative Modifier for 34 * multiple plural forms. 35 * 36 * <p> 37 * If this constructor is used, a plural form MUST be passed to {@link #getModifier}. 38 */ 39 public ParameterizedModifier() { 40 this.positive = null; 41 this.negative = null; 42 this.mods = new Modifier[2 * StandardPlural.COUNT]; 43 this.frozen = false; 44 } 45 46 public void setModifier(boolean isNegative, StandardPlural plural, Modifier mod) { 47 assert !frozen; 48 mods[getModIndex(isNegative, plural)] = mod; 49 } 50 51 public void freeze() { 52 frozen = true; 53 } 54 55 public Modifier getModifier(boolean isNegative) { 56 assert frozen; 57 assert mods == null; 58 return isNegative ? negative : positive; 59 } 60 61 public Modifier getModifier(boolean isNegative, StandardPlural plural) { 62 assert frozen; 63 assert positive == null; 64 return mods[getModIndex(isNegative, plural)]; 65 } 66 67 private static int getModIndex(boolean isNegative, StandardPlural plural) { 68 return plural.ordinal() * 2 + (isNegative ? 1 : 0); 69 } 70} 71