• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
NativePluralRules(int address)37     private NativePluralRules(int address) {
38         this.address = address;
39     }
40 
finalize()41     @Override protected void finalize() throws Throwable {
42         try {
43             finalizeImpl(address);
44         } finally {
45             super.finalize();
46         }
47     }
48 
forLocale(Locale locale)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      */
quantityForInt(int value)57     public int quantityForInt(int value) {
58         return quantityForIntImpl(address, value);
59     }
60 
finalizeImpl(int address)61     private static native void finalizeImpl(int address);
forLocaleImpl(String localeName)62     private static native int forLocaleImpl(String localeName);
quantityForIntImpl(int address, int value)63     private static native int quantityForIntImpl(int address, int value);
64 }
65