1/* GENERATED SOURCE. DO NOT MODIFY. */
2// © 2016 and later: Unicode, Inc. and others.
3// License & terms of use: http://www.unicode.org/copyright.html#License
4/*
5 *******************************************************************************
6 * Copyright (C) 2015, International Business Machines Corporation and
7 * others. All Rights Reserved.
8 *******************************************************************************
9 */
10package android.icu.impl;
11
12import java.util.Arrays;
13import java.util.Collections;
14import java.util.List;
15
16/**
17 * Standard CLDR plural form/category constants.
18 * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
19 * @hide Only a subset of ICU is exposed in Android
20 */
21public enum StandardPlural {
22    ZERO("zero"),
23    ONE("one"),
24    TWO("two"),
25    FEW("few"),
26    MANY("many"),
27    OTHER("other");
28
29    /**
30     * Numeric index of OTHER, same as OTHER.ordinal().
31     */
32    public static final int OTHER_INDEX = OTHER.ordinal();
33
34    /**
35     * Unmodifiable List of all standard plural form constants.
36     * List version of {@link #values()}.
37     */
38    public static final List<StandardPlural> VALUES =
39            Collections.unmodifiableList(Arrays.asList(values()));
40
41    /**
42     * Number of standard plural forms/categories.
43     */
44    public static final int COUNT = VALUES.size();
45
46    private final String keyword;
47
48    private StandardPlural(String kw) {
49        keyword = kw;
50    }
51
52    /**
53     * @return the lowercase CLDR keyword string for the plural form
54     */
55    public final String getKeyword() {
56        return keyword;
57    }
58
59    /**
60     * @param keyword for example "few" or "other"
61     * @return the plural form corresponding to the keyword, or null
62     */
63    public static final StandardPlural orNullFromString(CharSequence keyword) {
64        switch (keyword.length()) {
65        case 3:
66            if ("one".contentEquals(keyword)) {
67                return ONE;
68            } else if ("two".contentEquals(keyword)) {
69                return TWO;
70            } else if ("few".contentEquals(keyword)) {
71                return FEW;
72            }
73            break;
74        case 4:
75            if ("many".contentEquals(keyword)) {
76                return MANY;
77            } else if ("zero".contentEquals(keyword)) {
78                return ZERO;
79            }
80            break;
81        case 5:
82            if ("other".contentEquals(keyword)) {
83                return OTHER;
84            }
85            break;
86        default:
87            break;
88        }
89        return null;
90    }
91
92    /**
93     * @param keyword for example "few" or "other"
94     * @return the plural form corresponding to the keyword, or OTHER
95     */
96    public static final StandardPlural orOtherFromString(CharSequence keyword) {
97        StandardPlural p = orNullFromString(keyword);
98        return p != null ? p : OTHER;
99    }
100
101    /**
102     * @param keyword for example "few" or "other"
103     * @return the plural form corresponding to the keyword
104     * @throws IllegalArgumentException if the keyword is not a plural form
105     */
106    public static final StandardPlural fromString(CharSequence keyword) {
107        StandardPlural p = orNullFromString(keyword);
108        if (p != null) {
109            return p;
110        } else {
111            throw new IllegalArgumentException(keyword.toString());
112        }
113    }
114
115    /**
116     * @param keyword for example "few" or "other"
117     * @return the index of the plural form corresponding to the keyword, or a negative value
118     */
119    public static final int indexOrNegativeFromString(CharSequence keyword) {
120        StandardPlural p = orNullFromString(keyword);
121        return p != null ? p.ordinal() : -1;
122    }
123
124    /**
125     * @param keyword for example "few" or "other"
126     * @return the index of the plural form corresponding to the keyword, or OTHER_INDEX
127     */
128    public static final int indexOrOtherIndexFromString(CharSequence keyword) {
129        StandardPlural p = orNullFromString(keyword);
130        return p != null ? p.ordinal() : OTHER.ordinal();
131    }
132
133    /**
134     * @param keyword for example "few" or "other"
135     * @return the index of the plural form corresponding to the keyword
136     * @throws IllegalArgumentException if the keyword is not a plural form
137     */
138    public static final int indexFromString(CharSequence keyword) {
139        StandardPlural p = orNullFromString(keyword);
140        if (p != null) {
141            return p.ordinal();
142        } else {
143            throw new IllegalArgumentException(keyword.toString());
144        }
145    }
146}