commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
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 GMT
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<Locale> cAvailableLocaleList;
     /** Unmodifiable set of available locales. */
     //@GuardedBy("this")
-    private static Set cAvailableLocaleSet; // lazily created by availableLocaleSet()
+    private static Set<Locale> 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<String, List<Locale>> cLanguagesByCountry = Collections.synchronizedMap(new
HashMap<String, List<Locale>>());
     /** Unmodifiable map of country locales by language. */
-    private static final Map cCountriesByLanguage = Collections.synchronizedMap(new HashMap());
+    private static final Map<String, List<Locale>> cCountriesByLanguage = Collections.synchronizedMap(new
HashMap<String, List<Locale>>());
     static {
-        List list = Arrays.asList(Locale.getAvailableLocales());
+        List<Locale> 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<Locale> 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<Locale> localeLookupList(Locale locale, Locale defaultLocale)
{
+        List<Locale> list = new ArrayList<Locale>(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<Locale> 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<Locale> availableLocaleSet() {
+        Set<Locale> set = cAvailableLocaleSet;
         if (set == null) {
-            set = new HashSet(availableLocaleList());
+            set = new HashSet<Locale>(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<Locale> languagesByCountry(String countryCode) {
+        List<Locale> langs = cLanguagesByCountry.get(countryCode);  //syncd
         if (langs == null) {
             if (countryCode != null) {
-                langs = new ArrayList();
-                List locales = availableLocaleList();
+                langs = new ArrayList<Locale>();
+                List<Locale> 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<Locale> countriesByLanguage(String languageCode) {
+        List<Locale> countries = cCountriesByLanguage.get(languageCode);  //syncd
         if (countries == null) {
             if (languageCode != null) {
-                countries = new ArrayList();
-                List locales = availableLocaleList();
+                countries = new ArrayList<Locale>();
+                List<Locale> 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<Locale> 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<Locale> list = LocaleUtils.availableLocaleList();
+        List<Locale> list2 = LocaleUtils.availableLocaleList();
         assertNotNull(list);
         assertSame(list, list2);
         assertUnmodifiableCollection(list);
         
         Locale[] jdkLocaleArray = Locale.getAvailableLocales();
-        List jdkLocaleList = Arrays.asList(jdkLocaleArray);
+        List<Locale> 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<Locale> set = LocaleUtils.availableLocaleSet();
+        Set<Locale> 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<Locale> jdkLocaleList = Arrays.asList(jdkLocaleArray);
+        Set<Locale> jdkLocaleSet = new HashSet<Locale>(jdkLocaleList);
         assertEquals(jdkLocaleSet, set);
     }
 
@@ -380,7 +380,7 @@
      * Test availableLocaleSet() method.
      */
     public void testIsAvailableLocale() {
-        Set set = LocaleUtils.availableLocaleSet();
+        Set<Locale> 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<Locale> list = LocaleUtils.languagesByCountry(country);
+        List<Locale> 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<Locale> 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<Locale> list = LocaleUtils.countriesByLanguage(language);
+        List<Locale> 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<Locale> 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) {}
     }



Mime
View raw message