changeset 7600:6b22b3d5d3e9

Add javadoc for Arrays stream methods
author briangoetz
date Sun, 10 Mar 2013 20:34:24 -0400
parents 988d94a4b83e
children 37c4fdad51ce
files src/share/classes/java/util/Arrays.java src/share/classes/java/util/stream/DelegatingStream.java
diffstat 2 files changed, 238 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Arrays.java	Sun Mar 10 18:52:10 2013 -0400
+++ b/src/share/classes/java/util/Arrays.java	Sun Mar 10 20:34:24 2013 -0400
@@ -4485,98 +4485,320 @@
         return Streams.intRange(0, array.length);
     }
 
+    /**
+     * Produce a {@link Spliterator} for the contents of the specified array.
+     *
+     * @param array The array for which to create a {@code Spliterator}
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Spliterator} for the specified array
+     */
     public static <T> Spliterator<T> spliterator(T[] array) {
         return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator} for a contiguous portion of the specified array.
+     *
+     * @param array The array for which to create a {@code Spliterator}
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Spliterator} for the desired portion of the specified array
+     */
     public static <T> Spliterator<T> spliterator(T[] array, int fromIndex, int toIndex) {
         return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfInt} for the contents of the specified integer array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfInt}
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Spliterator.OfInt} for the specified array
+     */
     public static Spliterator.OfInt spliterator(int[] array) {
         return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfInt} for a contiguous portion of the specified integer array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfInt}
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Spliterator.OfInt} for the specified array
+     */
     public static Spliterator.OfInt spliterator(int[] array, int fromIndex, int toIndex) {
         return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfLong} for the contents of the specified long array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfLong}
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Spliterator.OfLong} for the specified array
+     */
     public static Spliterator.OfLong spliterator(long[] array) {
         return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfLong} for a contiguous portion of the specified long array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfLong}
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Spliterator.OfLong} for the specified array
+     */
     public static Spliterator.OfLong spliterator(long[] array, int fromIndex, int toIndex) {
         return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfDouble} for the contents of the specified double array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfDouble}
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Spliterator.OfDouble} for the specified array
+     */
     public static Spliterator.OfDouble spliterator(double[] array) {
         return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a {@link Spliterator.OfDouble} for a contiguous portion of the specified double array.
+     *
+     * @param array The array for which to create a {@code Spliterator.OfDouble}
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Spliterator.OfDouble} for the specified array
+     */
     public static Spliterator.OfDouble spliterator(double[] array, int fromIndex, int toIndex) {
         return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
+    /**
+     * Produce a sequential {@link Stream} backed by the provided array.
+     *
+     * @param array The array containing the stream contents
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Stream} backed by the provided array
+     */
     public static <T> Stream<T> stream(T[] array) {
         return stream(array, 0, array.length);
     }
 
+    /**
+     * Produce a sequential {@link Stream} backed by a contiguous portion of the provided array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Stream} backed by the provided array
+     */
     public static <T> Stream<T> stream(T[] array, int fromIndex, int toIndex) {
         return Streams.stream(spliterator(array, fromIndex, toIndex));
     }
 
-    public static IntStream stream(int[] source) {
-        return stream(source, 0, source.length);
+    /**
+     * Produce a sequential {@link IntStream} backed by the provided int array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code IntStream} backed by the provided array
+     */
+    public static IntStream stream(int[] array) {
+        return stream(array, 0, array.length);
     }
 
-    public static IntStream stream(int[] source, int fromIndex, int toIndex) {
-        return Streams.intStream(spliterator(source, fromIndex, toIndex));
+    /**
+     * Produce a sequential {@link IntStream} backed by a contiguous portion of the provided int array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code IntStream} backed by the provided array
+     */
+    public static IntStream stream(int[] array, int fromIndex, int toIndex) {
+        return Streams.intStream(spliterator(array, fromIndex, toIndex));
     }
 
-    public static LongStream stream(long[] source) {
-        return stream(source, 0, source.length);
+    /**
+     * Produce a sequential {@link LongStream} backed by the provided long array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code LongStream} backed by the provided array
+     */
+    public static LongStream stream(long[] array) {
+        return stream(array, 0, array.length);
     }
 
-    public static LongStream stream(long[] source, int fromIndex, int toIndex) {
-        return Streams.longStream(spliterator(source, fromIndex, toIndex));
+    /**
+     * Produce a sequential {@link LongStream} backed by a contiguous portion of the provided long array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code LongStream} backed by the provided array
+     */
+    public static LongStream stream(long[] array, int fromIndex, int toIndex) {
+        return Streams.longStream(spliterator(array, fromIndex, toIndex));
     }
 
-    public static DoubleStream stream(double[] source) {
-        return stream(source, 0, source.length);
+    /**
+     * Produce a sequential {@link DoubleStream} backed by the provided double array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code DoubleStream} backed by the provided array
+     */
+    public static DoubleStream stream(double[] array) {
+        return stream(array, 0, array.length);
     }
 
-    public static DoubleStream stream(double[] source, int fromIndex, int toIndex) {
-        return Streams.doubleStream(spliterator(source, fromIndex, toIndex));
+    /**
+     * Produce a sequential {@link DoubleStream} backed by a contiguous portion of the provided double array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code DoubleStream} backed by the provided array
+     */
+    public static DoubleStream stream(double[] array, int fromIndex, int toIndex) {
+        return Streams.doubleStream(spliterator(array, fromIndex, toIndex));
     }
 
+    /**
+     * Produce a parallel {@link Stream} backed by the provided array.
+     *
+     * @param array The array containing the stream contents
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @return A {@code Stream} backed by the provided array
+     */
     public static <T> Stream<T> parallelStream(T[] array) {
         return parallelStream(array, 0, array.length);
     }
 
+    /**
+     * Produce a parallel {@link Stream} backed by a contiguous portion of the provided array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @param <T> The type of the array elements
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code Stream} backed by the provided array
+     */
     public static <T> Stream<T> parallelStream(T[] array, int fromIndex, int toIndex) {
         return Streams.parallelStream(spliterator(array, fromIndex, toIndex));
     }
 
+    /**
+     * Produce a parallel {@link IntStream} backed by the provided int array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code IntStream} backed by the provided array
+     */
     public static IntStream parallelStream(int[] array) {
         return parallelStream(array, 0, array.length);
     }
 
+    /**
+     * Produce a parallel {@link IntStream} backed by a contiguous portion of the provided int array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code IntStream} backed by the provided array
+     */
     public static IntStream parallelStream(int[] array, int fromIndex, int toIndex) {
         return Streams.intParallelStream(spliterator(array, fromIndex, toIndex));
     }
 
+    /**
+     * Produce a parallel {@link LongStream} backed by the provided long array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code LongStream} backed by the provided array
+     */
     public static LongStream parallelStream(long[] array) {
         return parallelStream(array, 0, array.length);
     }
 
+    /**
+     * Produce a parallel {@link LongStream} backed by a contiguous portion of the provided long array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code LongStream} backed by the provided array
+     */
     public static LongStream parallelStream(long[] array, int fromIndex, int toIndex) {
         return Streams.longParallelStream(spliterator(array, fromIndex, toIndex));
     }
 
+    /**
+     * Produce a parallel {@link DoubleStream} backed by the provided double array.
+     *
+     * @param array The array containing the stream contents
+     * @throws NullPointerException if the specified array is null
+     * @return An {@code DoubleStream} backed by the provided array
+     */
     public static DoubleStream parallelStream(double[] array) {
         return parallelStream(array, 0, array.length);
     }
 
+    /**
+     * Produce a parallel {@link DoubleStream} backed by a contiguous portion of the provided double array.
+     *
+     * @param array The array containing the stream contents
+     * @param fromIndex The index of the first element (inclusive) to be included in the traversal
+     * @param toIndex The index of the last element (exclusive) to be included in the traversal
+     * @throws NullPointerException if the specified array is null
+     * @throws ArrayIndexOutOfBoundsException if fromIndex is negative, toIndex is less than fromIndex, or toIndex
+     * is greater than the array size
+     * @return A {@code DoubleStream} backed by the provided array
+     */
     public static DoubleStream parallelStream(double[] array, int fromIndex, int toIndex) {
         return Streams.doubleParallelStream(spliterator(array, fromIndex, toIndex));
     }
--- a/src/share/classes/java/util/stream/DelegatingStream.java	Sun Mar 10 18:52:10 2013 -0400
+++ b/src/share/classes/java/util/stream/DelegatingStream.java	Sun Mar 10 20:34:24 2013 -0400
@@ -204,6 +204,10 @@
         return delegate.min(comparator);
     }
 
+    public long count() {
+        return delegate.count();
+    }
+
     public boolean anyMatch(Predicate<? super T> predicate) {
         return delegate.anyMatch(predicate);
     }