2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import java.util.Locale;
22 * Provides access to ICU's
23 * <a href="http://icu-project.org/apiref/icu4c/classPluralRules.html">PluralRules</a> class.
24 * This is not necessary for Java API, but is used by frameworks/base's resources system to
25 * ease localization of strings to languages with complex grammatical rules regarding number.
27 public final class NativePluralRules {
28 public static final int ZERO = 0;
29 public static final int ONE = 1;
30 public static final int TWO = 2;
31 public static final int FEW = 3;
32 public static final int MANY = 4;
33 public static final int OTHER = 5;
35 private final int address;
37 private NativePluralRules(int address) {
38 this.address = address;
41 @Override public void finalize() throws Throwable {
43 finalizeImpl(address);
49 public static NativePluralRules forLocale(Locale locale) {
50 return new NativePluralRules(forLocaleImpl(locale.toString()));
54 * Returns the constant defined in this class corresponding
55 * to the first rule that matches the given value.
57 public int quantityForInt(int value) {
58 return quantityForIntImpl(address, value);
61 private static native void finalizeImpl(int address);
62 private static native int forLocaleImpl(String localeName);
63 private static native int quantityForIntImpl(int address, int value);