--- old/src/share/classes/java/util/Arrays.java 2013-04-23 11:32:19.032938726 -0700 +++ new/src/share/classes/java/util/Arrays.java 2013-04-23 11:32:18.884938727 -0700 @@ -25,7 +25,21 @@ package java.util; -import java.lang.reflect.*; +import java.lang.reflect.Array; +import java.util.concurrent.ForkJoinPool; +import java.util.function.BinaryOperator; +import java.util.function.DoubleBinaryOperator; +import java.util.function.IntBinaryOperator; +import java.util.function.IntFunction; +import java.util.function.IntToDoubleFunction; +import java.util.function.IntToLongFunction; +import java.util.function.IntUnaryOperator; +import java.util.function.LongBinaryOperator; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import static java.util.ArraysParallelSortHelpers.*; /** @@ -4306,8 +4320,155 @@ dejaVu.remove(a); } + + /** + * Set all elements of the specified array, using the provided + * generator function to compute each element. + * + *
If the generator function throws an exception, it is relayed to
+ * the caller and the array is left in an indeterminate state.
+ *
+ * @param array Array to be initialized
+ * @param generator Function accepting an index and producing the desired
+ * value for that position
+ * @param If the generator function throws an exception, it is relayed to
+ * the caller and the array is left in an indeterminate state.
+ *
+ * @param array Array to be initialized
+ * @param generator Function accepting an index and producing the desired
+ * value for that position
+ * @throw NullPointerException if the generator is null
+ */
+ public static void setAll(int[] array, IntUnaryOperator generator) {
+ Objects.requireNonNull(generator);
+ for (int i=0; i If the generator function throws an exception, it is relayed to
+ * the caller and the array is left in an indeterminate state.
+ *
+ * @param array Array to be initialized
+ * @param generator Function accepting an index and producing the desired
+ * value for that position
+ * @throw NullPointerException if the generator is null
+ */
+ public static void setAll(long[] array, IntToLongFunction generator) {
+ Objects.requireNonNull(generator);
+ for (int i=0; i If the generator function throws an exception, it is relayed to
+ * the caller and the array is left in an indeterminate state.
+ *
+ * @param array Array to be initialized
+ * @param generator Function accepting an index and producing the desired
+ * value for that position
+ * @throw NullPointerException if the generator is null
+ */
+ public static void setAll(double[] array, IntToDoubleFunction generator) {
+ Objects.requireNonNull(generator);
+ for (int i=0; i The spliterator reports {@link Spliterator#SIZED},
* {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
@@ -4315,7 +4476,7 @@
*
* @param The spliterator reports {@link Spliterator#SIZED},
@@ -4336,7 +4497,7 @@
* @param array The array, assumed to be unmodified during use
* @param fromIndex The least index (inclusive) to cover
* @param toIndex One past the greatest index to cover
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
* {@code toIndex} is less than {@code fromIndex}, or
@@ -4349,14 +4510,14 @@
}
/**
- * Creates a {@link Spliterator.OfInt} covering all of the specified array.
+ * Returns a {@link Spliterator.OfInt} covering all of the specified array.
*
* The spliterator reports {@link Spliterator#SIZED},
* {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
* {@link Spliterator#IMMUTABLE}.
*
* @param array The array, assumed to be unmodified during use
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @since 1.8
*/
@@ -4366,7 +4527,7 @@
}
/**
- * Creates a {@link Spliterator.OfInt} covering the specified range of the
+ * Returns a {@link Spliterator.OfInt} covering the specified range of the
* specified array.
*
* The spliterator reports {@link Spliterator#SIZED},
@@ -4376,7 +4537,7 @@
* @param array The array, assumed to be unmodified during use
* @param fromIndex The least index (inclusive) to cover
* @param toIndex One past the greatest index to cover
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
* {@code toIndex} is less than {@code fromIndex}, or
@@ -4389,14 +4550,14 @@
}
/**
- * Creates a {@link Spliterator.OfLong} covering all of the specified array.
+ * Returns a {@link Spliterator.OfLong} covering all of the specified array.
*
* The spliterator reports {@link Spliterator#SIZED},
* {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
* {@link Spliterator#IMMUTABLE}.
*
* @param array The array, assumed to be unmodified during use
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @since 1.8
*/
@@ -4406,7 +4567,7 @@
}
/**
- * Creates a {@link Spliterator.OfLong} covering the specified range of the
+ * Returns a {@link Spliterator.OfLong} covering the specified range of the
* specified array.
*
* The spliterator reports {@link Spliterator#SIZED},
@@ -4416,7 +4577,7 @@
* @param array The array, assumed to be unmodified during use
* @param fromIndex The least index (inclusive) to cover
* @param toIndex One past the greatest index to cover
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
* {@code toIndex} is less than {@code fromIndex}, or
@@ -4429,7 +4590,7 @@
}
/**
- * Creates a {@link Spliterator.OfDouble} covering all of the specified
+ * Returns a {@link Spliterator.OfDouble} covering all of the specified
* array.
*
* The spliterator reports {@link Spliterator#SIZED},
@@ -4437,7 +4598,7 @@
* {@link Spliterator#IMMUTABLE}.
*
* @param array The array, assumed to be unmodified during use
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @since 1.8
*/
@@ -4447,7 +4608,7 @@
}
/**
- * Creates a {@link Spliterator.OfDouble} covering the specified range of
+ * Returns a {@link Spliterator.OfDouble} covering the specified range of
* the specified array.
*
* The spliterator reports {@link Spliterator#SIZED},
@@ -4457,7 +4618,7 @@
* @param array The array, assumed to be unmodified during use
* @param fromIndex The least index (inclusive) to cover
* @param toIndex One past the greatest index to cover
- * @return A spliterator from the array
+ * @return the spliterator for the array elements
* @throws NullPointerException if the specified array is {@code null}
* @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
* {@code toIndex} is less than {@code fromIndex}, or
@@ -4468,4 +4629,134 @@
return Spliterators.spliterator(array, fromIndex, toIndex,
Spliterator.ORDERED | Spliterator.IMMUTABLE);
}
+
+ /**
+ * Returns a sequential {@link Stream} with the specified array as its
+ * source.
+ *
+ * @param