diff --git a/src/java/org/apache/commons/lang/LocaleUtils.java b/src/java/org/apache/commons/lang/LocaleUtils.java index a941fa8ef..8635b2e8f 100644 --- a/src/java/org/apache/commons/lang/LocaleUtils.java +++ b/src/java/org/apache/commons/lang/LocaleUtils.java @@ -40,16 +40,16 @@ import java.util.Set; public class LocaleUtils { /** Unmodifiable list of available locales. */ - private static final List cAvailableLocaleList; + private static final List cAvailableLocaleList; /** Unmodifiable set of available locales. */ //@GuardedBy("this") - private static Set cAvailableLocaleSet; // lazily created by availableLocaleSet() + private static Set cAvailableLocaleSet; // lazily created by availableLocaleSet() /** Unmodifiable map of language locales by country. */ - private static final Map cLanguagesByCountry = Collections.synchronizedMap(new HashMap()); + private static final Map> cLanguagesByCountry = Collections.synchronizedMap(new HashMap>()); /** Unmodifiable map of country locales by language. */ - private static final Map cCountriesByLanguage = Collections.synchronizedMap(new HashMap()); + private static final Map> cCountriesByLanguage = Collections.synchronizedMap(new HashMap>()); static { - List list = Arrays.asList(Locale.getAvailableLocales()); + List list = Arrays.asList(Locale.getAvailableLocales()); cAvailableLocaleList = Collections.unmodifiableList(list); } @@ -143,7 +143,7 @@ public class LocaleUtils { * @param locale the locale to start from * @return the unmodifiable list of Locale objects, 0 being locale, never null */ - public static List localeLookupList(Locale locale) { + public static List localeLookupList(Locale locale) { return localeLookupList(locale, locale); } @@ -165,8 +165,8 @@ public class LocaleUtils { * @param defaultLocale the default locale to use if no other is found * @return the unmodifiable list of Locale objects, 0 being locale, never null */ - public static List localeLookupList(Locale locale, Locale defaultLocale) { - List list = new ArrayList(4); + public static List localeLookupList(Locale locale, Locale defaultLocale) { + List list = new ArrayList(4); if (locale != null) { list.add(locale); if (locale.getVariant().length() > 0) { @@ -192,7 +192,7 @@ public class LocaleUtils { * * @return the unmodifiable list of available locales */ - public static List availableLocaleList() { + public static List availableLocaleList() { return cAvailableLocaleList; } @@ -206,10 +206,10 @@ public class LocaleUtils { * * @return the unmodifiable set of available locales */ - public static synchronized Set availableLocaleSet() { - Set set = cAvailableLocaleSet; + public static synchronized Set availableLocaleSet() { + Set set = cAvailableLocaleSet; if (set == null) { - set = new HashSet(availableLocaleList()); + set = new HashSet(availableLocaleList()); set = Collections.unmodifiableSet(set); cAvailableLocaleSet = set; } @@ -237,14 +237,14 @@ public class LocaleUtils { * @param countryCode the 2 letter country code, null returns empty * @return an unmodifiable List of Locale objects, never null */ - public static List languagesByCountry(String countryCode) { - List langs = (List) cLanguagesByCountry.get(countryCode); //syncd + public static List languagesByCountry(String countryCode) { + List langs = cLanguagesByCountry.get(countryCode); //syncd if (langs == null) { if (countryCode != null) { - langs = new ArrayList(); - List locales = availableLocaleList(); + langs = new ArrayList(); + List locales = availableLocaleList(); for (int i = 0; i < locales.size(); i++) { - Locale locale = (Locale) locales.get(i); + Locale locale = locales.get(i); if (countryCode.equals(locale.getCountry()) && locale.getVariant().length() == 0) { langs.add(locale); @@ -252,7 +252,7 @@ public class LocaleUtils { } langs = Collections.unmodifiableList(langs); } else { - langs = Collections.EMPTY_LIST; + langs = Collections.emptyList(); } cLanguagesByCountry.put(countryCode, langs); //syncd } @@ -269,14 +269,14 @@ public class LocaleUtils { * @param languageCode the 2 letter language code, null returns empty * @return an unmodifiable List of Locale objects, never null */ - public static List countriesByLanguage(String languageCode) { - List countries = (List) cCountriesByLanguage.get(languageCode); //syncd + public static List countriesByLanguage(String languageCode) { + List countries = cCountriesByLanguage.get(languageCode); //syncd if (countries == null) { if (languageCode != null) { - countries = new ArrayList(); - List locales = availableLocaleList(); + countries = new ArrayList(); + List locales = availableLocaleList(); for (int i = 0; i < locales.size(); i++) { - Locale locale = (Locale) locales.get(i); + Locale locale = locales.get(i); if (languageCode.equals(locale.getLanguage()) && locale.getCountry().length() != 0 && locale.getVariant().length() == 0) { @@ -285,7 +285,7 @@ public class LocaleUtils { } countries = Collections.unmodifiableList(countries); } else { - countries = Collections.EMPTY_LIST; + countries = Collections.emptyList(); } cCountriesByLanguage.put(languageCode, countries); //syncd } diff --git a/src/test/org/apache/commons/lang/LocaleUtilsTest.java b/src/test/org/apache/commons/lang/LocaleUtilsTest.java index 620a81b24..b4379b5da 100644 --- a/src/test/org/apache/commons/lang/LocaleUtilsTest.java +++ b/src/test/org/apache/commons/lang/LocaleUtilsTest.java @@ -89,7 +89,7 @@ public class LocaleUtilsTest extends TestCase { */ public void testConstructor() { assertNotNull(new LocaleUtils()); - Constructor[] cons = LocaleUtils.class.getDeclaredConstructors(); + Constructor[] cons = LocaleUtils.class.getDeclaredConstructors(); assertEquals(1, cons.length); assertEquals(true, Modifier.isPublic(cons[0].getModifiers())); assertEquals(true, Modifier.isPublic(LocaleUtils.class.getModifiers())); @@ -260,7 +260,7 @@ public class LocaleUtilsTest extends TestCase { * @param expected expected results */ private void assertLocaleLookupList(Locale locale, Locale defaultLocale, Locale[] expected) { - List localeList = defaultLocale == null ? + List localeList = defaultLocale == null ? LocaleUtils.localeLookupList(locale) : LocaleUtils.localeLookupList(locale, defaultLocale); @@ -347,14 +347,14 @@ public class LocaleUtilsTest extends TestCase { * Test availableLocaleList() method. */ public void testAvailableLocaleList() { - List list = LocaleUtils.availableLocaleList(); - List list2 = LocaleUtils.availableLocaleList(); + List list = LocaleUtils.availableLocaleList(); + List list2 = LocaleUtils.availableLocaleList(); assertNotNull(list); assertSame(list, list2); assertUnmodifiableCollection(list); Locale[] jdkLocaleArray = Locale.getAvailableLocales(); - List jdkLocaleList = Arrays.asList(jdkLocaleArray); + List jdkLocaleList = Arrays.asList(jdkLocaleArray); assertEquals(jdkLocaleList, list); } @@ -363,15 +363,15 @@ public class LocaleUtilsTest extends TestCase { * Test availableLocaleSet() method. */ public void testAvailableLocaleSet() { - Set set = LocaleUtils.availableLocaleSet(); - Set set2 = LocaleUtils.availableLocaleSet(); + Set set = LocaleUtils.availableLocaleSet(); + Set set2 = LocaleUtils.availableLocaleSet(); assertNotNull(set); assertSame(set, set2); assertUnmodifiableCollection(set); Locale[] jdkLocaleArray = Locale.getAvailableLocales(); - List jdkLocaleList = Arrays.asList(jdkLocaleArray); - Set jdkLocaleSet = new HashSet(jdkLocaleList); + List jdkLocaleList = Arrays.asList(jdkLocaleArray); + Set jdkLocaleSet = new HashSet(jdkLocaleList); assertEquals(jdkLocaleSet, set); } @@ -380,7 +380,7 @@ public class LocaleUtilsTest extends TestCase { * Test availableLocaleSet() method. */ public void testIsAvailableLocale() { - Set set = LocaleUtils.availableLocaleSet(); + Set set = LocaleUtils.availableLocaleSet(); assertEquals(set.contains(LOCALE_EN), LocaleUtils.isAvailableLocale(LOCALE_EN)); assertEquals(set.contains(LOCALE_EN_US), LocaleUtils.isAvailableLocale(LOCALE_EN_US)); assertEquals(set.contains(LOCALE_EN_US_ZZZZ), LocaleUtils.isAvailableLocale(LOCALE_EN_US_ZZZZ)); @@ -401,17 +401,17 @@ public class LocaleUtilsTest extends TestCase { * @param languages array of languages that should be returned */ private void assertLanguageByCountry(String country, String[] languages) { - List list = LocaleUtils.languagesByCountry(country); - List list2 = LocaleUtils.languagesByCountry(country); + List list = LocaleUtils.languagesByCountry(country); + List list2 = LocaleUtils.languagesByCountry(country); assertNotNull(list); assertSame(list, list2); //search through langauges for (int i = 0; i < languages.length; i++) { - Iterator iterator = list.iterator(); + Iterator iterator = list.iterator(); boolean found = false; // see if it was returned by the set while (iterator.hasNext()) { - Locale locale = (Locale) iterator.next(); + Locale locale = iterator.next(); // should have an en empty variant assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0); @@ -451,17 +451,17 @@ public class LocaleUtilsTest extends TestCase { * @param countries array of countries that should be returned */ private void assertCountriesByLanguage(String language, String[] countries) { - List list = LocaleUtils.countriesByLanguage(language); - List list2 = LocaleUtils.countriesByLanguage(language); + List list = LocaleUtils.countriesByLanguage(language); + List list2 = LocaleUtils.countriesByLanguage(language); assertNotNull(list); assertSame(list, list2); //search through langauges for (int i = 0; i < countries.length; i++) { - Iterator iterator = list.iterator(); + Iterator iterator = list.iterator(); boolean found = false; // see if it was returned by the set while (iterator.hasNext()) { - Locale locale = (Locale) iterator.next(); + Locale locale = iterator.next(); // should have an en empty variant assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0); @@ -492,9 +492,9 @@ public class LocaleUtilsTest extends TestCase { /** * @param coll the collection to check */ - private static void assertUnmodifiableCollection(Collection coll) { + private static void assertUnmodifiableCollection(Collection coll) { try { - coll.add("Unmodifiable"); + coll.add(null); fail(); } catch (UnsupportedOperationException ex) {} }