diff -r c58794ecca6c -r 46132d430504 jdk/src/java.base/share/classes/java/util/stream/IntStream.java --- a/jdk/src/java.base/share/classes/java/util/stream/IntStream.java Fri Sep 09 14:54:24 2016 -0700 +++ b/jdk/src/java.base/share/classes/java/util/stream/IntStream.java Fri Sep 09 14:54:29 2016 -0700 @@ -562,19 +562,23 @@ *
This is a terminal
* operation.
*
- * @param The action of applying {@code f} for one element
+ * happens-before
+ * the action of applying {@code f} for subsequent elements. For any given
+ * element the action may be performed in whatever thread the library
+ * chooses.
+ *
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
@@ -918,37 +928,44 @@
/**
* Returns a sequential ordered {@code IntStream} produced by iterative
- * application of a function to an initial element, conditioned on
- * satisfying the supplied predicate. The stream terminates as soon as
- * the predicate returns false.
+ * application of the given {@code next} function to an initial element,
+ * conditioned on satisfying the given {@code hasNext} predicate. The
+ * stream terminates as soon as the {@code hasNext} predicate returns false.
*
- *
- * {@code IntStream.iterate} should produce the same sequence of elements
- * as produced by the corresponding for-loop:
+ * {@code IntStream.iterate} should produce the same sequence of elements as
+ * produced by the corresponding for-loop:
*
- * The resulting sequence may be empty if the predicate does not hold on
- * the seed value. Otherwise the first element will be the supplied seed
- * value, the next element (if present) will be the result of applying the
- * function f to the seed value, and so on iteratively until the predicate
- * indicates that the stream should terminate.
+ * The resulting sequence may be empty if the {@code hasNext} predicate
+ * does not hold on the seed value. Otherwise the first element will be the
+ * supplied {@code seed} value, the next element (if present) will be the
+ * result of applying the {@code next} function to the {@code seed} value,
+ * and so on iteratively until the {@code hasNext} predicate indicates that
+ * the stream should terminate.
+ *
+ * The action of applying the {@code hasNext} predicate to an element
+ * happens-before
+ * the action of applying the {@code next} function to that element. The
+ * action of applying the {@code next} function for one element
+ * happens-before the action of applying the {@code hasNext}
+ * predicate for subsequent elements. For any given element an action may
+ * be performed in whatever thread the library chooses.
*
* @param seed the initial element
- * @param predicate a predicate to apply to elements to determine when the
- * stream must terminate.
- * @param f a function to be applied to the previous element to produce
- * a new element
+ * @param hasNext a predicate to apply to elements to determine when the
+ * stream must terminate.
+ * @param next a function to be applied to the previous element to produce
+ * a new element
* @return a new sequential {@code IntStream}
* @since 9
*/
- public static IntStream iterate(int seed, IntPredicate predicate, IntUnaryOperator f) {
- Objects.requireNonNull(f);
- Objects.requireNonNull(predicate);
+ public static IntStream iterate(int seed, IntPredicate hasNext, IntUnaryOperator next) {
+ Objects.requireNonNull(next);
+ Objects.requireNonNull(hasNext);
Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
int prev;
@@ -961,12 +978,12 @@
return false;
int t;
if (started)
- t = f.applyAsInt(prev);
+ t = next.applyAsInt(prev);
else {
t = seed;
started = true;
}
- if (!predicate.test(t)) {
+ if (!hasNext.test(t)) {
finished = true;
return false;
}
@@ -980,10 +997,10 @@
if (finished)
return;
finished = true;
- int t = started ? f.applyAsInt(prev) : seed;
- while (predicate.test(t)) {
+ int t = started ? next.applyAsInt(prev) : seed;
+ while (hasNext.test(t)) {
action.accept(t);
- t = f.applyAsInt(t);
+ t = next.applyAsInt(t);
}
}
};
{@code
- * for (int index=seed; predicate.test(index); index = f.applyAsInt(index)) {
+ * for (int index=seed; hasNext.test(index); index = next.applyAsInt(index)) {
* ...
* }
* }
*
- *