harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r470343 - in /incubator/harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/Timestamp.java test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Date Thu, 02 Nov 2006 12:09:30 GMT
Author: pyang
Date: Thu Nov  2 04:09:29 2006
New Revision: 470343

URL: http://svn.apache.org/viewvc?view=rev&rev=470343
Log:
Apply patch for HARMONY-1703 ([classlib][sql] The behavior of java.sql.TimeStamp.compareTo(TimeStamp)
is different from RI)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java?view=diff&rev=470343&r1=470342&r2=470343
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
Thu Nov  2 04:09:29 2006
@@ -188,13 +188,19 @@
      *         value >0 if this Timestamp object is after the supplied Timestamp
      */
     public int compareTo(Timestamp theTimestamp) {
-        if (this.before(theTimestamp)) {
-            return -1;
-        } else if (this.after(theTimestamp)) {
-            return +1;
-        } else {
-            return 0;
+        int result = super.compareTo(theTimestamp);
+        if (result == 0) {
+            int thisNano = this.getNanos();
+            int thatNano = theTimestamp.getNanos();
+            if (thisNano > thatNano) {
+                return 1;
+            } else if (thisNano == thatNano) {
+                return 0;
+            } else {
+                return -1;
+            }
         }
+        return result;
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java?view=diff&rev=470343&r1=470342&r2=470343
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
Thu Nov  2 04:09:29 2006
@@ -525,6 +525,24 @@
 			assertTrue(theTimestamp.compareTo(theTest2) < 0);
 			assertEquals(0, theTimestamp.compareTo(theTimestamp2));
 		} // end for
+        
+        Timestamp t1 = new Timestamp(-1L);
+        Timestamp t2 = new Timestamp(-1L);
+        
+        t1.setTime(Long.MIN_VALUE);
+        t2.setDate(Integer.MIN_VALUE);
+        assertEquals(1, t1.compareTo(t2));
+        assertEquals(-1, t2.compareTo(t1));
+
+        t1.setTime(Long.MAX_VALUE);
+        t2.setTime(Long.MAX_VALUE - 1);
+        assertEquals(1, t1.compareTo(t2));
+        assertEquals(-1, t2.compareTo(t1));
+
+        t1.setTime(Integer.MAX_VALUE);
+        t2.setTime(Integer.MAX_VALUE);
+        assertEquals(0, t1.compareTo(t2));
+        assertEquals(0, t2.compareTo(t1));
 
 	} // end method testcompareToTimestamp
 



Mime
View raw message