harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r698473 - in /harmony/enhanced/classlib/branches/java6/modules/sql/src: main/java/java/sql/Timestamp.java test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Date Wed, 24 Sep 2008 09:06:00 GMT
Author: qiuxx
Date: Wed Sep 24 02:05:59 2008
New Revision: 698473

URL: http://svn.apache.org/viewvc?rev=698473&view=rev
Log:
Fix java.sql.Timestamp compareTo(java.util.Date)'s defect when the parameter isn't an instance
of Timestampe. Avoid type casting when the parameter is an instance fo java.util.Date.

Modified:
    harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java
    harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java?rev=698473&r1=698472&r2=698473&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Timestamp.java
Wed Sep 24 02:05:59 2008
@@ -176,7 +176,21 @@
      */
     @Override
     public int compareTo(Date theObject) {
-        return this.compareTo((Timestamp) theObject);
+        if(theObject instanceof Timestamp){
+            return this.compareTo((Timestamp)theObject);
+        }
+        
+        if (this.getTime() < theObject.getTime()) {
+            return -1;
+        }
+        if (this.getTime() > theObject.getTime()) {
+            return 1;
+        }
+        
+        if(this.getNanos() > 0){
+            return 1;
+        }
+        return 0;
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?rev=698473&r1=698472&r2=698473&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Wed Sep 24 02:05:59 2008
@@ -599,22 +599,12 @@
             assertEquals(0, theTimestamp.compareTo(theTimestamp2));
         } // end for
 
-        Date nastyTest = new Date();
-        Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
-        try {
-            theTimestamp.compareTo(nastyTest);
-            // It throws ClassCastException in JDK 1.5.0_06 but in 1.5.0_07 it
-            // does not throw the expected exception.
-            fail("testCompareToObject: Did not get expected ClassCastException");
-        } catch (ClassCastException e) {
-            // Should get here
-            /*
-             * System.out.println("testCompareToObject: ClassCastException as
-             * expected"); System.out.println("Exception message: " +
-             * e.getMessage());
-             */
-        } // end try
-
+        Timestamp timestamp = new Timestamp(1000000);
+        Date date = new Date(1000000);
+        
+        assertEquals(0, timestamp.compareTo(date));
+        timestamp.setNanos(10);
+        assertEquals(1, timestamp.compareTo(date));
     } // end method testcompareToObject
 
     /**



Mime
View raw message