[#6922] Upgrade the jOOU dependency to version 0.9.3
This commit is contained in:
parent
1e77b59522
commit
65adb5928a
@ -23,6 +23,7 @@ import java.math.BigInteger;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
* @author Ed Schaller
|
||||
* @author Jens Nerche
|
||||
*/
|
||||
public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
|
||||
@ -48,6 +49,18 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
*/
|
||||
public static final short MAX_VALUE = 0xff;
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value an <code>unsigned byte</code> can
|
||||
* have as UByte, 0.
|
||||
*/
|
||||
public static final UByte MIN = valueOf(0x00);
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an <code>unsigned byte</code> can
|
||||
* have as UByte, 2<sup>8</sup>-1.
|
||||
*/
|
||||
public static final UByte MAX = valueOf(0xff);
|
||||
|
||||
/**
|
||||
* The value modelling the content of this <code>unsigned byte</code>
|
||||
*/
|
||||
@ -63,6 +76,7 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
|
||||
for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++)
|
||||
ret[i & MAX_VALUE] = new UByte((byte) i);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -178,9 +192,9 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
* @throws NumberFormatException if value is out of range
|
||||
*/
|
||||
private static short rangeCheck(short value) throws NumberFormatException {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE) {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE)
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -192,9 +206,9 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
* @throws NumberFormatException if value is out of range
|
||||
*/
|
||||
private static short rangeCheck(int value) throws NumberFormatException {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE) {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE)
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
}
|
||||
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@ -206,9 +220,9 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
* @throws NumberFormatException if value is out of range
|
||||
*/
|
||||
private static short rangeCheck(long value) throws NumberFormatException {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE) {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE)
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
}
|
||||
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
@ -253,9 +267,8 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj instanceof UByte) {
|
||||
if (obj instanceof UByte)
|
||||
return value == ((UByte) obj).value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -274,4 +287,20 @@ public final class UByte extends UNumber implements Comparable<UByte> {
|
||||
public BigInteger toBigInteger() {
|
||||
return BigInteger.valueOf(value);
|
||||
}
|
||||
|
||||
public UByte add(UByte val) throws NumberFormatException {
|
||||
return valueOf(value + val.value);
|
||||
}
|
||||
|
||||
public UByte add(int val) throws NumberFormatException {
|
||||
return valueOf(value + val);
|
||||
}
|
||||
|
||||
public UByte subtract(final UByte val) {
|
||||
return valueOf(value - val.value);
|
||||
}
|
||||
|
||||
public UByte subtract(final int val) {
|
||||
return valueOf(value - val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,8 +23,10 @@ import java.math.BigInteger;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
* @author Ed Schaller
|
||||
* @author Jens Nerche
|
||||
*/
|
||||
public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
|
||||
private static final Class<UInteger> CLASS = UInteger.class;
|
||||
private static final String CLASS_NAME = CLASS.getName();
|
||||
|
||||
@ -60,6 +62,18 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
*/
|
||||
public static final long MAX_VALUE = 0xffffffffL;
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value an <code>unsigned int</code> can
|
||||
* have as UInteger, 0.
|
||||
*/
|
||||
public static final UInteger MIN = valueOf(MIN_VALUE);
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an <code>unsigned int</code> can
|
||||
* have as UInteger, 2<sup>32</sup>-1.
|
||||
*/
|
||||
public static final UInteger MAX = valueOf(MAX_VALUE);
|
||||
|
||||
/**
|
||||
* The value modelling the content of this <code>unsigned int</code>
|
||||
*/
|
||||
@ -89,11 +103,12 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
}
|
||||
if (prop == null)
|
||||
return DEFAULT_PRECACHE_SIZE;
|
||||
if (prop.length() <= 0) {
|
||||
// empty value
|
||||
// FIXME: should we log this somewhere?
|
||||
|
||||
// empty value
|
||||
// FIXME: should we log this somewhere?
|
||||
if (prop.length() <= 0)
|
||||
return DEFAULT_PRECACHE_SIZE;
|
||||
}
|
||||
|
||||
try {
|
||||
propParsed = Long.parseLong(prop);
|
||||
}
|
||||
@ -102,13 +117,15 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
// FIXME: should we log this somewhere?
|
||||
return DEFAULT_PRECACHE_SIZE;
|
||||
}
|
||||
|
||||
// treat negative value as no cache...
|
||||
if (propParsed < 0)
|
||||
return 0;
|
||||
if (propParsed > Integer.MAX_VALUE) {
|
||||
// FIXME: should we log this somewhere
|
||||
|
||||
// FIXME: should we log this somewhere?
|
||||
if (propParsed > Integer.MAX_VALUE)
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
return (int) propParsed;
|
||||
}
|
||||
|
||||
@ -123,9 +140,11 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
|
||||
if (precacheSize <= 0)
|
||||
return null;
|
||||
|
||||
ret = new UInteger[precacheSize];
|
||||
for (int i = 0; i < precacheSize; i++)
|
||||
ret[i] = new UInteger(i);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -135,7 +154,7 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
* constructor without unnecessary value checks.
|
||||
*
|
||||
* @param value The value to wrap
|
||||
* @param unused Unused paramater to distinguish between this and the
|
||||
* @param unused Unused parameter to distinguish between this and the
|
||||
* deprecated public constructor.
|
||||
*/
|
||||
private UInteger(long value, boolean unused) {
|
||||
@ -151,6 +170,7 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
private static UInteger getCached(long value) {
|
||||
if (VALUES != null && value < VALUES.length)
|
||||
return VALUES[(int) value];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -162,6 +182,7 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
|
||||
if ((cached = getCached(value)) != null)
|
||||
return cached;
|
||||
|
||||
return new UInteger(value, true);
|
||||
}
|
||||
|
||||
@ -231,9 +252,9 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
* @throws NumberFormatException if value is out of range
|
||||
*/
|
||||
private static long rangeCheck(long value) throws NumberFormatException {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE) {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE)
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -251,6 +272,7 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
rangeCheck(value);
|
||||
if ((cached = getCached(value)) != null)
|
||||
return cached;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -288,9 +310,8 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj instanceof UInteger) {
|
||||
if (obj instanceof UInteger)
|
||||
return value == ((UInteger) obj).value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -304,4 +325,20 @@ public final class UInteger extends UNumber implements Comparable<UInteger> {
|
||||
public int compareTo(UInteger o) {
|
||||
return (value < o.value ? -1 : (value == o.value ? 0 : 1));
|
||||
}
|
||||
|
||||
public UInteger add(final UInteger val) {
|
||||
return valueOf(value + val.value);
|
||||
}
|
||||
|
||||
public UInteger add(final int val) {
|
||||
return valueOf(value + val);
|
||||
}
|
||||
|
||||
public UInteger subtract(final UInteger val) {
|
||||
return valueOf(value - val.value);
|
||||
}
|
||||
|
||||
public UInteger subtract(final int val) {
|
||||
return valueOf(value - val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ import java.math.BigInteger;
|
||||
* The <code>unsigned long</code> type
|
||||
*
|
||||
* @author Lukas Eder
|
||||
* @author Jens Nerche
|
||||
* @author Ivan Sokolov
|
||||
*/
|
||||
public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
|
||||
@ -47,10 +49,22 @@ public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
*/
|
||||
public static final BigInteger MAX_VALUE_LONG = new BigInteger("9223372036854775808");
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value an <code>unsigned long</code> can
|
||||
* have as ULong, 0.
|
||||
*/
|
||||
public static final ULong MIN = valueOf(MIN_VALUE.longValue());
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value + 1 an <code>signed long</code> can
|
||||
* have as ULong, 2<sup>63</sup>.
|
||||
*/
|
||||
public static final ULong MAX = valueOf(MAX_VALUE);
|
||||
|
||||
/**
|
||||
* The value modelling the content of this <code>unsigned long</code>
|
||||
*/
|
||||
private final BigInteger value;
|
||||
private final long value;
|
||||
|
||||
/**
|
||||
* Create an <code>unsigned long</code>
|
||||
@ -81,6 +95,12 @@ public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
return new ULong(value);
|
||||
}
|
||||
|
||||
public static int compare(long x, long y) {
|
||||
x += Long.MIN_VALUE;
|
||||
y += Long.MIN_VALUE;
|
||||
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an <code>unsigned long</code>
|
||||
*
|
||||
@ -88,8 +108,10 @@ public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
* of an <code>unsigned long</code>
|
||||
*/
|
||||
private ULong(BigInteger value) throws NumberFormatException {
|
||||
this.value = value;
|
||||
rangeCheck();
|
||||
if (value.compareTo(MIN_VALUE) < 0 || value.compareTo(MAX_VALUE) > 0)
|
||||
throw new NumberFormatException();
|
||||
else
|
||||
this.value = value.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,12 +120,7 @@ public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
* <code>(uint) 18446744073709551615</code>
|
||||
*/
|
||||
private ULong(long value) {
|
||||
if (value >= 0) {
|
||||
this.value = BigInteger.valueOf(value);
|
||||
}
|
||||
else {
|
||||
this.value = BigInteger.valueOf(value & Long.MAX_VALUE).add(MAX_VALUE_LONG);
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,64 +130,140 @@ public final class ULong extends UNumber implements Comparable<ULong> {
|
||||
* parsable <code>unsigned long</code>.
|
||||
*/
|
||||
private ULong(String value) throws NumberFormatException {
|
||||
this.value = new BigInteger(value);
|
||||
rangeCheck();
|
||||
}
|
||||
if (value == null)
|
||||
throw new NumberFormatException("null");
|
||||
|
||||
private void rangeCheck() throws NumberFormatException {
|
||||
if (value.compareTo(MIN_VALUE) < 0 || value.compareTo(MAX_VALUE) > 0) {
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
int length = value.length();
|
||||
|
||||
if (length == 0)
|
||||
throw new NumberFormatException("Empty input string");
|
||||
|
||||
if (value.charAt(0) == '-')
|
||||
throw new NumberFormatException(
|
||||
String.format("Illegal leading minus sign on unsigned string %s", value));
|
||||
|
||||
if (length <= 18) {
|
||||
this.value = Long.parseLong(value, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
final long first = Long.parseLong(value.substring(0, length - 1), 10);
|
||||
final int second = Character.digit(value.charAt(length - 1), 10);
|
||||
if (second < 0)
|
||||
throw new NumberFormatException("Bad digit at end of " + value);
|
||||
|
||||
long result = first * 10 + second;
|
||||
if (compare(result, first) < 0)
|
||||
throw new NumberFormatException(
|
||||
String.format("String value %s exceeds range of unsigned long", value));
|
||||
|
||||
this.value = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() {
|
||||
return value.intValue();
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue() {
|
||||
return value.longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
return value.floatValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue() {
|
||||
return value.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger toBigInteger() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
if (value < 0)
|
||||
return ((float) (value & Long.MAX_VALUE)) + Long.MAX_VALUE;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue() {
|
||||
if (value < 0)
|
||||
return ((double) (value & Long.MAX_VALUE)) + Long.MAX_VALUE;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value.hashCode();
|
||||
return Long.valueOf(value).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj instanceof ULong) {
|
||||
return value.equals(((ULong) obj).value);
|
||||
}
|
||||
if (obj instanceof ULong)
|
||||
return value == ((ULong) obj).value;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
if (value >= 0)
|
||||
return Long.toString(value);
|
||||
else
|
||||
return BigInteger.valueOf(value & Long.MAX_VALUE).add(MAX_VALUE_LONG).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ULong o) {
|
||||
return value.compareTo(o.value);
|
||||
return compare(value, o.value);
|
||||
}
|
||||
|
||||
public ULong add(ULong val) throws NumberFormatException {
|
||||
if (value < 0 && val.value < 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
final long result = value + val.value;
|
||||
if ((value < 0 || val.value < 0) && result >= 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
return valueOf(result);
|
||||
}
|
||||
|
||||
public ULong add(int val) throws NumberFormatException {
|
||||
return add((long) val);
|
||||
}
|
||||
|
||||
public ULong add(long val) throws NumberFormatException {
|
||||
if (val < 0)
|
||||
return subtract(Math.abs(val));
|
||||
|
||||
final long result = value + val;
|
||||
if (value < 0 && result >= 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
return valueOf(result);
|
||||
}
|
||||
|
||||
public ULong subtract(final ULong val) {
|
||||
if (this.compareTo(val) < 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
final long result = value - val.value;
|
||||
if (value < 0 && result >= 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
return valueOf(result);
|
||||
}
|
||||
|
||||
public ULong subtract(final int val) {
|
||||
return subtract((long) val);
|
||||
}
|
||||
|
||||
public ULong subtract(final long val) {
|
||||
if (val < 0)
|
||||
return add(-val);
|
||||
|
||||
if (compare(value, val) < 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
final long result = value - val;
|
||||
if (value < 0 && result >= 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
return valueOf(result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import java.math.BigInteger;
|
||||
* The <code>unsigned short</code> type
|
||||
*
|
||||
* @author Lukas Eder
|
||||
* @author Jens Nerche
|
||||
*/
|
||||
public final class UShort extends UNumber implements Comparable<UShort> {
|
||||
|
||||
@ -41,6 +42,18 @@ public final class UShort extends UNumber implements Comparable<UShort> {
|
||||
*/
|
||||
public static final int MAX_VALUE = 0xffff;
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value an <code>unsigned short</code> can
|
||||
* have as UShort, 0.
|
||||
*/
|
||||
public static final UShort MIN = valueOf(MIN_VALUE);
|
||||
|
||||
/**
|
||||
* A constant holding the maximum value an <code>unsigned short</code> can
|
||||
* have as UShort, 2<sup>16</sup>-1.
|
||||
*/
|
||||
public static final UShort MAX = valueOf(MAX_VALUE);
|
||||
|
||||
/**
|
||||
* The value modelling the content of this <code>unsigned short</code>
|
||||
*/
|
||||
@ -107,9 +120,8 @@ public final class UShort extends UNumber implements Comparable<UShort> {
|
||||
}
|
||||
|
||||
private void rangeCheck() throws NumberFormatException {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE) {
|
||||
if (value < MIN_VALUE || value > MAX_VALUE)
|
||||
throw new NumberFormatException("Value is out of range : " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -144,11 +156,8 @@ public final class UShort extends UNumber implements Comparable<UShort> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj instanceof UShort) {
|
||||
if (obj instanceof UShort)
|
||||
return value == ((UShort) obj).value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -162,4 +171,20 @@ public final class UShort extends UNumber implements Comparable<UShort> {
|
||||
public int compareTo(UShort o) {
|
||||
return (value < o.value ? -1 : (value == o.value ? 0 : 1));
|
||||
}
|
||||
|
||||
public UShort add(UShort val) throws NumberFormatException {
|
||||
return valueOf(value + val.value);
|
||||
}
|
||||
|
||||
public UShort add(int val) throws NumberFormatException {
|
||||
return valueOf(value + val);
|
||||
}
|
||||
|
||||
public UShort subtract(final UShort val) {
|
||||
return valueOf(value - val.value);
|
||||
}
|
||||
|
||||
public UShort subtract(final int val) {
|
||||
return valueOf(value - val);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user