Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 6652 invoked from network); 15 Mar 2009 02:50:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Mar 2009 02:50:41 -0000 Received: (qmail 93544 invoked by uid 500); 15 Mar 2009 02:50:40 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 93493 invoked by uid 500); 15 Mar 2009 02:50:40 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 93484 invoked by uid 99); 15 Mar 2009 02:50:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Mar 2009 19:50:40 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Mar 2009 02:50:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 47BFC2388C01; Sun, 15 Mar 2009 02:50:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r754603 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/LocaleUtils.java test/org/apache/commons/lang/LocaleUtilsTest.java Date: Sun, 15 Mar 2009 02:50:19 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090315025019.47BFC2388C01@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Sun Mar 15 02:50:18 2009 New Revision: 754603 URL: http://svn.apache.org/viewvc?rev=754603&view=rev Log: Generify LocaleUtils and its Test class Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/LocaleUtils.java commons/proper/lang/trunk/src/test/org/apache/commons/lang/LocaleUtilsTest.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/LocaleUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/LocaleUtils.java?rev=754603&r1=754602&r2=754603&view=diff ============================================================================== --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/LocaleUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/LocaleUtils.java Sun Mar 15 02:50:18 2009 @@ -40,16 +40,16 @@ 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 @@ * @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 @@ * @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 @@ * * @return the unmodifiable list of available locales */ - public static List availableLocaleList() { + public static List availableLocaleList() { return cAvailableLocaleList; } @@ -206,10 +206,10 @@ * * @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 @@ * @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 @@ } langs = Collections.unmodifiableList(langs); } else { - langs = Collections.EMPTY_LIST; + langs = Collections.emptyList(); } cLanguagesByCountry.put(countryCode, langs); //syncd } @@ -269,14 +269,14 @@ * @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 @@ } countries = Collections.unmodifiableList(countries); } else { - countries = Collections.EMPTY_LIST; + countries = Collections.emptyList(); } cCountriesByLanguage.put(languageCode, countries); //syncd } Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/LocaleUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LocaleUtilsTest.java?rev=754603&r1=754602&r2=754603&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/org/apache/commons/lang/LocaleUtilsTest.java (original) +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/LocaleUtilsTest.java Sun Mar 15 02:50:18 2009 @@ -89,7 +89,7 @@ */ 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 @@ * @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 @@ * 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 @@ * 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 @@ * 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 @@ * @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 @@ * @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 @@ /** * @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) {} }