jdk/test/java/nio/Buffer/BasicLong.java
changeset 37913 3cc95b690353
parent 36933 3e6453e2d833
--- a/jdk/test/java/nio/Buffer/BasicLong.java	Mon May 16 07:01:26 2016 +0200
+++ b/jdk/test/java/nio/Buffer/BasicLong.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicLong
@@ -60,7 +59,6 @@
 
     private static void relGet(LongBuffer b) {
         int n = b.capacity();
-        long v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(LongBuffer b, int start) {
         int n = b.remaining();
-        long v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(LongBuffer b) {
         int n = b.capacity();
-        long v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         long[] a = new long[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)((long)ic(i)));
+        }
     }
 
     private static void relPut(LongBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              LongBuffer xb, LongBuffer yb,
                              long x, long y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(long[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(long [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(long[] t, Class<?> ex, Runnable thunk) {
         tryCatch(LongBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         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((long)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(), (long)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((long)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (long)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        long v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (long)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         LongBuffer b2 = LongBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     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((long)99);
@@ -714,7 +720,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 (long y : VALUES) {
@@ -765,9 +771,10 @@
 
         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);
+        }
 
 
 
@@ -808,87 +815,17 @@
             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);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(LongBuffer) should not change source position
         final LongBuffer src = LongBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,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);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final long [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         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() {
-                    LongBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.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() {
-                    LongBuffer.wrap((long []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap((long []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> LongBuffer.wrap((long []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> LongBuffer.wrap((long []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> LongBuffer.allocate(-1));
         try {
             LongBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {