485 * @param <R> type of the result 486 * @param supplier a function that creates a new result container. For a 487 * parallel execution, this function may be called 488 * multiple times and must return a fresh value each time. 489 * @param accumulator an <a href="package-summary.html#Associativity">associative</a> 490 * <a href="package-summary.html#NonInterference">non-interfering, 491 * stateless</a> function for incorporating an additional 492 * element into a result 493 * @param combiner an <a href="package-summary.html#Associativity">associative</a> 494 * <a href="package-summary.html#NonInterference">non-interfering, 495 * stateless</a> function for combining two values, which 496 * must be compatible with the accumulator function 497 * @return the result of the reduction 498 * @see Stream#collect(Supplier, BiConsumer, BiConsumer) 499 */ 500 <R> R collect(Supplier<R> supplier, 501 ObjDoubleConsumer<R> accumulator, 502 BiConsumer<R, R> combiner); 503 504 /** 505 * Returns the sum of elements in this stream. The sum returned can vary 506 * depending upon the order in which elements are encountered. This is due 507 * to accumulated rounding error in addition of values of differing 508 * magnitudes. Elements sorted by increasing absolute magnitude tend to 509 * yield more accurate results. If any stream element is a {@code NaN} or 510 * the sum is at any point a {@code NaN} then the sum will be {@code NaN}. 511 * This is a special case of a 512 * <a href="package-summary.html#Reduction">reduction</a> and is 513 * equivalent to: 514 * <pre>{@code 515 * return reduce(0, Double::sum); 516 * }</pre> 517 * 518 * <p>This is a <a href="package-summary.html#StreamOps">terminal 519 * operation</a>. 520 * 521 * @return the sum of elements in this stream 522 */ 523 double sum(); 524 525 /** 526 * Returns an {@code OptionalDouble} describing the minimum element of this 527 * stream, or an empty OptionalDouble if this stream is empty. The minimum 528 * element will be {@code Double.NaN} if any stream element was NaN. Unlike 529 * the numerical comparison operators, this method considers negative zero 530 * to be strictly smaller than positive zero. This is a special case of a 531 * <a href="package-summary.html#Reduction">reduction</a> and is 532 * equivalent to: 533 * <pre>{@code 534 * return reduce(Double::min); 535 * }</pre> 536 * 537 * <p>This is a <a href="package-summary.html#StreamOps">terminal 538 * operation</a>. 539 * 540 * @return an {@code OptionalDouble} containing the minimum element of this 561 * @return an {@code OptionalDouble} containing the maximum element of this 562 * stream, or an empty optional if the stream is empty 563 */ 564 OptionalDouble max(); 565 566 /** 567 * Returns the count of elements in this stream. This is a special case of 568 * a <a href="package-summary.html#Reduction">reduction</a> and is 569 * equivalent to: 570 * <pre>{@code 571 * return mapToLong(e -> 1L).sum(); 572 * }</pre> 573 * 574 * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>. 575 * 576 * @return the count of elements in this stream 577 */ 578 long count(); 579 580 /** 581 * Returns an {@code OptionalDouble} describing the arithmetic mean of elements of 582 * this stream, or an empty optional if this stream is empty. The average 583 * returned can vary depending upon the order in which elements are 584 * encountered. This is due to accumulated rounding error in addition of 585 * elements of differing magnitudes. Elements sorted by increasing absolute 586 * magnitude tend to yield more accurate results. If any recorded value is 587 * a {@code NaN} or the sum is at any point a {@code NaN} then the average 588 * will be {@code NaN}. This is a special case of a 589 * <a href="package-summary.html#Reduction">reduction</a>. 590 * 591 * <p>This is a <a href="package-summary.html#StreamOps">terminal 592 * operation</a>. 593 * 594 * @return an {@code OptionalDouble} containing the average element of this 595 * stream, or an empty optional if the stream is empty 596 */ 597 OptionalDouble average(); 598 599 /** 600 * Returns a {@code DoubleSummaryStatistics} describing various summary data 601 * about the elements of this stream. This is a special 602 * case of a <a href="package-summary.html#Reduction">reduction</a>. 603 * 604 * <p>This is a <a href="package-summary.html#StreamOps">terminal 605 * operation</a>. 606 * 607 * @return a {@code DoubleSummaryStatistics} describing various summary data 608 * about the elements of this stream 609 */ 610 DoubleSummaryStatistics summaryStatistics(); 611 612 /** | 485 * @param <R> type of the result 486 * @param supplier a function that creates a new result container. For a 487 * parallel execution, this function may be called 488 * multiple times and must return a fresh value each time. 489 * @param accumulator an <a href="package-summary.html#Associativity">associative</a> 490 * <a href="package-summary.html#NonInterference">non-interfering, 491 * stateless</a> function for incorporating an additional 492 * element into a result 493 * @param combiner an <a href="package-summary.html#Associativity">associative</a> 494 * <a href="package-summary.html#NonInterference">non-interfering, 495 * stateless</a> function for combining two values, which 496 * must be compatible with the accumulator function 497 * @return the result of the reduction 498 * @see Stream#collect(Supplier, BiConsumer, BiConsumer) 499 */ 500 <R> R collect(Supplier<R> supplier, 501 ObjDoubleConsumer<R> accumulator, 502 BiConsumer<R, R> combiner); 503 504 /** 505 * Returns the sum of elements in this stream. 506 * 507 * Summation is a special case of a <a 508 * href="package-summary.html#Reduction">reduction</a>. If 509 * floating-point summation were exact, this method would be 510 * equivalent to: 511 * 512 * <pre>{@code 513 * return reduce(0, Double::sum); 514 * }</pre> 515 * 516 * However, since floating-point summation is not exact, the above 517 * code is not necessarily equivalent to the summation computation 518 * done by this method. 519 * 520 * <p>If any stream element is a NaN or the sum is at any point a NaN 521 * then the sum will be NaN. 522 * 523 * The value of a floating-point sum is a function both 524 * of the input values as well as the order of addition 525 * operations. The order of addition operations of this method is 526 * intentionally not defined to allow for implementation 527 * flexibility to improve the speed and accuracy of the computed 528 * result. 529 * 530 * In particular, this method may be implemented using compensated 531 * summation or other technique to reduce the error bound in the 532 * numerical sum compared to a simple summation of {@code double} 533 * values. 534 * 535 * <p>This is a <a href="package-summary.html#StreamOps">terminal 536 * operation</a>. 537 * 538 * @apiNote Sorting values by increasing absolute magnitude tends to yield 539 * more accurate results. 540 * 541 * @return the sum of elements in this stream 542 */ 543 double sum(); 544 545 /** 546 * Returns an {@code OptionalDouble} describing the minimum element of this 547 * stream, or an empty OptionalDouble if this stream is empty. The minimum 548 * element will be {@code Double.NaN} if any stream element was NaN. Unlike 549 * the numerical comparison operators, this method considers negative zero 550 * to be strictly smaller than positive zero. This is a special case of a 551 * <a href="package-summary.html#Reduction">reduction</a> and is 552 * equivalent to: 553 * <pre>{@code 554 * return reduce(Double::min); 555 * }</pre> 556 * 557 * <p>This is a <a href="package-summary.html#StreamOps">terminal 558 * operation</a>. 559 * 560 * @return an {@code OptionalDouble} containing the minimum element of this 581 * @return an {@code OptionalDouble} containing the maximum element of this 582 * stream, or an empty optional if the stream is empty 583 */ 584 OptionalDouble max(); 585 586 /** 587 * Returns the count of elements in this stream. This is a special case of 588 * a <a href="package-summary.html#Reduction">reduction</a> and is 589 * equivalent to: 590 * <pre>{@code 591 * return mapToLong(e -> 1L).sum(); 592 * }</pre> 593 * 594 * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>. 595 * 596 * @return the count of elements in this stream 597 */ 598 long count(); 599 600 /** 601 * Returns an {@code OptionalDouble} describing the arithmetic 602 * mean of elements of this stream, or an empty optional if this 603 * stream is empty. 604 * 605 * If any recorded value is a NaN or the sum is at any point a NaN 606 * then the average will be NaN. 607 * 608 * <p>The average returned can vary depending upon the order in 609 * which values are recorded. 610 * 611 * This method may be implemented using compensated summation or 612 * other technique to reduce the error bound in the {@link #sum 613 * numerical sum} used to compute the average. 614 * 615 * <p>The average is a special case of a <a 616 * href="package-summary.html#Reduction">reduction</a>. 617 * 618 * <p>This is a <a href="package-summary.html#StreamOps">terminal 619 * operation</a>. 620 * 621 * @apiNote Elements sorted by increasing absolute magnitude tend 622 * to yield more accurate results. 623 * 624 * @return an {@code OptionalDouble} containing the average element of this 625 * stream, or an empty optional if the stream is empty 626 */ 627 OptionalDouble average(); 628 629 /** 630 * Returns a {@code DoubleSummaryStatistics} describing various summary data 631 * about the elements of this stream. This is a special 632 * case of a <a href="package-summary.html#Reduction">reduction</a>. 633 * 634 * <p>This is a <a href="package-summary.html#StreamOps">terminal 635 * operation</a>. 636 * 637 * @return a {@code DoubleSummaryStatistics} describing various summary data 638 * about the elements of this stream 639 */ 640 DoubleSummaryStatistics summaryStatistics(); 641 642 /** |