< prev index next >
test/java/nio/Buffer/BasicFloat.java
Print this page
@@ -29,11 +29,10 @@
*/
// -- This file was mechanically generated: Do not edit! -- //
import java.nio.*;
-import java.lang.reflect.Method;
public class BasicFloat
extends Basic
{
@@ -58,74 +57,79 @@
};
private static void relGet(FloatBuffer b) {
int n = b.capacity();
- float v;
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
ck(b, (long)b.get(), (long)((float)ic(i)));
+ }
b.rewind();
}
private static void relGet(FloatBuffer b, int start) {
int n = b.remaining();
- float v;
- for (int i = start; i < n; i++)
+ for (int i = start; i < n; i++) {
ck(b, (long)b.get(), (long)((float)ic(i)));
+ }
b.rewind();
}
private static void absGet(FloatBuffer b) {
int n = b.capacity();
- float v;
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
ck(b, (long)b.get(), (long)((float)ic(i)));
+ }
b.rewind();
}
private static void bulkGet(FloatBuffer b) {
int n = b.capacity();
float[] a = new float[n + 7];
b.get(a, 7, n);
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
ck(b, (long)a[i + 7], (long)((float)ic(i)));
}
+ }
private static void relPut(FloatBuffer b) {
int n = b.capacity();
b.clear();
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
b.put((float)ic(i));
+ }
b.flip();
}
private static void absPut(FloatBuffer b) {
int n = b.capacity();
b.clear();
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
b.put(i, (float)ic(i));
+ }
b.limit(n);
b.position(0);
}
private static void bulkPutArray(FloatBuffer b) {
int n = b.capacity();
b.clear();
float[] a = new float[n + 7];
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
a[i + 7] = (float)ic(i);
+ }
b.put(a, 7, n);
b.flip();
}
private static void bulkPutBuffer(FloatBuffer b) {
int n = b.capacity();
b.clear();
FloatBuffer c = FloatBuffer.allocate(n + 7);
c.position(7);
- for (int i = 0; i < n; i++)
+ for (int i = 0; i < n; i++) {
c.put((float)ic(i));
+ }
c.flip();
c.position(7);
b.put(c);
b.flip();
try {
@@ -186,19 +190,29 @@
+
private static void checkSlice(FloatBuffer b, FloatBuffer slice) {
ck(slice, 0, slice.position());
ck(slice, b.remaining(), slice.limit());
ck(slice, b.remaining(), slice.capacity());
- if (b.isDirect() != slice.isDirect())
+ if (b.isDirect() != slice.isDirect()) {
fail("Lost direction", slice);
- if (b.isReadOnly() != slice.isReadOnly())
+ }
+ if (b.isReadOnly() != slice.isReadOnly()) {
fail("Lost read-only", slice);
}
+ }
+
+
+
+
+
+
+
@@ -450,24 +464,26 @@
caught = true;
} else {
fail(x.getMessage() + " not expected");
}
}
- if (!caught)
+ if (!caught) {
fail(ex.getName() + " not thrown", b);
}
+ }
private static void tryCatch(float [] t, Class<?> ex, Runnable thunk) {
tryCatch(FloatBuffer.wrap(t), ex, thunk);
}
public static void test(int level, final FloatBuffer b, boolean direct) {
show(level, b);
- if (direct != b.isDirect())
+ if (direct != b.isDirect()) {
fail("Wrong direction", b);
+ }
// Gets and puts
relPut(b);
relGet(b);
@@ -520,11 +536,10 @@
-
// Compact
relPut(b);
b.position(13);
b.compact();
@@ -535,42 +550,17 @@
relPut(b);
b.limit(b.capacity() / 2);
b.position(b.limit());
- tryCatch(b, BufferUnderflowException.class, new Runnable() {
- public void run() {
- b.get();
- }});
-
- tryCatch(b, BufferOverflowException.class, new Runnable() {
- public void run() {
- b.put((float)42);
- }});
-
- // The index must be non-negative and lesss than the buffer's limit.
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(b.limit());
- }});
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.get(-1);
- }});
-
- tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- b.put(b.limit(), (float)42);
- }});
-
- tryCatch(b, InvalidMarkException.class, new Runnable() {
- public void run() {
- b.position(0);
- b.mark();
- b.compact();
- b.reset();
- }});
+ tryCatch(b, BufferUnderflowException.class, () -> b.get());
+ tryCatch(b, BufferOverflowException.class, () -> b.put((float)42));
+ // The index must be non-negative and less than the buffer's limit.
+ tryCatch(b, IndexOutOfBoundsException.class, () -> b.get(b.limit()));
+ tryCatch(b, IndexOutOfBoundsException.class, () -> b.get(-1));
+ tryCatch(b, IndexOutOfBoundsException.class, () -> b.put(b.limit(), (float)42));
+ tryCatch(b, InvalidMarkException.class, () -> b.position(0).mark().compact().reset());
try {
b.position(b.limit() + 1);
fail("IllegalArgumentException expected for position beyond limit");
} catch (IllegalArgumentException e) {
@@ -633,26 +623,27 @@
- float v;
b.flip();
ck(b, b.get(), 0);
ck(b, b.get(), (float)-1);
ck(b, b.get(), 1);
ck(b, b.get(), Float.MAX_VALUE);
ck(b, b.get(), Float.MIN_VALUE);
+ float v;
ck(b, b.get(), -Float.MAX_VALUE);
ck(b, b.get(), -Float.MIN_VALUE);
ck(b, b.get(), Float.NEGATIVE_INFINITY);
ck(b, b.get(), Float.POSITIVE_INFINITY);
if (Float.floatToRawIntBits(v = b.get()) !=
- Float.floatToRawIntBits(Float.NaN))
+ Float.floatToRawIntBits(Float.NaN)) {
fail(b, (long)Float.NaN, (long)v);
+ }
ck(b, b.get(), 0.91697687f);
@@ -663,10 +654,12 @@
+
+
// Comparison
b.rewind();
FloatBuffer b2 = FloatBuffer.allocate(b.capacity());
b2.put(b);
b2.flip();
@@ -681,42 +674,47 @@
|| Float.compare(x, y) != 0
- )
+ ) {
out.println("[" + i + "] " + x + " != " + y);
}
+ }
fail("Identical buffers not equal", b, b2);
}
- if (b.compareTo(b2) != 0)
+ if (b.compareTo(b2) != 0) {
fail("Comparison to identical buffer != 0", b, b2);
-
+ }
b.limit(b.limit() + 1);
b.position(b.limit() - 1);
b.put((float)99);
b.rewind();
b2.rewind();
- if (b.equals(b2))
+ if (b.equals(b2)) {
fail("Non-identical buffers equal", b, b2);
- if (b.compareTo(b2) <= 0)
+ }
+ if (b.compareTo(b2) <= 0) {
fail("Comparison to shorter buffer <= 0", b, b2);
+ }
b.limit(b.limit() - 1);
b.put(2, (float)42);
- if (b.equals(b2))
+ if (b.equals(b2)) {
fail("Non-identical buffers equal", b, b2);
- if (b.compareTo(b2) <= 0)
+ }
+ if (b.compareTo(b2) <= 0) {
fail("Comparison to lesser buffer <= 0", b, b2);
+ }
// Check equals and compareTo with interesting values
for (float x : VALUES) {
FloatBuffer xb = FloatBuffer.wrap(new float[] { x });
if (xb.compareTo(xb) != 0) {
fail("compareTo not reflexive", xb, xb, x, x);
}
- if (! xb.equals(xb)) {
+ if (!xb.equals(xb)) {
fail("equals not reflexive", xb, xb, x, x);
}
for (float y : VALUES) {
FloatBuffer yb = FloatBuffer.wrap(new float[] { y });
if (xb.compareTo(yb) != - yb.compareTo(xb)) {
@@ -761,15 +759,17 @@
checkSlice(b, sb);
b.position(0);
FloatBuffer sb2 = sb.slice();
checkSlice(sb, sb2);
- if (!sb.equals(sb2))
+ if (!sb.equals(sb2)) {
fail("Sliced slices do not match", sb, sb2);
- if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+ }
+ if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
fail("Array offsets do not match: "
+ sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+ }
@@ -802,87 +802,26 @@
// Read-only views
b.rewind();
final FloatBuffer rb = b.asReadOnlyBuffer();
- if (!b.equals(rb))
+ if (!b.equals(rb)) {
fail("Buffer not equal to read-only view", b, rb);
+ }
show(level + 1, rb);
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- relPut(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- absPut(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- bulkPutArray(rb);
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- bulkPutBuffer(rb);
- }});
+ tryCatch(b, ReadOnlyBufferException.class, () -> relPut(rb));
+ tryCatch(b, ReadOnlyBufferException.class, () -> absPut(rb));
+ tryCatch(b, ReadOnlyBufferException.class, () -> bulkPutArray(rb));
+ tryCatch(b, ReadOnlyBufferException.class, () -> bulkPutBuffer(rb));
// put(FloatBuffer) should not change source position
final FloatBuffer src = FloatBuffer.allocate(1);
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.put(src);
- }});
+ tryCatch(b, ReadOnlyBufferException.class, () -> rb.put(src));
ck(src, src.position(), 0);
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.compact();
- }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ tryCatch(b, ReadOnlyBufferException.class, () -> rb.compact());
@@ -914,25 +853,15 @@
if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.array();
- }});
-
- tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
- public void run() {
- rb.arrayOffset();
- }});
-
- if (rb.hasArray())
- fail("Read-only heap buffer's backing array is accessible",
- rb);
-
+ tryCatch(b, ReadOnlyBufferException.class, () -> rb.array());
+ tryCatch(b, ReadOnlyBufferException.class, () -> rb.arrayOffset());
+ if (rb.hasArray()) {
+ fail("Read-only heap buffer's backing array is accessible", rb);
+ }
}
// Bulk puts from read-only buffers
b.clear();
@@ -1050,44 +979,23 @@
ck(b, b.capacity(), ba.length);
ck(b, b.position(), offset);
ck(b, b.limit(), offset + length);
// The offset must be non-negative and no larger than <array.length>.
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap(ba, -1, ba.length);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap(ba, ba.length + 1, ba.length);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap(ba, 0, -1);
- }});
- tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap(ba, 0, ba.length + 1);
- }});
+ tryCatch(ba, IndexOutOfBoundsException.class, () -> FloatBuffer.wrap(ba, -1, ba.length));
+ tryCatch(ba, IndexOutOfBoundsException.class, () -> FloatBuffer.wrap(ba, ba.length + 1, ba.length));
+ tryCatch(ba, IndexOutOfBoundsException.class, () -> FloatBuffer.wrap(ba, 0, -1));
+ tryCatch(ba, IndexOutOfBoundsException.class, () -> FloatBuffer.wrap(ba, 0, ba.length + 1));
// A NullPointerException will be thrown if the array is null.
- tryCatch(ba, NullPointerException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap((float []) null, 0, 5);
- }});
- tryCatch(ba, NullPointerException.class, new Runnable() {
- public void run() {
- FloatBuffer.wrap((float []) null);
- }});
+ tryCatch(ba, NullPointerException.class, () -> FloatBuffer.wrap((float []) null, 0, 5));
+ tryCatch(ba, NullPointerException.class, () -> FloatBuffer.wrap((float []) null));
}
private static void testAllocate() {
// An IllegalArgumentException will be thrown for negative capacities.
- tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
- public void run() {
- FloatBuffer.allocate(-1);
- }});
+ tryCatch((Buffer) null, IllegalArgumentException.class, () -> FloatBuffer.allocate(-1));
try {
FloatBuffer.allocate(-1);
} catch (IllegalArgumentException e) {
if (e.getMessage() == null) {
fail("Non-null IllegalArgumentException message expected for"
@@ -1103,13 +1011,10 @@
-
-
-
}
public static void test() {
testAllocate();
test(0, FloatBuffer.allocate(7 * 1024), false);
@@ -1123,10 +1028,11 @@
+
callReset(FloatBuffer.allocate(10));
putBuffer();
< prev index next >