Improve Long.hashCode to follow correct semantics.
PiperOrigin-RevId: 318960075
Change-Id: I11b65f96a10b1ddb6617d9b2ff3b1ed5bed506cc
diff --git a/user/super/com/google/gwt/emul/java/lang/Long.java b/user/super/com/google/gwt/emul/java/lang/Long.java
index 0654fa4..b4e8c9b 100644
--- a/user/super/com/google/gwt/emul/java/lang/Long.java
+++ b/user/super/com/google/gwt/emul/java/lang/Long.java
@@ -15,14 +15,10 @@
*/
package java.lang;
-/**
- * Wraps a primitive <code>long</code> as an object.
- */
+/** Wraps a primitive <code>long</code> as an object. */
public final class Long extends Number implements Comparable<Long> {
- /**
- * Use nested class to avoid clinit on outer.
- */
+ /** Use nested class to avoid clinit on outer. */
static class BoxedValues {
// Box values according to JLS - between -128 and 127
static Long[] boxedValues = new Long[256];
@@ -56,7 +52,9 @@
}
public static int hashCode(long l) {
- return (int) l;
+ int high = (int) (l >>> 32);
+ int low = (int) l;
+ return high ^ low;
}
public static long highestOneBit(long i) {
@@ -109,15 +107,13 @@
public static long reverse(long i) {
int high = (int) (i >>> 32);
int low = (int) i;
- return ((long) Integer.reverse(low) << 32)
- | (Integer.reverse(high) & 0xffffffffL);
+ return ((long) Integer.reverse(low) << 32) | (Integer.reverse(high) & 0xffffffffL);
}
public static long reverseBytes(long i) {
int high = (int) (i >>> 32);
int low = (int) i;
- return ((long) Integer.reverseBytes(low) << 32)
- | (Integer.reverseBytes(high) & 0xffffffffL);
+ return ((long) Integer.reverseBytes(low) << 32) | (Integer.reverseBytes(high) & 0xffffffffL);
}
public static long rotateLeft(long i, int distance) {
diff --git a/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java b/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java
index aa1be65..f6a344b 100644
--- a/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java
+++ b/user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java
@@ -16,15 +16,13 @@
package com.google.gwt.emultest.java.sql;
import com.google.gwt.junit.client.GWTTestCase;
-
import java.sql.Date;
/**
- * Tests {@link java.sql.Date}. We assume that the underlying
- * {@link java.util.Date} implementation is correct and concentrate only on the
- * differences between the two.
+ * Tests {@link java.sql.Date}. We assume that the underlying {@link java.util.Date} implementation
+ * is correct and concentrate only on the differences between the two.
*/
-@SuppressWarnings("deprecation")
+@SuppressWarnings({"deprecation", "DoNotCall"})
public class SqlDateTest extends GWTTestCase {
/**