Enum Class LocaleCode

java.lang.Object
java.lang.Enum<LocaleCode>
com.luna.common.i18n.LocaleCode
All Implemented Interfaces:
Serializable, Comparable<LocaleCode>, java.lang.constant.Constable

public enum LocaleCode extends Enum<LocaleCode>
Locale code.

The list of the enum entries was generated based on the output from Locale.getAvailableLocales() of Java SE 7, but locales whose format do not match either 'xx' or 'xx-XX' were excluded.

 // List all the locale codes.
 for (LocaleCode code : LocaleCode.values())
 {
     String language = code.getLanguage().getName();
     String country  = code.getCountry() != null
                     ? code.getCountry().getName() : null;

     // For example, "[de-DE] German, Germany" is printed.
     System.out.format("[%s] %s, %s\n", code, language, country);
 }

 // Get a LocaleCode instance in various ways.
 LocaleCode code;
 code = LocaleCode.getByCode("en-GB");
 code = LocaleCode.getByCode("es", "ES");
 code = LocaleCode.getByLocale(new Locale("pt", "BR"));

 // Convert to a Locale instance.
 Locale locale = LocaleCode.en.toLocale();

 // toLocale() of some LocaleCode instances does not create
 // a new Locale instance but returns a static variable of
 // Locale class instead. See toLocale() for details.
 if (locale == Locale.ENGLISH)
 {
     System.out.println("Locale.en.toLocale() returned Locale.ENGLISH");
 }

 // Get a list of LocaleCode instances whose language is Arabic.
 List<LocaleCode> list = LocaleCode.getByLanguage(LanguageCode.ar);

 // Get a list of LocaleCode instances whose country is Switzerland.
 list = LocaleCode.getByCountry(CountryCode.CH);
 
Author:
Takahiko Kawasaki