author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58288 | 48e480e56aad |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
48251
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.spi; |
|
27 |
||
28 |
import java.util.Locale; |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
29 |
import java.util.Objects; |
2 | 30 |
|
31 |
/** |
|
32 |
* An abstract class for service providers that |
|
33 |
* provide localized names for the |
|
34 |
* {@link java.util.Locale Locale} class. |
|
35 |
* |
|
36 |
* @since 1.6 |
|
37 |
*/ |
|
38 |
public abstract class LocaleNameProvider extends LocaleServiceProvider { |
|
39 |
||
40 |
/** |
|
41 |
* Sole constructor. (For invocation by subclass constructors, typically |
|
42 |
* implicit.) |
|
43 |
*/ |
|
44 |
protected LocaleNameProvider() { |
|
45 |
} |
|
46 |
||
47 |
/** |
|
6501 | 48 |
* Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> |
49 |
* IETF BCP47</a> language code and the given locale that is appropriate for |
|
50 |
* display to the user. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
51 |
* For example, if {@code languageCode} is "fr" and {@code locale} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
52 |
* is en_US, getDisplayLanguage() will return "French"; if {@code languageCode} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
53 |
* is "en" and {@code locale} is fr_FR, getDisplayLanguage() will return "anglais". |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
54 |
* If the name returned cannot be localized according to {@code locale}, |
2 | 55 |
* (say, the provider does not have a Japanese name for Croatian), |
56 |
* this method returns null. |
|
6501 | 57 |
* @param languageCode the language code string in the form of two to eight |
2 | 58 |
* lower-case letters between 'a' (U+0061) and 'z' (U+007A) |
59 |
* @param locale the desired locale |
|
60 |
* @return the name of the given language code for the specified locale, or null if it's not |
|
61 |
* available. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
62 |
* @throws NullPointerException if {@code languageCode} or {@code locale} is null |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
63 |
* @throws IllegalArgumentException if {@code languageCode} is not in the form of |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
64 |
* two or three lower-case letters, or {@code locale} isn't |
2 | 65 |
* one of the locales returned from |
66 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
|
67 |
* getAvailableLocales()}. |
|
68 |
* @see java.util.Locale#getDisplayLanguage(java.util.Locale) |
|
69 |
*/ |
|
70 |
public abstract String getDisplayLanguage(String languageCode, Locale locale); |
|
71 |
||
72 |
/** |
|
6501 | 73 |
* Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> |
74 |
* IETF BCP47</a> script code and the given locale that is appropriate for |
|
75 |
* display to the user. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
76 |
* For example, if {@code scriptCode} is "Latn" and {@code locale} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
77 |
* is en_US, getDisplayScript() will return "Latin"; if {@code scriptCode} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
78 |
* is "Cyrl" and {@code locale} is fr_FR, getDisplayScript() will return "cyrillique". |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
79 |
* If the name returned cannot be localized according to {@code locale}, |
6501 | 80 |
* (say, the provider does not have a Japanese name for Cyrillic), |
8146
f1b64e82649f
7013282: No appropriate CCC request for listed JDK 7 changes in java.util.spi package (b121)
naoto
parents:
7252
diff
changeset
|
81 |
* this method returns null. The default implementation returns null. |
6501 | 82 |
* @param scriptCode the four letter script code string in the form of title-case |
83 |
* letters (the first letter is upper-case character between 'A' (U+0041) and |
|
84 |
* 'Z' (U+005A) followed by three lower-case character between 'a' (U+0061) |
|
85 |
* and 'z' (U+007A)). |
|
86 |
* @param locale the desired locale |
|
87 |
* @return the name of the given script code for the specified locale, or null if it's not |
|
88 |
* available. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
89 |
* @throws NullPointerException if {@code scriptCode} or {@code locale} is null |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
90 |
* @throws IllegalArgumentException if {@code scriptCode} is not in the form of |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
91 |
* four title case letters, or {@code locale} isn't |
6501 | 92 |
* one of the locales returned from |
93 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
|
94 |
* getAvailableLocales()}. |
|
95 |
* @see java.util.Locale#getDisplayScript(java.util.Locale) |
|
96 |
* @since 1.7 |
|
97 |
*/ |
|
7252
2316b2e837d8
7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents:
6501
diff
changeset
|
98 |
public String getDisplayScript(String scriptCode, Locale locale) { |
2316b2e837d8
7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents:
6501
diff
changeset
|
99 |
return null; |
2316b2e837d8
7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents:
6501
diff
changeset
|
100 |
} |
6501 | 101 |
|
102 |
/** |
|
103 |
* Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> |
|
104 |
* IETF BCP47</a> region code (either ISO 3166 country code or UN M.49 area |
|
105 |
* codes) and the given locale that is appropriate for display to the user. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
106 |
* For example, if {@code countryCode} is "FR" and {@code locale} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
107 |
* is en_US, getDisplayCountry() will return "France"; if {@code countryCode} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
108 |
* is "US" and {@code locale} is fr_FR, getDisplayCountry() will return "Etats-Unis". |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
109 |
* If the name returned cannot be localized according to {@code locale}, |
2 | 110 |
* (say, the provider does not have a Japanese name for Croatia), |
111 |
* this method returns null. |
|
6501 | 112 |
* @param countryCode the country(region) code string in the form of two |
113 |
* upper-case letters between 'A' (U+0041) and 'Z' (U+005A) or the UN M.49 area code |
|
114 |
* in the form of three digit letters between '0' (U+0030) and '9' (U+0039). |
|
2 | 115 |
* @param locale the desired locale |
116 |
* @return the name of the given country code for the specified locale, or null if it's not |
|
117 |
* available. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
118 |
* @throws NullPointerException if {@code countryCode} or {@code locale} is null |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
119 |
* @throws IllegalArgumentException if {@code countryCode} is not in the form of |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
120 |
* two upper-case letters or three digit letters, or {@code locale} isn't |
2 | 121 |
* one of the locales returned from |
122 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
|
123 |
* getAvailableLocales()}. |
|
124 |
* @see java.util.Locale#getDisplayCountry(java.util.Locale) |
|
125 |
*/ |
|
126 |
public abstract String getDisplayCountry(String countryCode, Locale locale); |
|
127 |
||
128 |
/** |
|
129 |
* Returns a localized name for the given variant code and the given locale that |
|
130 |
* is appropriate for display to the user. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
131 |
* If the name returned cannot be localized according to {@code locale}, |
2 | 132 |
* this method returns null. |
133 |
* @param variant the variant string |
|
134 |
* @param locale the desired locale |
|
135 |
* @return the name of the given variant string for the specified locale, or null if it's not |
|
136 |
* available. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
137 |
* @throws NullPointerException if {@code variant} or {@code locale} is null |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
138 |
* @throws IllegalArgumentException if {@code locale} isn't |
2 | 139 |
* one of the locales returned from |
140 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
|
141 |
* getAvailableLocales()}. |
|
142 |
* @see java.util.Locale#getDisplayVariant(java.util.Locale) |
|
143 |
*/ |
|
144 |
public abstract String getDisplayVariant(String variant, Locale locale); |
|
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
145 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
146 |
/** |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
147 |
* Returns a localized name for the given |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
148 |
* <a href="../Locale.html#def_locale_extension">Unicode extension</a> key, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
149 |
* and the given locale that is appropriate for display to the user. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
150 |
* If the name returned cannot be localized according to {@code locale}, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
151 |
* this method returns null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
152 |
* @implSpec the default implementation returns {@code null}. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
153 |
* @param key the Unicode Extension key, not null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
154 |
* @param locale the desired locale, not null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
155 |
* @return the name of the given key string for the specified locale, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
156 |
* or null if it's not available. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
48251
diff
changeset
|
157 |
* @throws NullPointerException if {@code key} or {@code locale} is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
48251
diff
changeset
|
158 |
* @throws IllegalArgumentException if {@code locale} isn't |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
159 |
* one of the locales returned from |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
160 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
161 |
* getAvailableLocales()}. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
162 |
* @since 10 |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
163 |
*/ |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
164 |
public String getDisplayUnicodeExtensionKey(String key, Locale locale) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
165 |
Objects.requireNonNull(key); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
166 |
Objects.requireNonNull(locale); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
167 |
return null; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
168 |
} |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
169 |
|
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
170 |
/** |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
171 |
* Returns a localized name for the given |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
172 |
* <a href="../Locale.html#def_locale_extension">Unicode extension</a> type, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
173 |
* and the given locale that is appropriate for display to the user. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
174 |
* If the name returned cannot be localized according to {@code locale}, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
175 |
* this method returns null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
176 |
* @implSpec the default implementation returns {@code null}. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
177 |
* @param type the Unicode Extension type, not null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
178 |
* @param key the Unicode Extension key for this {@code type}, not null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
179 |
* @param locale the desired locale, not null. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
180 |
* @return the name of the given type string for the specified locale, |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
181 |
* or null if it's not available. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
48251
diff
changeset
|
182 |
* @throws NullPointerException if {@code key}, {@code type} or {@code locale} is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
48251
diff
changeset
|
183 |
* @throws IllegalArgumentException if {@code locale} isn't |
48251
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
184 |
* one of the locales returned from |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
185 |
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
186 |
* getAvailableLocales()}. |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
187 |
* @since 10 |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
188 |
*/ |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
189 |
public String getDisplayUnicodeExtensionType(String type, String key, Locale locale) { |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
190 |
Objects.requireNonNull(type); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
191 |
Objects.requireNonNull(key); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
192 |
Objects.requireNonNull(locale); |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
193 |
return null; |
57148c79bd75
8176841: Additional Unicode Language-Tag Extensions
naoto
parents:
47216
diff
changeset
|
194 |
} |
2 | 195 |
} |