changeset 5871:ef17a5d81036 it2-bootstrap

Merge
author briangoetz
date Mon, 27 Aug 2012 18:50:24 -0400
parents 83923cc50252 46e198a52fb8
children debae4fe344f
files test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java	Mon Aug 27 18:47:18 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java	Mon Aug 27 18:50:24 2012 -0400
@@ -51,40 +51,40 @@
 @Test
 public abstract class StreamOpTestCase {
 
-    protected<T> Stream<T> seq(T[] data) {
+    protected static <T> Stream<T> seq(T[] data) {
         return Streams.stream(Arrays.iterator(data), data.length);
     }
 
-    protected<T> Stream<T> par(T[] data) {
+    protected static <T> Stream<T> par(T[] data) {
         return Streams.parallel(Arrays.spliterator(data), data.length);
     }
 
-    protected<T, U> Stream<U> seq(T[] data, IntermediateOp<T,U> op) {
+    protected static <T, U> Stream<U> seq(T[] data, IntermediateOp<T,U> op) {
         return ((LinearPipeline) Streams.stream(Arrays.iterator(data), data.length)).pipeline(op);
     }
 
-    protected<T, U> Stream<U> par(T[] data, IntermediateOp<T,U> op) {
+    protected static <T, U> Stream<U> par(T[] data, IntermediateOp<T,U> op) {
         return ((LinearPipeline) Streams.parallel(Arrays.spliterator(data), data.length)).pipeline(op);
     }
 
-    protected<T, U> U seq(T[] data, TerminalOp<T,U> op) {
+    protected static <T, U> U seq(T[] data, TerminalOp<T,U> op) {
         return ((LinearPipeline<?, T>) Streams.stream(Arrays.iterator(data), data.length)).pipeline(op);
     }
 
-    protected<T, U> U par(T[] data, TerminalOp<T,U> op) {
+    protected static <T, U> U par(T[] data, TerminalOp<T,U> op) {
         return ((LinearPipeline<?, T>) Streams.parallel(Arrays.spliterator(data), data.length)).pipeline(op);
     }
 
-    protected<T> Iterator<T> iterator(T[] data) {
+    protected static<T> Iterator<T> iterator(T[] data) {
         return Arrays.iterator(data);
     }
 
-    protected<T> void forEach(T[] data, Sink<? super T> sink) {
+    protected static <T> void forEach(T[] data, Sink<? super T> sink) {
         for (T t : data)
             sink.accept(t);
     }
 
-    protected <T, U> void assertConsistentOpBehavior(T[] data,
+    protected static <T, U> void assertConsistentOpBehavior(T[] data,
                                                      IntermediateOp<T, U> op,
                                                      Mapper<Integer, Integer> lengthMapper) {
         int length = (lengthMapper == null) ? 100 : lengthMapper.map(data.length);
@@ -198,7 +198,7 @@
     }
 
 
-    protected <T, U> void assertConsistentOpBehavior(T[] data, ShortCircuitTerminalOp<T, U> op) {
+    protected static <T, U> void assertConsistentOpBehavior(T[] data, ShortCircuitTerminalOp<T, U> op) {
         // First pass -- wrap Iterator
         U answer1 = op.evaluate(iterator(data));
 
@@ -211,7 +211,7 @@
 
     // @@@ Merge these two into a single method
 
-    protected <T, U> void assertConsistentOpBehavior(T[] data, TerminalOp<T, U> op, BiPredicate<U,U> equalator) {
+    protected static <T, U> void assertConsistentOpBehavior(T[] data, TerminalOp<T, U> op, BiPredicate<U,U> equalator) {
         // First pass -- create a sink and evaluate, with no size advice
         StatefulSink<T, U> sink = op.sink();
         sink.begin(-1);
@@ -253,7 +253,7 @@
 
     private static class ArraySink<T> implements Sink<T>, Traversable<T>, Sized {
 
-        private T[] array;
+        private Object[] array;
 
         private int offset;
 
@@ -269,22 +269,21 @@
         @Override
         public void forEach(Sink<? super T> sink) {
             for (int i = 0; i < offset; i++) {
-                sink.accept(array[i]);
+                sink.accept((T) array[i]);
             }
         }
 
         @Override
+        @SuppressWarnings("unchecked")
         public Iterator<T> iterator() {
-            return Arrays.iterator(array, 0, offset);
+            return (Iterator<T>) Arrays.iterator(array, 0, offset);
         }
 
         @Override
+        @SuppressWarnings("unchecked")
         public void accept(T t) {
             if (offset == array.length) {
-                @SuppressWarnings("unchecked")
-                T[] temp = (T[])new Object[Math.max(array.length, 1) * 2];
-                System.arraycopy(array, 0, temp, 0, array.length);
-                array = temp;
+                array = Arrays.copyOf(array, Math.max(array.length, 1) * 2);
             }
             array[offset++] = t;
         }
@@ -296,7 +295,11 @@
 
         @Override
         public String toString() {
-            return String.format("ArraySink[%d](%s)", offset, Arrays.toString(array));
+            return String.format("%s[%d](%s)", super.toString(), offset, Arrays.toString(array));
+        }
+
+        public Object[] toArray() {
+            return Arrays.copyOf(array, offset);
         }
     }