OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / libcore / icu / NativePluralRules.java
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package libcore.icu;
18
19 import java.util.Locale;
20
21 /**
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.
26  */
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;
34
35     private final int address;
36
37     private NativePluralRules(int address) {
38         this.address = address;
39     }
40
41     @Override public void finalize() throws Throwable {
42         try {
43             finalizeImpl(address);
44         } finally {
45             super.finalize();
46         }
47     }
48
49     public static NativePluralRules forLocale(Locale locale) {
50         return new NativePluralRules(forLocaleImpl(locale.toString()));
51     }
52
53     /**
54      * Returns the constant defined in this class corresponding
55      * to the first rule that matches the given value.
56      */
57     public int quantityForInt(int value) {
58         return quantityForIntImpl(address, value);
59     }
60
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);
64 }