You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/05/08 13:17:47 UTC

svn commit: r405018 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/File.java test/java/tests/api/java/io/FileTest.java

Author: tellison
Date: Mon May  8 04:17:45 2006
New Revision: 405018

URL: http://svn.apache.org/viewcvs?rev=405018&view=rev
Log:
Added generic declaration for File's Comparable interface.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?rev=405018&r1=405017&r2=405018&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java Mon May  8 04:17:45 2006
@@ -38,7 +38,7 @@
  * @see java.lang.Comparable
  */
 
-public class File implements Serializable, Comparable {
+public class File implements Serializable, Comparable<File> {
 	private static final long serialVersionUID = 301077366599181567L;
 
 	private String path;
@@ -322,35 +322,21 @@
 	}
 
 	/**
-	 * Compare this abstract File with another returning the relative position.
-	 * 
-	 * @param another
-	 *            an object to compare the receiver to
-	 * @return an int determined by comparing the two paths.
-	 * 
-	 * @throws ClassCastException
-	 *             if the argument is not a File
-	 */
-	public int compareTo(Object another) {
-		if (this.getClass() == another.getClass())
-			return this.getPath().compareTo(((File) another).getPath());
-		throw new ClassCastException(org.apache.harmony.luni.util.Msg.getString("K0069")); //$NON-NLS-1$
-	}
-
-	/**
-	 * Compare this abstract File with another returning the relative position.
-	 * 
-	 * @param another
-	 *            a File to compare the receiver to
-	 * @return an int determined by comparing the two paths.
-	 */
-	public int compareTo(File another) {
-		if (caseSensitive) {
-			return this.getPath().compareTo(another.getPath());
-		}
-		return this.getPath().compareToIgnoreCase(another.getPath());
-
-	}
+     * Answers the relative sort ordering of paths for the receiver and given
+     * argument. The ordering is platform dependent.
+     * 
+     * @param another
+     *            a File to compare the receiver to
+     * @return an int determined by comparing the two paths. The meanning is
+     *         described in the Comparable interface.
+     * @see Comparable
+     */
+    public int compareTo(File another) {
+        if (caseSensitive) {
+            return this.getPath().compareTo(another.getPath());
+        }
+        return this.getPath().compareToIgnoreCase(another.getPath());
+    }
 
 	/**
 	 * Deletes the file specified by this File. Directories must be empty before

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java?rev=405018&r1=405017&r2=405018&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FileTest.java Mon May  8 04:17:45 2006
@@ -309,58 +309,17 @@
 	/**
 	 * @tests java.io.File#compareTo(java.io.File)
 	 */
-	public void test_compareToLjava_io_File() {
-		// Test for method int java.io.File.compareTo(java.lang.Object)
-		File f1 = new File("thisFile.tst");
-		File f2 = new File("thisFile.tst");
-		File f3 = new File("thatFile.tst");
-
-		String notAFile = "notAFile.tst";
-		assertEquals("Equal files did not answer zero for compareTo", 0, f1
-				.compareTo(f2));
-		assertTrue("f3.compareTo(f1) did not result in value < 0", f3
-				.compareTo(f1) < 0);
-		assertTrue("f1.compareTo(f3) did not result in vale > 0", f1
-				.compareTo(f3) > 0);
-		try {
-			f1.compareTo(notAFile);
-			fail(
-					"ClassCastException not thrown when comparing a file to a string");
-		} catch (ClassCastException e) {
-		}
-
-		f3 = new File("ThisFile.tst");
-		boolean onWindows = File.separatorChar == '\\';
-		boolean onUnix = File.separatorChar == '/';
-		if (onWindows) {
-			assertEquals("Files Should Return Equal.", 0, f1.compareTo(f3));
-		} else if (onUnix) {
-			assertTrue("Files Should NOT Return Equal.", f1.compareTo(f3) != 0);
-		}
-	}
-
-	/**
-	 * @tests java.io.File#compareTo(java.lang.Object)
-	 */
-	public void test_compareToLjava_lang_Object() {
-		// Test for method int java.io.File.compareTo(java.lang.Object)
-		File f1 = new File("thisFile.file");
-		File f2 = new File("thisFile.file");
-		File f3 = new File("thatFile.file");
-		String notAFile = "notAFile.file";
-		assertEquals("Equal files did not answer zero for compareTo", 0, f1
-				.compareTo((Object) f2));
-		assertTrue("f3.compareTo(f1) did not result in value < 0", f3
-				.compareTo((Object) f1) < 0);
-		assertTrue("f1.compareTo(f3) did not result in vale > 0", f1
-				.compareTo((Object) f3) > 0);
-		try {
-			f1.compareTo(notAFile);
-			fail(
-					"ClassCastException not thown when comparing a file to a string");
-		} catch (ClassCastException e) {
-		}
-	}
+    public void test_compareToLjava_lang_Object() {
+        File f1 = new File("thisFile.file");
+        File f2 = new File("thisFile.file");
+        File f3 = new File("thatFile.file");
+        assertEquals("Equal files did not answer zero for compareTo", 0, f1
+                .compareTo(f2));
+        assertTrue("f3.compareTo(f1) did not result in value < 0", f3
+                .compareTo(f1) < 0);
+        assertTrue("f1.compareTo(f3) did not result in vale > 0", f1
+                .compareTo(f3) > 0);
+    }
 
 	/**
 	 * @tests java.io.File#createNewFile()