harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r450726 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Locale.java test/java/tests/api/java/util/LocaleTest.java
Date Thu, 28 Sep 2006 07:11:43 GMT
Author: pyang
Date: Thu Sep 28 00:11:42 2006
New Revision: 450726

URL: http://svn.apache.org/viewvc?view=rev&rev=450726
Log:
Apply patch for HARMONY-1514 with changes([classlib][util] Locale.getAvailableLocales returns
duplicate data)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java?view=diff&rev=450726&r1=450725&r2=450726
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Locale.java
Thu Sep 28 00:11:42 2006
@@ -278,13 +278,9 @@
 	static Locale[] find(String prefix) {
 		int last = prefix.lastIndexOf('/');
 		final String thePackage = prefix.substring(0, last + 1);
-		final String classPrefix = prefix.substring(last + 1, prefix.length());
-		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
-				return name.startsWith(classPrefix);
-			}
-		};
-		List<String> result = new ArrayList<String>();
+		int length = prefix.length();
+        final String classPrefix = prefix.substring(last + 1, length);
+		Set<String> result = new HashSet<String>();
 		StringTokenizer paths = new StringTokenizer(System.getProperty(
 				"org.apache.harmony.boot.class.path", ""), System.getProperty( //$NON-NLS-1$ //$NON-NLS-2$
 				"path.separator", ";"));  //$NON-NLS-1$//$NON-NLS-2$
@@ -293,24 +289,31 @@
 			File directory = new File(nextToken);
 			if (directory.exists()) {
 				if (directory.isDirectory()) {
-					try {
-						File newDir;
-						String path = directory.getCanonicalPath();
-						if (path.charAt(path.length() - 1) == File.separatorChar) {
-                            newDir = new File(path + thePackage);
-                        } else {
-                            newDir = new File(path + File.separatorChar
-									+ thePackage);
-                        }
-						if (newDir.isDirectory()) {
-							String[] list = newDir.list(filter);
-							for (int j = 0; j < list.length; j++) {
-                                result.add(list[j]);
+                    String path;
+                    try {
+						path = directory.getCanonicalPath();
+                    } catch (IOException e) {
+                        continue;
+                    }
+                    File newDir;
+                    if (path.charAt(path.length() - 1) == File.separatorChar) {
+                        newDir = new File(path + thePackage);
+                    } else {
+                        newDir = new File(path + File.separatorChar
+                                + thePackage);
+                    }
+                    if (newDir.isDirectory()) {
+                        String[] list = newDir.list();
+                        for (int i = 0; i < list.length; i++) {
+                            String name = list[i];
+                            if (name.startsWith(classPrefix)
+                                    && name.endsWith(".class")) { //$NON-NLS-1$
+                                result.add(name.substring(0,
+                                                name.length() - 6));
                             }
-						}
-					} catch (IOException e) {
-                        //Empty
-					}
+                        }
+                    }
+					
 				} else {
 					// Handle ZIP/JAR files.
 					try {
@@ -320,8 +323,8 @@
                             ZipEntry e = entries.nextElement();
 							String name = e.getName();
 							if (name.startsWith(prefix)
-									&& name.endsWith(".class")) {//$NON-NLS-1$
-                                result.add(name);
+                                    && name.endsWith(".class")) {//$NON-NLS-1$
+                                result.add(name.substring(last+1, name.length() - 6));
                             }
 						}
 						zip.close();
@@ -332,26 +335,26 @@
 			}
 		}
 		Locale[] locales = new Locale[result.size()];
-		for (int i = 0; i < result.size(); i++) {
-			String name = result.get(i);
-			name = name.substring(0, name.length() - 6); // remove .class
+        int i = 0;
+		for (String name: result) {
+            System.out.println(name);
 			int index = name.indexOf('_');
 			int nextIndex = name.indexOf('_', index + 1);
 			if (nextIndex == -1) {
-				locales[i] = new Locale(name
-						.substring(index + 1, name.length()), ""); //$NON-NLS-1$
-				continue;
-			}
-			String language = name.substring(index + 1, nextIndex);
-			String variant;
-			if ((index = name.indexOf('_', nextIndex + 1)) == -1) {
-				variant = ""; //$NON-NLS-1$
-				index = name.length();
-			} else {
-                variant = name.substring(index + 1, name.length());
+                locales[i++] = new Locale(name
+                        .substring(index + 1, name.length()), ""); //$NON-NLS-1$
+			}else{
+    			String language = name.substring(index + 1, nextIndex);
+    			String variant;
+    			if ((index = name.indexOf('_', nextIndex + 1)) == -1) {
+    				variant = ""; //$NON-NLS-1$
+    				index = name.length();
+    			} else {
+                    variant = name.substring(index + 1, name.length());
+                }
+    			String country = name.substring(nextIndex + 1, index);
+                locales[i++] = new Locale(language, country, variant);
             }
-			String country = name.substring(nextIndex + 1, index);
-			locales[i] = new Locale(language, country, variant);
 		}
 		return locales;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java?view=diff&rev=450726&r1=450725&r2=450726
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LocaleTest.java
Thu Sep 28 00:11:42 2006
@@ -15,7 +15,10 @@
 
 package tests.api.java.util;
 
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Locale;
+import java.util.Set;
 
 public class LocaleTest extends junit.framework.TestCase {
 
@@ -94,6 +97,10 @@
 		try {
 			Locale[] locales = Locale.getAvailableLocales();
 			assertTrue("Wrong number of locales: ", locales.length > 100);
+			// regression test for HARMONY-1514
+            // HashSet can filter duplicate locales
+            Set<Locale> localesSet = new HashSet<Locale>(Arrays.asList(locales));
+            assertEquals(localesSet.size(), locales.length);            
 		} catch (Exception e) {
 			fail("Exception during test : " + e.getMessage());
 		}



Mime
View raw message