diff options
-rw-r--r-- | src/java/com/jogamp/common/util/Bitstream.java | 28 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/BitstreamData.java | 4 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/TestBitstream00.java | 4 |
3 files changed, 22 insertions, 14 deletions
diff --git a/src/java/com/jogamp/common/util/Bitstream.java b/src/java/com/jogamp/common/util/Bitstream.java index 419b356..7938c1c 100644 --- a/src/java/com/jogamp/common/util/Bitstream.java +++ b/src/java/com/jogamp/common/util/Bitstream.java @@ -1167,7 +1167,7 @@ public class Bitstream<T> { * and swap bytes if !bigEndian. * <p> * In case the returned value shall be interpreted as <code>uint32_t</code> - * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for + * utilize {@link #toUInt32Long(int)} or {@link #toUInt32Int(int)} for * an appropriate conversion. * </p> * @param msbFirst if true incoming stream bit order is MSB to LSB, otherwise LSB to MSB. @@ -1215,7 +1215,7 @@ public class Bitstream<T> { * and swap bytes if !bigEndian. * <p> * In case the returned value shall be interpreted as <code>uint32_t</code> - * utilize {@link #toUint32Long(int)} or {@link #toUint32Int(int)} for + * utilize {@link #toUInt32Long(int)} or {@link #toUInt32Int(int)} for * an appropriate conversion. * </p> * @param bigEndian if false, swap incoming bytes to little-endian, otherwise leave them as little-endian. @@ -1306,22 +1306,30 @@ public class Bitstream<T> { * final long l = 0xffffffffL & int32; * </pre> */ - public static final long toUint32Long(final int val) { - return 0xffffffffL & val; + public static final long toUInt32Long(final int int32) { + return 0xffffffffL & int32; } /** * Returns the reinterpreted given <code>int32_t</code> value - * as <code>uint32_t</code> if < {@link Integer#MAX_VALUE} + * as <code>uint32_t</code> if ≤ {@link Integer#MAX_VALUE} * as within an <code>int</code> storage. * Otherwise return -1. */ - public static final int toUint32Int(final int val) { - final long v = toUint32Long(val); - if( v > Integer.MAX_VALUE ) { - return -1; + public static final int toUInt32Int(final int int32) { + return uint32LongtoInt(toUInt32Long(int32)); + } + + /** + * Returns the given <code>uint32_t</code> value <code>long</code> + * value as <code>int</code> if ≤ {@link Integer#MAX_VALUE}. + * Otherwise return -1. + */ + public static final int uint32LongtoInt(final long uint32) { + if( Integer.MAX_VALUE >= uint32 ) { + return (int)uint32; } else { - return (int)v; + return -1; } } diff --git a/src/junit/com/jogamp/common/util/BitstreamData.java b/src/junit/com/jogamp/common/util/BitstreamData.java index b5c2c62..5a8bd46 100644 --- a/src/junit/com/jogamp/common/util/BitstreamData.java +++ b/src/junit/com/jogamp/common/util/BitstreamData.java @@ -116,8 +116,8 @@ public class BitstreamData { return String.format("[%0"+nibbles+"X, %s]", v, toBinaryString(v, bitCount)); } public static String toUnsignedBinaryString(final int int32) { - final long l = Bitstream.toUint32Long(int32); - final int i = Bitstream.toUint32Int(int32); + final long l = Bitstream.toUInt32Long(int32); + final int i = Bitstream.toUInt32Int(int32); return "(long)"+l+", (int)"+i+", "+toHexBinaryString(l, 32); } } diff --git a/src/junit/com/jogamp/common/util/TestBitstream00.java b/src/junit/com/jogamp/common/util/TestBitstream00.java index 47ed1cf..767117b 100644 --- a/src/junit/com/jogamp/common/util/TestBitstream00.java +++ b/src/junit/com/jogamp/common/util/TestBitstream00.java @@ -101,9 +101,9 @@ public class TestBitstream00 extends JunitTracer { } void testUInt32Conversion(final int int32, final int expUint32Int) { final String int32_hStr = toHexString(int32); - final long l = Bitstream.toUint32Long(int32); + final long l = Bitstream.toUInt32Long(int32); final String l_hStr = toHexString(l); - final int i = Bitstream.toUint32Int(int32); + final int i = Bitstream.toUInt32Int(int32); final String i_hStr = toHexString(i); System.err.printf("int32_t %012d %10s -> (long) %012d %10s, (int) %012d %10s%n", int32, int32_hStr, l, l_hStr, i, i_hStr); Assert.assertEquals(int32_hStr, l_hStr); |