583 * @see #getExtension(char)
584 * @see Builder#setExtension(char, String)
585 * @since 1.7
586 */
587 public static final char PRIVATE_USE_EXTENSION = 'x';
588
589 /**
590 * The key for Unicode locale extension ('u').
591 *
592 * @see #getExtension(char)
593 * @see Builder#setExtension(char, String)
594 * @since 1.7
595 */
596 public static final char UNICODE_LOCALE_EXTENSION = 'u';
597
598 /** serialization ID
599 */
600 static final long serialVersionUID = 9149081749638150636L;
601
602 /**
603 * Display types for retrieving localized names from the name providers.
604 */
605 private static final int DISPLAY_LANGUAGE = 0;
606 private static final int DISPLAY_COUNTRY = 1;
607 private static final int DISPLAY_VARIANT = 2;
608 private static final int DISPLAY_SCRIPT = 3;
609
610 /**
611 * Private constructor used by getInstance method
612 */
613 private Locale(BaseLocale baseLocale, LocaleExtensions extensions) {
614 this.baseLocale = baseLocale;
615 this.localeExtensions = extensions;
616 }
617
618 /**
619 * Construct a locale from language, country and variant.
620 * This constructor normalizes the language value to lowercase and
621 * the country value to uppercase.
622 * <p>
979 }
980 }
981
982 /**
983 * Returns an array of all installed locales.
984 * The returned array represents the union of locales supported
985 * by the Java runtime environment and by installed
986 * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
987 * implementations. It must contain at least a <code>Locale</code>
988 * instance equal to {@link java.util.Locale#US Locale.US}.
989 *
990 * @return An array of installed locales.
991 */
992 public static Locale[] getAvailableLocales() {
993 return LocaleServiceProviderPool.getAllAvailableLocales();
994 }
995
996 /**
997 * Returns a list of all 2-letter country codes defined in ISO 3166.
998 * Can be used to create Locales.
999 * <p>
1000 * <b>Note:</b> The <code>Locale</code> class also supports other codes for
1001 * country (region), such as 3-letter numeric UN M.49 area codes.
1002 * Therefore, the list returned by this method does not contain ALL valid
1003 * codes that can be used to create Locales.
1004 *
1005 * @return An array of ISO 3166 two-letter country codes.
1006 */
1007 public static String[] getISOCountries() {
1008 if (isoCountries == null) {
1009 isoCountries = getISO2Table(LocaleISOData.isoCountryTable);
1010 }
1011 String[] result = new String[isoCountries.length];
1012 System.arraycopy(isoCountries, 0, result, 0, isoCountries.length);
1013 return result;
1014 }
1015
1016 /**
1017 * Returns a list of all 2-letter language codes defined in ISO 639.
1018 * Can be used to create Locales.
1019 * <p>
1020 * <b>Note:</b>
1021 * <ul>
1022 * <li>ISO 639 is not a stable standard— some languages' codes have changed.
1023 * The list this function returns includes both the new and the old codes for the
1024 * languages whose codes have changed.
1025 * <li>The <code>Locale</code> class also supports language codes up to
1026 * 8 characters in length. Therefore, the list returned by this method does
1027 * not contain ALL valid codes that can be used to create Locales.
1028 * </ul>
1029 *
1030 * @return An array of ISO 639 two-letter language codes.
1031 */
1032 public static String[] getISOLanguages() {
1033 if (isoLanguages == null) {
1034 isoLanguages = getISO2Table(LocaleISOData.isoLanguageTable);
1035 }
1036 String[] result = new String[isoLanguages.length];
|
583 * @see #getExtension(char)
584 * @see Builder#setExtension(char, String)
585 * @since 1.7
586 */
587 public static final char PRIVATE_USE_EXTENSION = 'x';
588
589 /**
590 * The key for Unicode locale extension ('u').
591 *
592 * @see #getExtension(char)
593 * @see Builder#setExtension(char, String)
594 * @since 1.7
595 */
596 public static final char UNICODE_LOCALE_EXTENSION = 'u';
597
598 /** serialization ID
599 */
600 static final long serialVersionUID = 9149081749638150636L;
601
602 /**
603 * Enum for specifying the type defined in ISO 3166. This enum is used to
604 * retrieve the two-letter ISO3166-1 alpha-2, three-letter ISO3166-1
605 * alpha-3, four-letter ISO3166-3 country codes.
606 *
607 * @see #getISOCountries(Locale.IsoCountryCode)
608 * @since 9
609 */
610 public static enum IsoCountryCode {
611 /**
612 * PART1_ALPHA2 is used to represent the ISO3166-1 alpha-2 two letter
613 * country codes.
614 */
615 PART1_ALPHA2,
616
617 /**
618 *
619 * PART1_ALPHA3 is used to represent the ISO3166-1 alpha-3 three letter
620 * country codes.
621 */
622 PART1_ALPHA3,
623
624 /**
625 * PART3 is used to represent the ISO3166-3 four letter country codes.
626 */
627 PART3;
628 }
629
630 /**
631 * Display types for retrieving localized names from the name providers.
632 */
633 private static final int DISPLAY_LANGUAGE = 0;
634 private static final int DISPLAY_COUNTRY = 1;
635 private static final int DISPLAY_VARIANT = 2;
636 private static final int DISPLAY_SCRIPT = 3;
637
638 /**
639 * Private constructor used by getInstance method
640 */
641 private Locale(BaseLocale baseLocale, LocaleExtensions extensions) {
642 this.baseLocale = baseLocale;
643 this.localeExtensions = extensions;
644 }
645
646 /**
647 * Construct a locale from language, country and variant.
648 * This constructor normalizes the language value to lowercase and
649 * the country value to uppercase.
650 * <p>
1007 }
1008 }
1009
1010 /**
1011 * Returns an array of all installed locales.
1012 * The returned array represents the union of locales supported
1013 * by the Java runtime environment and by installed
1014 * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
1015 * implementations. It must contain at least a <code>Locale</code>
1016 * instance equal to {@link java.util.Locale#US Locale.US}.
1017 *
1018 * @return An array of installed locales.
1019 */
1020 public static Locale[] getAvailableLocales() {
1021 return LocaleServiceProviderPool.getAllAvailableLocales();
1022 }
1023
1024 /**
1025 * Returns a list of all 2-letter country codes defined in ISO 3166.
1026 * Can be used to create Locales.
1027 * This method is equivalent to {@link #getISOCountries(Locale.IsoCountryCode type)}
1028 * with {@code type} {@link IsoCountryCode#PART1_ALPHA2}.
1029 * <p>
1030 * <b>Note:</b> The <code>Locale</code> class also supports other codes for
1031 * country (region), such as 3-letter numeric UN M.49 area codes.
1032 * Therefore, the list returned by this method does not contain ALL valid
1033 * codes that can be used to create Locales.
1034 * <p>
1035 * Note that this method does not return obsolete 2-letter country codes.
1036 * ISO3166-3 codes which designate country codes for those obsolete codes,
1037 * can be retrieved from {@link #getISOCountries(Locale.IsoCountryCode type)} with
1038 * {@code type} {@link IsoCountryCode#PART3}.
1039 * @return An array of ISO 3166 two-letter country codes.
1040 */
1041 public static String[] getISOCountries() {
1042 if (isoCountries == null) {
1043 isoCountries = getISO2Table(LocaleISOData.isoCountryTable);
1044 }
1045 String[] result = new String[isoCountries.length];
1046 System.arraycopy(isoCountries, 0, result, 0, isoCountries.length);
1047 return result;
1048 }
1049
1050 /**
1051 * Returns a {@code Set} of ISO3166 country codes for the specified type.
1052 *
1053 * @param type {@link Locale.IsoCountryCode} specified ISO code type.
1054 * @see java.util.Locale.IsoCountryCode
1055 * @throws NullPointerException if type is null
1056 * @return a {@code Set} of ISO country codes for the specified type.
1057 * @since 9
1058 */
1059 public static Set<String> getISOCountries(IsoCountryCode type) {
1060 Objects.requireNonNull(type);
1061 return LocaleISOData.retrieveIsoCountryCodes(type);
1062 }
1063
1064 /**
1065 * Returns a list of all 2-letter language codes defined in ISO 639.
1066 * Can be used to create Locales.
1067 * <p>
1068 * <b>Note:</b>
1069 * <ul>
1070 * <li>ISO 639 is not a stable standard— some languages' codes have changed.
1071 * The list this function returns includes both the new and the old codes for the
1072 * languages whose codes have changed.
1073 * <li>The <code>Locale</code> class also supports language codes up to
1074 * 8 characters in length. Therefore, the list returned by this method does
1075 * not contain ALL valid codes that can be used to create Locales.
1076 * </ul>
1077 *
1078 * @return An array of ISO 639 two-letter language codes.
1079 */
1080 public static String[] getISOLanguages() {
1081 if (isoLanguages == null) {
1082 isoLanguages = getISO2Table(LocaleISOData.isoLanguageTable);
1083 }
1084 String[] result = new String[isoLanguages.length];
|