< prev index next >

src/java.base/share/classes/java/util/Locale.java

Print this page




 702     }
 703 
 704     /**
 705      * This method must be called only for creating the Locale.*
 706      * constants due to making shortcuts.
 707      */
 708     private static Locale createConstant(String lang, String country) {
 709         BaseLocale base = BaseLocale.createInstance(lang, country);
 710         return getInstance(base, null);
 711     }
 712 
 713     /**
 714      * Returns a <code>Locale</code> constructed from the given
 715      * <code>language</code>, <code>country</code> and
 716      * <code>variant</code>. If the same <code>Locale</code> instance
 717      * is available in the cache, then that instance is
 718      * returned. Otherwise, a new <code>Locale</code> instance is
 719      * created and cached.
 720      *
 721      * @param language lowercase 2 to 8 language code.
 722      * @param country uppercase two-letter ISO-3166 code and numric-3 UN M.49 area code.
 723      * @param variant vendor and browser specific code. See class description.
 724      * @return the <code>Locale</code> instance requested
 725      * @exception NullPointerException if any argument is null.
 726      */
 727     static Locale getInstance(String language, String country, String variant) {
 728         return getInstance(language, "", country, variant, null);
 729     }
 730 
 731     static Locale getInstance(String language, String script, String country,
 732                                       String variant, LocaleExtensions extensions) {
 733         if (language== null || script == null || country == null || variant == null) {
 734             throw new NullPointerException();
 735         }
 736 
 737         if (extensions == null) {
 738             extensions = getCompatibilityExtensions(language, script, country, variant);
 739         }
 740 
 741         BaseLocale baseloc = BaseLocale.getInstance(language, script, country, variant);
 742         return getInstance(baseloc, extensions);


1219      */
1220     public Set<String> getUnicodeLocaleKeys() {
1221         if (localeExtensions == null) {
1222             return Collections.emptySet();
1223         }
1224         return localeExtensions.getUnicodeLocaleKeys();
1225     }
1226 
1227     /**
1228      * Package locale method returning the Locale's BaseLocale,
1229      * used by ResourceBundle
1230      * @return base locale of this Locale
1231      */
1232     BaseLocale getBaseLocale() {
1233         return baseLocale;
1234     }
1235 
1236     /**
1237      * Package private method returning the Locale's LocaleExtensions,
1238      * used by ResourceBundle.
1239      * @return locale exnteions of this Locale,
1240      *         or {@code null} if no extensions are defined
1241      */
1242      LocaleExtensions getLocaleExtensions() {
1243          return localeExtensions;
1244      }
1245 
1246     /**
1247      * Returns a string representation of this <code>Locale</code>
1248      * object, consisting of language, country, variant, script,
1249      * and extensions as below:
1250      * <blockquote>
1251      * language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions
1252      * </blockquote>
1253      *
1254      * Language is always lower case, country is always upper case, script is always title
1255      * case, and extensions are always lower case.  Extensions and private use subtags
1256      * will be in canonical order as explained in {@link #toLanguageTag}.
1257      *
1258      * <p>When the locale has neither script nor extensions, the result is the same as in
1259      * Java 6 and prior.


2592          * @return This builder.
2593          * @throws NullPointerException if <code>attribute</code> is null
2594          * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
2595          * @see #setExtension(char, String)
2596          */
2597         public Builder addUnicodeLocaleAttribute(String attribute) {
2598             try {
2599                 localeBuilder.addUnicodeLocaleAttribute(attribute);
2600             } catch (LocaleSyntaxException e) {
2601                 throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
2602             }
2603             return this;
2604         }
2605 
2606         /**
2607          * Removes a unicode locale attribute, if present, otherwise has no
2608          * effect.  The attribute must not be null and must be <a
2609          * href="./Locale.html#def_locale_extension">well-formed</a> or an exception
2610          * is thrown.
2611          *
2612          * <p>Attribute comparision for removal is case-insensitive.
2613          *
2614          * @param attribute the attribute
2615          * @return This builder.
2616          * @throws NullPointerException if <code>attribute</code> is null
2617          * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
2618          * @see #setExtension(char, String)
2619          */
2620         public Builder removeUnicodeLocaleAttribute(String attribute) {
2621             try {
2622                 localeBuilder.removeUnicodeLocaleAttribute(attribute);
2623             } catch (LocaleSyntaxException e) {
2624                 throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
2625             }
2626             return this;
2627         }
2628 
2629         /**
2630          * Resets the builder to its initial, empty state.
2631          *
2632          * @return This builder.




 702     }
 703 
 704     /**
 705      * This method must be called only for creating the Locale.*
 706      * constants due to making shortcuts.
 707      */
 708     private static Locale createConstant(String lang, String country) {
 709         BaseLocale base = BaseLocale.createInstance(lang, country);
 710         return getInstance(base, null);
 711     }
 712 
 713     /**
 714      * Returns a <code>Locale</code> constructed from the given
 715      * <code>language</code>, <code>country</code> and
 716      * <code>variant</code>. If the same <code>Locale</code> instance
 717      * is available in the cache, then that instance is
 718      * returned. Otherwise, a new <code>Locale</code> instance is
 719      * created and cached.
 720      *
 721      * @param language lowercase 2 to 8 language code.
 722      * @param country uppercase two-letter ISO-3166 code and numeric-3 UN M.49 area code.
 723      * @param variant vendor and browser specific code. See class description.
 724      * @return the <code>Locale</code> instance requested
 725      * @exception NullPointerException if any argument is null.
 726      */
 727     static Locale getInstance(String language, String country, String variant) {
 728         return getInstance(language, "", country, variant, null);
 729     }
 730 
 731     static Locale getInstance(String language, String script, String country,
 732                                       String variant, LocaleExtensions extensions) {
 733         if (language== null || script == null || country == null || variant == null) {
 734             throw new NullPointerException();
 735         }
 736 
 737         if (extensions == null) {
 738             extensions = getCompatibilityExtensions(language, script, country, variant);
 739         }
 740 
 741         BaseLocale baseloc = BaseLocale.getInstance(language, script, country, variant);
 742         return getInstance(baseloc, extensions);


1219      */
1220     public Set<String> getUnicodeLocaleKeys() {
1221         if (localeExtensions == null) {
1222             return Collections.emptySet();
1223         }
1224         return localeExtensions.getUnicodeLocaleKeys();
1225     }
1226 
1227     /**
1228      * Package locale method returning the Locale's BaseLocale,
1229      * used by ResourceBundle
1230      * @return base locale of this Locale
1231      */
1232     BaseLocale getBaseLocale() {
1233         return baseLocale;
1234     }
1235 
1236     /**
1237      * Package private method returning the Locale's LocaleExtensions,
1238      * used by ResourceBundle.
1239      * @return locale extensions of this Locale,
1240      *         or {@code null} if no extensions are defined
1241      */
1242      LocaleExtensions getLocaleExtensions() {
1243          return localeExtensions;
1244      }
1245 
1246     /**
1247      * Returns a string representation of this <code>Locale</code>
1248      * object, consisting of language, country, variant, script,
1249      * and extensions as below:
1250      * <blockquote>
1251      * language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions
1252      * </blockquote>
1253      *
1254      * Language is always lower case, country is always upper case, script is always title
1255      * case, and extensions are always lower case.  Extensions and private use subtags
1256      * will be in canonical order as explained in {@link #toLanguageTag}.
1257      *
1258      * <p>When the locale has neither script nor extensions, the result is the same as in
1259      * Java 6 and prior.


2592          * @return This builder.
2593          * @throws NullPointerException if <code>attribute</code> is null
2594          * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
2595          * @see #setExtension(char, String)
2596          */
2597         public Builder addUnicodeLocaleAttribute(String attribute) {
2598             try {
2599                 localeBuilder.addUnicodeLocaleAttribute(attribute);
2600             } catch (LocaleSyntaxException e) {
2601                 throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
2602             }
2603             return this;
2604         }
2605 
2606         /**
2607          * Removes a unicode locale attribute, if present, otherwise has no
2608          * effect.  The attribute must not be null and must be <a
2609          * href="./Locale.html#def_locale_extension">well-formed</a> or an exception
2610          * is thrown.
2611          *
2612          * <p>Attribute comparison for removal is case-insensitive.
2613          *
2614          * @param attribute the attribute
2615          * @return This builder.
2616          * @throws NullPointerException if <code>attribute</code> is null
2617          * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
2618          * @see #setExtension(char, String)
2619          */
2620         public Builder removeUnicodeLocaleAttribute(String attribute) {
2621             try {
2622                 localeBuilder.removeUnicodeLocaleAttribute(attribute);
2623             } catch (LocaleSyntaxException e) {
2624                 throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
2625             }
2626             return this;
2627         }
2628 
2629         /**
2630          * Resets the builder to its initial, empty state.
2631          *
2632          * @return This builder.


< prev index next >