--- old/test/java/nio/Buffer/BasicShort.java 2016-05-13 12:29:00.000000000 +0100 +++ new/test/java/nio/Buffer/BasicShort.java 2016-05-13 12:29:00.000000000 +0100 @@ -31,7 +31,6 @@ // -- This file was mechanically generated: Do not edit! -- // import java.nio.*; -import java.lang.reflect.Method; public class BasicShort @@ -60,25 +59,25 @@ private static void relGet(ShortBuffer b) { int n = b.capacity(); - short v; - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { ck(b, (long)b.get(), (long)((short)ic(i))); + } b.rewind(); } private static void relGet(ShortBuffer b, int start) { int n = b.remaining(); - short v; - for (int i = start; i < n; i++) + for (int i = start; i < n; i++) { ck(b, (long)b.get(), (long)((short)ic(i))); + } b.rewind(); } private static void absGet(ShortBuffer b) { int n = b.capacity(); - short v; - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { ck(b, (long)b.get(), (long)((short)ic(i))); + } b.rewind(); } @@ -86,23 +85,26 @@ int n = b.capacity(); short[] a = new short[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)((short)ic(i))); + } } private static void relPut(ShortBuffer b) { int n = b.capacity(); b.clear(); - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { b.put((short)ic(i)); + } b.flip(); } private static void absPut(ShortBuffer b) { int n = b.capacity(); b.clear(); - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { b.put(i, (short)ic(i)); + } b.limit(n); b.position(0); } @@ -111,8 +113,9 @@ int n = b.capacity(); b.clear(); short[] a = new short[n + 7]; - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { a[i + 7] = (short)ic(i); + } b.put(a, 7, n); b.flip(); } @@ -122,8 +125,9 @@ b.clear(); ShortBuffer c = ShortBuffer.allocate(n + 7); c.position(7); - for (int i = 0; i < n; i++) + for (int i = 0; i < n; i++) { c.put((short)ic(i)); + } c.flip(); c.position(7); b.put(c); @@ -188,14 +192,17 @@ + private static void checkSlice(ShortBuffer b, ShortBuffer 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); + } } @@ -435,6 +442,13 @@ + + + + + + + private static void fail(String problem, ShortBuffer xb, ShortBuffer yb, short x, short y) { @@ -452,8 +466,9 @@ fail(x.getMessage() + " not expected"); } } - if (!caught) + if (!caught) { fail(ex.getName() + " not thrown", b); + } } private static void tryCatch(short [] t, Class ex, Runnable thunk) { @@ -464,8 +479,9 @@ show(level, b); - if (direct != b.isDirect()) + if (direct != b.isDirect()) { fail("Wrong direction", b); + } // Gets and puts @@ -522,7 +538,6 @@ - // Compact relPut(b); @@ -537,38 +552,13 @@ 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((short)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(), (short)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((short)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(), (short)42)); + tryCatch(b, InvalidMarkException.class, () -> b.position(0).mark().compact().reset()); try { b.position(b.limit() + 1); @@ -635,7 +625,6 @@ - short v; b.flip(); ck(b, b.get(), 0); ck(b, b.get(), (short)-1); @@ -665,6 +654,10 @@ + + + + // Comparison b.rewind(); ShortBuffer b2 = ShortBuffer.allocate(b.capacity()); @@ -683,30 +676,35 @@ - ) + ) { 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((short)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, (short)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 (short x : VALUES) { @@ -714,7 +712,7 @@ 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 (short y : VALUES) { @@ -763,11 +761,13 @@ ShortBuffer 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); + } @@ -804,83 +804,22 @@ b.rewind(); final ShortBuffer 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(ShortBuffer) should not change source position final ShortBuffer src = ShortBuffer.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()); @@ -916,21 +855,11 @@ 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 @@ -1052,40 +981,19 @@ ck(b, b.limit(), offset + length); // The offset must be non-negative and no larger than . - tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { - public void run() { - ShortBuffer.wrap(ba, -1, ba.length); - }}); - tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { - public void run() { - ShortBuffer.wrap(ba, ba.length + 1, ba.length); - }}); - tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { - public void run() { - ShortBuffer.wrap(ba, 0, -1); - }}); - tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() { - public void run() { - ShortBuffer.wrap(ba, 0, ba.length + 1); - }}); + tryCatch(ba, IndexOutOfBoundsException.class, () -> ShortBuffer.wrap(ba, -1, ba.length)); + tryCatch(ba, IndexOutOfBoundsException.class, () -> ShortBuffer.wrap(ba, ba.length + 1, ba.length)); + tryCatch(ba, IndexOutOfBoundsException.class, () -> ShortBuffer.wrap(ba, 0, -1)); + tryCatch(ba, IndexOutOfBoundsException.class, () -> ShortBuffer.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() { - ShortBuffer.wrap((short []) null, 0, 5); - }}); - tryCatch(ba, NullPointerException.class, new Runnable() { - public void run() { - ShortBuffer.wrap((short []) null); - }}); + tryCatch(ba, NullPointerException.class, () -> ShortBuffer.wrap((short []) null, 0, 5)); + tryCatch(ba, NullPointerException.class, () -> ShortBuffer.wrap((short []) null)); } private static void testAllocate() { // An IllegalArgumentException will be thrown for negative capacities. - tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() { - public void run() { - ShortBuffer.allocate(-1); - }}); + tryCatch((Buffer) null, IllegalArgumentException.class, () -> ShortBuffer.allocate(-1)); try { ShortBuffer.allocate(-1); } catch (IllegalArgumentException e) { @@ -1105,9 +1013,6 @@ - - - } public static void test() { @@ -1125,6 +1030,7 @@ + callReset(ShortBuffer.allocate(10));