提交 b9ed0d07 authored 作者: Thomas Mueller's avatar Thomas Mueller

Java 1.4 is no longer supported.

上级 b9a93634
......@@ -573,7 +573,7 @@ public class Data {
writeByte((byte) DOUBLE_0_1);
} else {
writeByte((byte) type);
writeVarLong(MathUtils.reverseLong(d));
writeVarLong(Long.reverse(d));
}
}
break;
......@@ -588,7 +588,7 @@ public class Data {
writeByte((byte) FLOAT_0_1);
} else {
writeByte((byte) type);
writeVarInt(MathUtils.reverseInt(f));
writeVarInt(Integer.reverse(f));
}
}
break;
......@@ -778,9 +778,9 @@ public class Data {
case DOUBLE_0_1 + 1:
return ValueDouble.get(1);
case Value.DOUBLE:
return ValueDouble.get(Double.longBitsToDouble(MathUtils.reverseLong(readVarLong())));
return ValueDouble.get(Double.longBitsToDouble(Long.reverse(readVarLong())));
case Value.FLOAT:
return ValueFloat.get(Float.intBitsToFloat(MathUtils.reverseInt(readVarInt())));
return ValueFloat.get(Float.intBitsToFloat(Integer.reverse(readVarInt())));
case Value.BLOB:
case Value.CLOB: {
int smallLen = readVarInt();
......@@ -913,7 +913,7 @@ public class Data {
if (d == ValueDouble.ZERO_BITS) {
return 1;
}
return 1 + getVarLongLen(MathUtils.reverseLong(d));
return 1 + getVarLongLen(Long.reverse(d));
}
case Value.FLOAT: {
float x = v.getFloat();
......@@ -924,7 +924,7 @@ public class Data {
if (f == ValueFloat.ZERO_BITS) {
return 1;
}
return 1 + getVarIntLen(MathUtils.reverseInt(f));
return 1 + getVarIntLen(Integer.reverse(f));
}
case Value.STRING: {
String s = v.getString();
......
......@@ -268,33 +268,6 @@ public class MathUtils {
}
}
/**
* Reverse the bits in a 32 bit integer. This code is also available in Java
* 5 using Integer.reverse, however not available yet in Retrotranslator.
* The code was taken from http://www.hackersdelight.org - reverse.c
*
* @param x the original value
* @return the value with reversed bits
*/
public static int reverseInt(int x) {
x = (x & 0x55555555) << 1 | (x >>> 1) & 0x55555555;
x = (x & 0x33333333) << 2 | (x >>> 2) & 0x33333333;
x = (x & 0x0f0f0f0f) << 4 | (x >>> 4) & 0x0f0f0f0f;
x = (x << 24) | ((x & 0xff00) << 8) | ((x >>> 8) & 0xff00) | (x >>> 24);
return x;
}
/**
* Reverse the bits in a 64 bit long. This code is also available in Java 5
* using Long.reverse, however not available yet in Retrotranslator.
*
* @param x the original value
* @return the value with reversed bits
*/
public static long reverseLong(long x) {
return (reverseInt((int) (x >>> 32L)) & 0xffffffffL) ^ (((long) reverseInt((int) x)) << 32L);
}
/**
* Compare two values. Returns -1 if the first value is smaller, 1 if bigger,
* and 0 if equal.
......
......@@ -10,7 +10,6 @@ import java.math.BigInteger;
import java.util.Random;
import org.h2.test.TestBase;
import org.h2.test.utils.AssertThrows;
import org.h2.util.MathUtils;
/**
* Tests math utility methods.
......@@ -32,35 +31,35 @@ public class TestMathUtils extends TestBase {
}
private void testReverse() {
assertEquals(Integer.reverse(0), MathUtils.reverseInt(0));
assertEquals(Integer.reverse(Integer.MAX_VALUE), MathUtils.reverseInt(Integer.MAX_VALUE));
assertEquals(Integer.reverse(Integer.MIN_VALUE), MathUtils.reverseInt(Integer.MIN_VALUE));
assertEquals(Long.reverse(0), MathUtils.reverseLong(0L));
assertEquals(Long.reverse(Long.MAX_VALUE), MathUtils.reverseLong(Long.MAX_VALUE));
assertEquals(Long.reverse(Long.MIN_VALUE), MathUtils.reverseLong(Long.MIN_VALUE));
assertEquals(Integer.reverse(0), Integer.reverse(0));
assertEquals(Integer.reverse(Integer.MAX_VALUE), Integer.reverse(Integer.MAX_VALUE));
assertEquals(Integer.reverse(Integer.MIN_VALUE), Integer.reverse(Integer.MIN_VALUE));
assertEquals(Long.reverse(0), Long.reverse(0L));
assertEquals(Long.reverse(Long.MAX_VALUE), Long.reverse(Long.MAX_VALUE));
assertEquals(Long.reverse(Long.MIN_VALUE), Long.reverse(Long.MIN_VALUE));
for (int i = Integer.MIN_VALUE; i < 0; i += 1019) {
int x = MathUtils.reverseInt(i);
int x = Integer.reverse(i);
assertEquals(Integer.reverse(i), x);
}
for (int i = 0; i > 0; i += 1019) {
int x = MathUtils.reverseInt(i);
int x = Integer.reverse(i);
assertEquals(Integer.reverse(i), x);
}
for (long i = Long.MIN_VALUE; i < 0; i += 1018764321251L) {
long x = MathUtils.reverseLong(i);
long x = Long.reverse(i);
assertEquals(Long.reverse(i), x);
}
for (long i = 0; i > 0; i += 1018764321251L) {
long x = MathUtils.reverseLong(i);
long x = Long.reverse(i);
assertEquals(Long.reverse(i), x);
}
Random random = new Random(10);
for (int i = 0; i < 1000000; i++) {
long x = random.nextLong();
long r = MathUtils.reverseLong(x);
long r = Long.reverse(x);
assertEquals(Long.reverse(x), r);
int y = random.nextInt();
int s = MathUtils.reverseInt(y);
int s = Integer.reverse(y);
assertEquals(Integer.reverse(y), s);
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论