1 /* 2 * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package java.util.stream; 26 27 import java.util.Arrays; 28 import java.util.DoubleSummaryStatistics; 29 import java.util.Objects; 30 import java.util.OptionalDouble; 31 import java.util.PrimitiveIterator; 32 import java.util.Spliterator; 33 import java.util.Spliterators; 34 import java.util.function.BiConsumer; 35 import java.util.function.DoubleBinaryOperator; 36 import java.util.function.DoubleConsumer; 37 import java.util.function.DoubleFunction; 38 import java.util.function.DoublePredicate; 39 import java.util.function.DoubleSupplier; 40 import java.util.function.DoubleToIntFunction; 41 import java.util.function.DoubleToLongFunction; 42 import java.util.function.DoubleUnaryOperator; 43 import java.util.function.Function; 44 import java.util.function.ObjDoubleConsumer; 45 import java.util.function.Supplier; 46 47 /** 48 * A sequence of primitive double-valued elements supporting sequential and parallel 49 * aggregate operations. This is the {@code double} primitive specialization of 50 * {@link Stream}. 51 * 52 * <p>The following example illustrates an aggregate operation using 53 * {@link Stream} and {@link DoubleStream}, computing the sum of the weights of the 54 * red widgets: 55 * 56 * <pre>{@code 57 * double sum = widgets.stream() 58 * .filter(w -> w.getColor() == RED) 59 * .mapToDouble(w -> w.getWeight()) 60 * .sum(); 61 * }</pre> 62 * 63 * See the class documentation for {@link Stream} and the package documentation 64 * for <a href="package-summary.html">java.util.stream</a> for additional 65 * specification of streams, stream operations, stream pipelines, and 66 * parallelism. 67 * 68 * @since 1.8 69 * @see Stream 70 * @see <a href="package-summary.html">java.util.stream</a> 71 */ 72 public interface DoubleStream extends BaseStream<Double, DoubleStream> { 73 74 /** 75 * Returns a stream consisting of the elements of this stream that match 76 * the given predicate. 77 * 78 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 79 * operation</a>. 80 * 81 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 82 * <a href="package-summary.html#Statelessness">stateless</a> 83 * predicate to apply to each element to determine if it 84 * should be included 85 * @return the new stream 86 */ filter(DoublePredicate predicate)87 DoubleStream filter(DoublePredicate predicate); 88 89 /** 90 * Returns a stream consisting of the results of applying the given 91 * function to the elements of this stream. 92 * 93 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 94 * operation</a>. 95 * 96 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 97 * <a href="package-summary.html#Statelessness">stateless</a> 98 * function to apply to each element 99 * @return the new stream 100 */ map(DoubleUnaryOperator mapper)101 DoubleStream map(DoubleUnaryOperator mapper); 102 103 /** 104 * Returns an object-valued {@code Stream} consisting of the results of 105 * applying the given function to the elements of this stream. 106 * 107 * <p>This is an <a href="package-summary.html#StreamOps"> 108 * intermediate operation</a>. 109 * 110 * @param <U> the element type of the new stream 111 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 112 * <a href="package-summary.html#Statelessness">stateless</a> 113 * function to apply to each element 114 * @return the new stream 115 */ mapToObj(DoubleFunction<? extends U> mapper)116 <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper); 117 118 /** 119 * Returns an {@code IntStream} consisting of the results of applying the 120 * given function to the elements of this stream. 121 * 122 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 123 * operation</a>. 124 * 125 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 126 * <a href="package-summary.html#Statelessness">stateless</a> 127 * function to apply to each element 128 * @return the new stream 129 */ mapToInt(DoubleToIntFunction mapper)130 IntStream mapToInt(DoubleToIntFunction mapper); 131 132 /** 133 * Returns a {@code LongStream} consisting of the results of applying the 134 * given function to the elements of this stream. 135 * 136 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 137 * operation</a>. 138 * 139 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 140 * <a href="package-summary.html#Statelessness">stateless</a> 141 * function to apply to each element 142 * @return the new stream 143 */ mapToLong(DoubleToLongFunction mapper)144 LongStream mapToLong(DoubleToLongFunction mapper); 145 146 /** 147 * Returns a stream consisting of the results of replacing each element of 148 * this stream with the contents of a mapped stream produced by applying 149 * the provided mapping function to each element. Each mapped stream is 150 * {@link java.util.stream.BaseStream#close() closed} after its contents 151 * have been placed into this stream. (If a mapped stream is {@code null} 152 * an empty stream is used, instead.) 153 * 154 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 155 * operation</a>. 156 * 157 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 158 * <a href="package-summary.html#Statelessness">stateless</a> 159 * function to apply to each element which produces a 160 * {@code DoubleStream} of new values 161 * @return the new stream 162 * @see Stream#flatMap(Function) 163 */ flatMap(DoubleFunction<? extends DoubleStream> mapper)164 DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper); 165 166 /** 167 * Returns a stream consisting of the results of replacing each element of 168 * this stream with multiple elements, specifically zero or more elements. 169 * Replacement is performed by applying the provided mapping function to each 170 * element in conjunction with a {@linkplain DoubleConsumer consumer} argument 171 * that accepts replacement elements. The mapping function calls the consumer 172 * zero or more times to provide the replacement elements. 173 * 174 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 175 * operation</a>. 176 * 177 * <p>If the {@linkplain DoubleConsumer consumer} argument is used outside the scope of 178 * its application to the mapping function, the results are undefined. 179 * 180 * @implSpec 181 * The default implementation invokes {@link #flatMap flatMap} on this stream, 182 * passing a function that behaves as follows. First, it calls the mapper function 183 * with a {@code DoubleConsumer} that accumulates replacement elements into a newly created 184 * internal buffer. When the mapper function returns, it creates a {@code DoubleStream} from the 185 * internal buffer. Finally, it returns this stream to {@code flatMap}. 186 * 187 * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, 188 * <a href="package-summary.html#Statelessness">stateless</a> 189 * function that generates replacement elements 190 * @return the new stream 191 * @see Stream#mapMulti Stream.mapMulti 192 * @since 16 193 */ mapMulti(DoubleMapMultiConsumer mapper)194 default DoubleStream mapMulti(DoubleMapMultiConsumer mapper) { 195 Objects.requireNonNull(mapper); 196 return flatMap(e -> { 197 SpinedBuffer.OfDouble buffer = new SpinedBuffer.OfDouble(); 198 mapper.accept(e, buffer); 199 return StreamSupport.doubleStream(buffer.spliterator(), false); 200 }); 201 } 202 203 /** 204 * Returns a stream consisting of the distinct elements of this stream. The 205 * elements are compared for equality according to 206 * {@link java.lang.Double#compare(double, double)}. 207 * 208 * <p>This is a <a href="package-summary.html#StreamOps">stateful 209 * intermediate operation</a>. 210 * 211 * @return the result stream 212 */ distinct()213 DoubleStream distinct(); 214 215 /** 216 * Returns a stream consisting of the elements of this stream in sorted 217 * order. The elements are compared for equality according to 218 * {@link java.lang.Double#compare(double, double)}. 219 * 220 * <p>This is a <a href="package-summary.html#StreamOps">stateful 221 * intermediate operation</a>. 222 * 223 * @return the result stream 224 */ sorted()225 DoubleStream sorted(); 226 227 /** 228 * Returns a stream consisting of the elements of this stream, additionally 229 * performing the provided action on each element as elements are consumed 230 * from the resulting stream. 231 * 232 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 233 * operation</a>. 234 * 235 * <p>For parallel stream pipelines, the action may be called at 236 * whatever time and in whatever thread the element is made available by the 237 * upstream operation. If the action modifies shared state, 238 * it is responsible for providing the required synchronization. 239 * 240 * @apiNote This method exists mainly to support debugging, where you want 241 * to see the elements as they flow past a certain point in a pipeline: 242 * <pre>{@code 243 * DoubleStream.of(1, 2, 3, 4) 244 * .filter(e -> e > 2) 245 * .peek(e -> System.out.println("Filtered value: " + e)) 246 * .map(e -> e * e) 247 * .peek(e -> System.out.println("Mapped value: " + e)) 248 * .sum(); 249 * }</pre> 250 * 251 * <p>In cases where the stream implementation is able to optimize away the 252 * production of some or all the elements (such as with short-circuiting 253 * operations like {@code findFirst}, or in the example described in 254 * {@link #count}), the action will not be invoked for those elements. 255 * 256 * @param action a <a href="package-summary.html#NonInterference"> 257 * non-interfering</a> action to perform on the elements as 258 * they are consumed from the stream 259 * @return the new stream 260 */ peek(DoubleConsumer action)261 DoubleStream peek(DoubleConsumer action); 262 263 /** 264 * Returns a stream consisting of the elements of this stream, truncated 265 * to be no longer than {@code maxSize} in length. 266 * 267 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 268 * stateful intermediate operation</a>. 269 * 270 * @apiNote 271 * While {@code limit()} is generally a cheap operation on sequential 272 * stream pipelines, it can be quite expensive on ordered parallel pipelines, 273 * especially for large values of {@code maxSize}, since {@code limit(n)} 274 * is constrained to return not just any <em>n</em> elements, but the 275 * <em>first n</em> elements in the encounter order. Using an unordered 276 * stream source (such as {@link #generate(DoubleSupplier)}) or removing the 277 * ordering constraint with {@link #unordered()} may result in significant 278 * speedups of {@code limit()} in parallel pipelines, if the semantics of 279 * your situation permit. If consistency with encounter order is required, 280 * and you are experiencing poor performance or memory utilization with 281 * {@code limit()} in parallel pipelines, switching to sequential execution 282 * with {@link #sequential()} may improve performance. 283 * 284 * @param maxSize the number of elements the stream should be limited to 285 * @return the new stream 286 * @throws IllegalArgumentException if {@code maxSize} is negative 287 */ limit(long maxSize)288 DoubleStream limit(long maxSize); 289 290 /** 291 * Returns a stream consisting of the remaining elements of this stream 292 * after discarding the first {@code n} elements of the stream. 293 * If this stream contains fewer than {@code n} elements then an 294 * empty stream will be returned. 295 * 296 * <p>This is a <a href="package-summary.html#StreamOps">stateful 297 * intermediate operation</a>. 298 * 299 * @apiNote 300 * While {@code skip()} is generally a cheap operation on sequential 301 * stream pipelines, it can be quite expensive on ordered parallel pipelines, 302 * especially for large values of {@code n}, since {@code skip(n)} 303 * is constrained to skip not just any <em>n</em> elements, but the 304 * <em>first n</em> elements in the encounter order. Using an unordered 305 * stream source (such as {@link #generate(DoubleSupplier)}) or removing the 306 * ordering constraint with {@link #unordered()} may result in significant 307 * speedups of {@code skip()} in parallel pipelines, if the semantics of 308 * your situation permit. If consistency with encounter order is required, 309 * and you are experiencing poor performance or memory utilization with 310 * {@code skip()} in parallel pipelines, switching to sequential execution 311 * with {@link #sequential()} may improve performance. 312 * 313 * @param n the number of leading elements to skip 314 * @return the new stream 315 * @throws IllegalArgumentException if {@code n} is negative 316 */ skip(long n)317 DoubleStream skip(long n); 318 319 /** 320 * Returns, if this stream is ordered, a stream consisting of the longest 321 * prefix of elements taken from this stream that match the given predicate. 322 * Otherwise returns, if this stream is unordered, a stream consisting of a 323 * subset of elements taken from this stream that match the given predicate. 324 * 325 * <p>If this stream is ordered then the longest prefix is a contiguous 326 * sequence of elements of this stream that match the given predicate. The 327 * first element of the sequence is the first element of this stream, and 328 * the element immediately following the last element of the sequence does 329 * not match the given predicate. 330 * 331 * <p>If this stream is unordered, and some (but not all) elements of this 332 * stream match the given predicate, then the behavior of this operation is 333 * nondeterministic; it is free to take any subset of matching elements 334 * (which includes the empty set). 335 * 336 * <p>Independent of whether this stream is ordered or unordered if all 337 * elements of this stream match the given predicate then this operation 338 * takes all elements (the result is the same as the input), or if no 339 * elements of the stream match the given predicate then no elements are 340 * taken (the result is an empty stream). 341 * 342 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 343 * stateful intermediate operation</a>. 344 * 345 * @implSpec 346 * The default implementation obtains the {@link #spliterator() spliterator} 347 * of this stream, wraps that spliterator so as to support the semantics 348 * of this operation on traversal, and returns a new stream associated with 349 * the wrapped spliterator. The returned stream preserves the execution 350 * characteristics of this stream (namely parallel or sequential execution 351 * as per {@link #isParallel()}) but the wrapped spliterator may choose to 352 * not support splitting. When the returned stream is closed, the close 353 * handlers for both the returned and this stream are invoked. 354 * 355 * @apiNote 356 * While {@code takeWhile()} is generally a cheap operation on sequential 357 * stream pipelines, it can be quite expensive on ordered parallel 358 * pipelines, since the operation is constrained to return not just any 359 * valid prefix, but the longest prefix of elements in the encounter order. 360 * Using an unordered stream source (such as 361 * {@link #generate(DoubleSupplier)}) or removing the ordering constraint 362 * with {@link #unordered()} may result in significant speedups of 363 * {@code takeWhile()} in parallel pipelines, if the semantics of your 364 * situation permit. If consistency with encounter order is required, and 365 * you are experiencing poor performance or memory utilization with 366 * {@code takeWhile()} in parallel pipelines, switching to sequential 367 * execution with {@link #sequential()} may improve performance. 368 * 369 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 370 * <a href="package-summary.html#Statelessness">stateless</a> 371 * predicate to apply to elements to determine the longest 372 * prefix of elements. 373 * @return the new stream 374 * @since 9 375 */ takeWhile(DoublePredicate predicate)376 default DoubleStream takeWhile(DoublePredicate predicate) { 377 Objects.requireNonNull(predicate); 378 // Reuses the unordered spliterator, which, when encounter is present, 379 // is safe to use as long as it configured not to split 380 return StreamSupport.doubleStream( 381 new WhileOps.UnorderedWhileSpliterator.OfDouble.Taking(spliterator(), true, predicate), 382 isParallel()).onClose(this::close); 383 } 384 385 /** 386 * Returns, if this stream is ordered, a stream consisting of the remaining 387 * elements of this stream after dropping the longest prefix of elements 388 * that match the given predicate. Otherwise returns, if this stream is 389 * unordered, a stream consisting of the remaining elements of this stream 390 * after dropping a subset of elements that match the given predicate. 391 * 392 * <p>If this stream is ordered then the longest prefix is a contiguous 393 * sequence of elements of this stream that match the given predicate. The 394 * first element of the sequence is the first element of this stream, and 395 * the element immediately following the last element of the sequence does 396 * not match the given predicate. 397 * 398 * <p>If this stream is unordered, and some (but not all) elements of this 399 * stream match the given predicate, then the behavior of this operation is 400 * nondeterministic; it is free to drop any subset of matching elements 401 * (which includes the empty set). 402 * 403 * <p>Independent of whether this stream is ordered or unordered if all 404 * elements of this stream match the given predicate then this operation 405 * drops all elements (the result is an empty stream), or if no elements of 406 * the stream match the given predicate then no elements are dropped (the 407 * result is the same as the input). 408 * 409 * <p>This is a <a href="package-summary.html#StreamOps">stateful 410 * intermediate operation</a>. 411 * 412 * @implSpec 413 * The default implementation obtains the {@link #spliterator() spliterator} 414 * of this stream, wraps that spliterator so as to support the semantics 415 * of this operation on traversal, and returns a new stream associated with 416 * the wrapped spliterator. The returned stream preserves the execution 417 * characteristics of this stream (namely parallel or sequential execution 418 * as per {@link #isParallel()}) but the wrapped spliterator may choose to 419 * not support splitting. When the returned stream is closed, the close 420 * handlers for both the returned and this stream are invoked. 421 * 422 * @apiNote 423 * While {@code dropWhile()} is generally a cheap operation on sequential 424 * stream pipelines, it can be quite expensive on ordered parallel 425 * pipelines, since the operation is constrained to return not just any 426 * valid prefix, but the longest prefix of elements in the encounter order. 427 * Using an unordered stream source (such as 428 * {@link #generate(DoubleSupplier)}) or removing the ordering constraint 429 * with {@link #unordered()} may result in significant speedups of 430 * {@code dropWhile()} in parallel pipelines, if the semantics of your 431 * situation permit. If consistency with encounter order is required, and 432 * you are experiencing poor performance or memory utilization with 433 * {@code dropWhile()} in parallel pipelines, switching to sequential 434 * execution with {@link #sequential()} may improve performance. 435 * 436 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 437 * <a href="package-summary.html#Statelessness">stateless</a> 438 * predicate to apply to elements to determine the longest 439 * prefix of elements. 440 * @return the new stream 441 * @since 9 442 */ dropWhile(DoublePredicate predicate)443 default DoubleStream dropWhile(DoublePredicate predicate) { 444 Objects.requireNonNull(predicate); 445 // Reuses the unordered spliterator, which, when encounter is present, 446 // is safe to use as long as it configured not to split 447 return StreamSupport.doubleStream( 448 new WhileOps.UnorderedWhileSpliterator.OfDouble.Dropping(spliterator(), true, predicate), 449 isParallel()).onClose(this::close); 450 } 451 452 /** 453 * Performs an action for each element of this stream. 454 * 455 * <p>This is a <a href="package-summary.html#StreamOps">terminal 456 * operation</a>. 457 * 458 * <p>For parallel stream pipelines, this operation does <em>not</em> 459 * guarantee to respect the encounter order of the stream, as doing so 460 * would sacrifice the benefit of parallelism. For any given element, the 461 * action may be performed at whatever time and in whatever thread the 462 * library chooses. If the action accesses shared state, it is 463 * responsible for providing the required synchronization. 464 * 465 * @param action a <a href="package-summary.html#NonInterference"> 466 * non-interfering</a> action to perform on the elements 467 */ forEach(DoubleConsumer action)468 void forEach(DoubleConsumer action); 469 470 /** 471 * Performs an action for each element of this stream, guaranteeing that 472 * each element is processed in encounter order for streams that have a 473 * defined encounter order. 474 * 475 * <p>This is a <a href="package-summary.html#StreamOps">terminal 476 * operation</a>. 477 * 478 * @param action a <a href="package-summary.html#NonInterference"> 479 * non-interfering</a> action to perform on the elements 480 * @see #forEach(DoubleConsumer) 481 */ forEachOrdered(DoubleConsumer action)482 void forEachOrdered(DoubleConsumer action); 483 484 /** 485 * Returns an array containing the elements of this stream. 486 * 487 * <p>This is a <a href="package-summary.html#StreamOps">terminal 488 * operation</a>. 489 * 490 * @return an array containing the elements of this stream 491 */ toArray()492 double[] toArray(); 493 494 /** 495 * Performs a <a href="package-summary.html#Reduction">reduction</a> on the 496 * elements of this stream, using the provided identity value and an 497 * <a href="package-summary.html#Associativity">associative</a> 498 * accumulation function, and returns the reduced value. This is equivalent 499 * to: 500 * <pre>{@code 501 * double result = identity; 502 * for (double element : this stream) 503 * result = accumulator.applyAsDouble(result, element) 504 * return result; 505 * }</pre> 506 * 507 * but is not constrained to execute sequentially. 508 * 509 * <p>The {@code identity} value must be an identity for the accumulator 510 * function. This means that for all {@code x}, 511 * {@code accumulator.apply(identity, x)} is equal to {@code x}. 512 * The {@code accumulator} function must be an 513 * <a href="package-summary.html#Associativity">associative</a> function. 514 * 515 * <p>This is a <a href="package-summary.html#StreamOps">terminal 516 * operation</a>. 517 * 518 * @apiNote Sum, min, max, and average are all special cases of reduction. 519 * Summing a stream of numbers can be expressed as: 520 * 521 * <pre>{@code 522 * double sum = numbers.reduce(0, (a, b) -> a+b); 523 * }</pre> 524 * 525 * or more compactly: 526 * 527 * <pre>{@code 528 * double sum = numbers.reduce(0, Double::sum); 529 * }</pre> 530 * 531 * <p>While this may seem a more roundabout way to perform an aggregation 532 * compared to simply mutating a running total in a loop, reduction 533 * operations parallelize more gracefully, without needing additional 534 * synchronization and with greatly reduced risk of data races. 535 * 536 * @param identity the identity value for the accumulating function 537 * @param op an <a href="package-summary.html#Associativity">associative</a>, 538 * <a href="package-summary.html#NonInterference">non-interfering</a>, 539 * <a href="package-summary.html#Statelessness">stateless</a> 540 * function for combining two values 541 * @return the result of the reduction 542 * @see #sum() 543 * @see #min() 544 * @see #max() 545 * @see #average() 546 */ reduce(double identity, DoubleBinaryOperator op)547 double reduce(double identity, DoubleBinaryOperator op); 548 549 /** 550 * Performs a <a href="package-summary.html#Reduction">reduction</a> on the 551 * elements of this stream, using an 552 * <a href="package-summary.html#Associativity">associative</a> accumulation 553 * function, and returns an {@code OptionalDouble} describing the reduced 554 * value, if any. This is equivalent to: 555 * <pre>{@code 556 * boolean foundAny = false; 557 * double result = null; 558 * for (double element : this stream) { 559 * if (!foundAny) { 560 * foundAny = true; 561 * result = element; 562 * } 563 * else 564 * result = accumulator.applyAsDouble(result, element); 565 * } 566 * return foundAny ? OptionalDouble.of(result) : OptionalDouble.empty(); 567 * }</pre> 568 * 569 * but is not constrained to execute sequentially. 570 * 571 * <p>The {@code accumulator} function must be an 572 * <a href="package-summary.html#Associativity">associative</a> function. 573 * 574 * <p>This is a <a href="package-summary.html#StreamOps">terminal 575 * operation</a>. 576 * 577 * @param op an <a href="package-summary.html#Associativity">associative</a>, 578 * <a href="package-summary.html#NonInterference">non-interfering</a>, 579 * <a href="package-summary.html#Statelessness">stateless</a> 580 * function for combining two values 581 * @return the result of the reduction 582 * @see #reduce(double, DoubleBinaryOperator) 583 */ reduce(DoubleBinaryOperator op)584 OptionalDouble reduce(DoubleBinaryOperator op); 585 586 /** 587 * Performs a <a href="package-summary.html#MutableReduction">mutable 588 * reduction</a> operation on the elements of this stream. A mutable 589 * reduction is one in which the reduced value is a mutable result container, 590 * such as an {@code ArrayList}, and elements are incorporated by updating 591 * the state of the result rather than by replacing the result. This 592 * produces a result equivalent to: 593 * <pre>{@code 594 * R result = supplier.get(); 595 * for (double element : this stream) 596 * accumulator.accept(result, element); 597 * return result; 598 * }</pre> 599 * 600 * <p>Like {@link #reduce(double, DoubleBinaryOperator)}, {@code collect} 601 * operations can be parallelized without requiring additional 602 * synchronization. 603 * 604 * <p>This is a <a href="package-summary.html#StreamOps">terminal 605 * operation</a>. 606 * 607 * @param <R> the type of the mutable result container 608 * @param supplier a function that creates a new mutable result container. 609 * For a parallel execution, this function may be called 610 * multiple times and must return a fresh value each time. 611 * @param accumulator an <a href="package-summary.html#Associativity">associative</a>, 612 * <a href="package-summary.html#NonInterference">non-interfering</a>, 613 * <a href="package-summary.html#Statelessness">stateless</a> 614 * function that must fold an element into a result 615 * container. 616 * @param combiner an <a href="package-summary.html#Associativity">associative</a>, 617 * <a href="package-summary.html#NonInterference">non-interfering</a>, 618 * <a href="package-summary.html#Statelessness">stateless</a> 619 * function that accepts two partial result containers 620 * and merges them, which must be compatible with the 621 * accumulator function. The combiner function must fold 622 * the elements from the second result container into the 623 * first result container. 624 * @return the result of the reduction 625 * @see Stream#collect(Supplier, BiConsumer, BiConsumer) 626 */ collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R, R> combiner)627 <R> R collect(Supplier<R> supplier, 628 ObjDoubleConsumer<R> accumulator, 629 BiConsumer<R, R> combiner); 630 631 /** 632 * Returns the sum of elements in this stream. 633 * 634 * Summation is a special case of a <a 635 * href="package-summary.html#Reduction">reduction</a>. If 636 * floating-point summation were exact, this method would be 637 * equivalent to: 638 * 639 * <pre>{@code 640 * return reduce(0, Double::sum); 641 * }</pre> 642 * 643 * However, since floating-point summation is not exact, the above 644 * code is not necessarily equivalent to the summation computation 645 * done by this method. 646 * 647 * <p>The value of a floating-point sum is a function both 648 * of the input values as well as the order of addition 649 * operations. The order of addition operations of this method is 650 * intentionally not defined to allow for implementation 651 * flexibility to improve the speed and accuracy of the computed 652 * result. 653 * 654 * In particular, this method may be implemented using compensated 655 * summation or other technique to reduce the error bound in the 656 * numerical sum compared to a simple summation of {@code double} 657 * values. 658 * 659 * Because of the unspecified order of operations and the 660 * possibility of using differing summation schemes, the output of 661 * this method may vary on the same input elements. 662 * 663 * <p>Various conditions can result in a non-finite sum being 664 * computed. This can occur even if the all the elements 665 * being summed are finite. If any element is non-finite, 666 * the sum will be non-finite: 667 * 668 * <ul> 669 * 670 * <li>If any element is a NaN, then the final sum will be 671 * NaN. 672 * 673 * <li>If the elements contain one or more infinities, the 674 * sum will be infinite or NaN. 675 * 676 * <ul> 677 * 678 * <li>If the elements contain infinities of opposite sign, 679 * the sum will be NaN. 680 * 681 * <li>If the elements contain infinities of one sign and 682 * an intermediate sum overflows to an infinity of the opposite 683 * sign, the sum may be NaN. 684 * 685 * </ul> 686 * 687 * </ul> 688 * 689 * It is possible for intermediate sums of finite values to 690 * overflow into opposite-signed infinities; if that occurs, the 691 * final sum will be NaN even if the elements are all 692 * finite. 693 * 694 * If all the elements are zero, the sign of zero is 695 * <em>not</em> guaranteed to be preserved in the final sum. 696 * 697 * <p>This is a <a href="package-summary.html#StreamOps">terminal 698 * operation</a>. 699 * 700 * @apiNote Elements sorted by increasing absolute magnitude tend 701 * to yield more accurate results. 702 * 703 * @return the sum of elements in this stream 704 */ sum()705 double sum(); 706 707 /** 708 * Returns an {@code OptionalDouble} describing the minimum element of this 709 * stream, or an empty OptionalDouble if this stream is empty. The minimum 710 * element will be {@code Double.NaN} if any stream element was NaN. Unlike 711 * the numerical comparison operators, this method considers negative zero 712 * to be strictly smaller than positive zero. This is a special case of a 713 * <a href="package-summary.html#Reduction">reduction</a> and is 714 * equivalent to: 715 * <pre>{@code 716 * return reduce(Double::min); 717 * }</pre> 718 * 719 * <p>This is a <a href="package-summary.html#StreamOps">terminal 720 * operation</a>. 721 * 722 * @return an {@code OptionalDouble} containing the minimum element of this 723 * stream, or an empty optional if the stream is empty 724 */ min()725 OptionalDouble min(); 726 727 /** 728 * Returns an {@code OptionalDouble} describing the maximum element of this 729 * stream, or an empty OptionalDouble if this stream is empty. The maximum 730 * element will be {@code Double.NaN} if any stream element was NaN. Unlike 731 * the numerical comparison operators, this method considers negative zero 732 * to be strictly smaller than positive zero. This is a 733 * special case of a 734 * <a href="package-summary.html#Reduction">reduction</a> and is 735 * equivalent to: 736 * <pre>{@code 737 * return reduce(Double::max); 738 * }</pre> 739 * 740 * <p>This is a <a href="package-summary.html#StreamOps">terminal 741 * operation</a>. 742 * 743 * @return an {@code OptionalDouble} containing the maximum element of this 744 * stream, or an empty optional if the stream is empty 745 */ max()746 OptionalDouble max(); 747 748 /** 749 * Returns the count of elements in this stream. This is a special case of 750 * a <a href="package-summary.html#Reduction">reduction</a> and is 751 * equivalent to: 752 * <pre>{@code 753 * return mapToLong(e -> 1L).sum(); 754 * }</pre> 755 * 756 * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>. 757 * 758 * @apiNote 759 * An implementation may choose to not execute the stream pipeline (either 760 * sequentially or in parallel) if it is capable of computing the count 761 * directly from the stream source. In such cases no source elements will 762 * be traversed and no intermediate operations will be evaluated. 763 * Behavioral parameters with side-effects, which are strongly discouraged 764 * except for harmless cases such as debugging, may be affected. For 765 * example, consider the following stream: 766 * <pre>{@code 767 * DoubleStream s = DoubleStream.of(1, 2, 3, 4); 768 * long count = s.peek(System.out::println).count(); 769 * }</pre> 770 * The number of elements covered by the stream source is known and the 771 * intermediate operation, {@code peek}, does not inject into or remove 772 * elements from the stream (as may be the case for {@code flatMap} or 773 * {@code filter} operations). Thus the count is 4 and there is no need to 774 * execute the pipeline and, as a side-effect, print out the elements. 775 * 776 * @return the count of elements in this stream 777 */ count()778 long count(); 779 780 /** 781 * Returns an {@code OptionalDouble} describing the arithmetic 782 * mean of elements of this stream, or an empty optional if this 783 * stream is empty. 784 * 785 * <p>The computed average can vary numerically and have the 786 * special case behavior as computing the sum; see {@link #sum} 787 * for details. 788 * 789 * <p>The average is a special case of a <a 790 * href="package-summary.html#Reduction">reduction</a>. 791 * 792 * <p>This is a <a href="package-summary.html#StreamOps">terminal 793 * operation</a>. 794 * 795 * @apiNote Elements sorted by increasing absolute magnitude tend 796 * to yield more accurate results. 797 * 798 * @return an {@code OptionalDouble} containing the average element of this 799 * stream, or an empty optional if the stream is empty 800 */ average()801 OptionalDouble average(); 802 803 /** 804 * Returns a {@code DoubleSummaryStatistics} describing various summary data 805 * about the elements of this stream. This is a special 806 * case of a <a href="package-summary.html#Reduction">reduction</a>. 807 * 808 * <p>This is a <a href="package-summary.html#StreamOps">terminal 809 * operation</a>. 810 * 811 * @return a {@code DoubleSummaryStatistics} describing various summary data 812 * about the elements of this stream 813 */ summaryStatistics()814 DoubleSummaryStatistics summaryStatistics(); 815 816 /** 817 * Returns whether any elements of this stream match the provided 818 * predicate. May not evaluate the predicate on all elements if not 819 * necessary for determining the result. If the stream is empty then 820 * {@code false} is returned and the predicate is not evaluated. 821 * 822 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 823 * terminal operation</a>. 824 * 825 * @apiNote 826 * This method evaluates the <em>existential quantification</em> of the 827 * predicate over the elements of the stream (for some x P(x)). 828 * 829 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 830 * <a href="package-summary.html#Statelessness">stateless</a> 831 * predicate to apply to elements of this stream 832 * @return {@code true} if any elements of the stream match the provided 833 * predicate, otherwise {@code false} 834 */ 835 boolean anyMatch(DoublePredicate predicate); 836 837 /** 838 * Returns whether all elements of this stream match the provided predicate. 839 * May not evaluate the predicate on all elements if not necessary for 840 * determining the result. If the stream is empty then {@code true} is 841 * returned and the predicate is not evaluated. 842 * 843 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 844 * terminal operation</a>. 845 * 846 * @apiNote 847 * This method evaluates the <em>universal quantification</em> of the 848 * predicate over the elements of the stream (for all x P(x)). If the 849 * stream is empty, the quantification is said to be <em>vacuously 850 * satisfied</em> and is always {@code true} (regardless of P(x)). 851 * 852 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 853 * <a href="package-summary.html#Statelessness">stateless</a> 854 * predicate to apply to elements of this stream 855 * @return {@code true} if either all elements of the stream match the 856 * provided predicate or the stream is empty, otherwise {@code false} 857 */ 858 boolean allMatch(DoublePredicate predicate); 859 860 /** 861 * Returns whether no elements of this stream match the provided predicate. 862 * May not evaluate the predicate on all elements if not necessary for 863 * determining the result. If the stream is empty then {@code true} is 864 * returned and the predicate is not evaluated. 865 * 866 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 867 * terminal operation</a>. 868 * 869 * @apiNote 870 * This method evaluates the <em>universal quantification</em> of the 871 * negated predicate over the elements of the stream (for all x ~P(x)). If 872 * the stream is empty, the quantification is said to be vacuously satisfied 873 * and is always {@code true}, regardless of P(x). 874 * 875 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, 876 * <a href="package-summary.html#Statelessness">stateless</a> 877 * predicate to apply to elements of this stream 878 * @return {@code true} if either no elements of the stream match the 879 * provided predicate or the stream is empty, otherwise {@code false} 880 */ 881 boolean noneMatch(DoublePredicate predicate); 882 883 /** 884 * Returns an {@link OptionalDouble} describing the first element of this 885 * stream, or an empty {@code OptionalDouble} if the stream is empty. If 886 * the stream has no encounter order, then any element may be returned. 887 * 888 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 889 * terminal operation</a>. 890 * 891 * @return an {@code OptionalDouble} describing the first element of this 892 * stream, or an empty {@code OptionalDouble} if the stream is empty 893 */ findFirst()894 OptionalDouble findFirst(); 895 896 /** 897 * Returns an {@link OptionalDouble} describing some element of the stream, 898 * or an empty {@code OptionalDouble} if the stream is empty. 899 * 900 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting 901 * terminal operation</a>. 902 * 903 * <p>The behavior of this operation is explicitly nondeterministic; it is 904 * free to select any element in the stream. This is to allow for maximal 905 * performance in parallel operations; the cost is that multiple invocations 906 * on the same source may not return the same result. (If a stable result 907 * is desired, use {@link #findFirst()} instead.) 908 * 909 * @return an {@code OptionalDouble} describing some element of this stream, 910 * or an empty {@code OptionalDouble} if the stream is empty 911 * @see #findFirst() 912 */ findAny()913 OptionalDouble findAny(); 914 915 /** 916 * Returns a {@code Stream} consisting of the elements of this stream, 917 * boxed to {@code Double}. 918 * 919 * <p>This is an <a href="package-summary.html#StreamOps">intermediate 920 * operation</a>. 921 * 922 * @return a {@code Stream} consistent of the elements of this stream, 923 * each boxed to a {@code Double} 924 */ boxed()925 Stream<Double> boxed(); 926 927 @Override sequential()928 DoubleStream sequential(); 929 930 @Override parallel()931 DoubleStream parallel(); 932 933 @Override iterator()934 PrimitiveIterator.OfDouble iterator(); 935 936 @Override spliterator()937 Spliterator.OfDouble spliterator(); 938 939 940 // Static factories 941 942 /** 943 * Returns a builder for a {@code DoubleStream}. 944 * 945 * @return a stream builder 946 */ builder()947 public static Builder builder() { 948 return new Streams.DoubleStreamBuilderImpl(); 949 } 950 951 /** 952 * Returns an empty sequential {@code DoubleStream}. 953 * 954 * @return an empty sequential stream 955 */ empty()956 public static DoubleStream empty() { 957 return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator(), false); 958 } 959 960 /** 961 * Returns a sequential {@code DoubleStream} containing a single element. 962 * 963 * @param t the single element 964 * @return a singleton sequential stream 965 */ of(double t)966 public static DoubleStream of(double t) { 967 return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t), false); 968 } 969 970 /** 971 * Returns a sequential ordered stream whose elements are the specified values. 972 * 973 * @param values the elements of the new stream 974 * @return the new stream 975 */ of(double... values)976 public static DoubleStream of(double... values) { 977 return Arrays.stream(values); 978 } 979 980 /** 981 * Returns an infinite sequential ordered {@code DoubleStream} produced by iterative 982 * application of a function {@code f} to an initial element {@code seed}, 983 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, 984 * {@code f(f(seed))}, etc. 985 * 986 * <p>The first element (position {@code 0}) in the {@code DoubleStream} 987 * will be the provided {@code seed}. For {@code n > 0}, the element at 988 * position {@code n}, will be the result of applying the function {@code f} 989 * to the element at position {@code n - 1}. 990 * 991 * <p>The action of applying {@code f} for one element 992 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a> 993 * the action of applying {@code f} for subsequent elements. For any given 994 * element the action may be performed in whatever thread the library 995 * chooses. 996 * 997 * @param seed the initial element 998 * @param f a function to be applied to the previous element to produce 999 * a new element 1000 * @return a new sequential {@code DoubleStream} 1001 */ iterate(final double seed, final DoubleUnaryOperator f)1002 public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) { 1003 Objects.requireNonNull(f); 1004 Spliterator.OfDouble spliterator = new Spliterators.AbstractDoubleSpliterator(Long.MAX_VALUE, 1005 Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) { 1006 double prev; 1007 boolean started; 1008 1009 @Override 1010 public boolean tryAdvance(DoubleConsumer action) { 1011 Objects.requireNonNull(action); 1012 double t; 1013 if (started) 1014 t = f.applyAsDouble(prev); 1015 else { 1016 t = seed; 1017 started = true; 1018 } 1019 action.accept(prev = t); 1020 return true; 1021 } 1022 }; 1023 return StreamSupport.doubleStream(spliterator, false); 1024 } 1025 1026 /** 1027 * Returns a sequential ordered {@code DoubleStream} produced by iterative 1028 * application of the given {@code next} function to an initial element, 1029 * conditioned on satisfying the given {@code hasNext} predicate. The 1030 * stream terminates as soon as the {@code hasNext} predicate returns false. 1031 * 1032 * <p>{@code DoubleStream.iterate} should produce the same sequence of elements as 1033 * produced by the corresponding for-loop: 1034 * <pre>{@code 1035 * for (double index=seed; hasNext.test(index); index = next.applyAsDouble(index)) { 1036 * ... 1037 * } 1038 * }</pre> 1039 * 1040 * <p>The resulting sequence may be empty if the {@code hasNext} predicate 1041 * does not hold on the seed value. Otherwise the first element will be the 1042 * supplied {@code seed} value, the next element (if present) will be the 1043 * result of applying the {@code next} function to the {@code seed} value, 1044 * and so on iteratively until the {@code hasNext} predicate indicates that 1045 * the stream should terminate. 1046 * 1047 * <p>The action of applying the {@code hasNext} predicate to an element 1048 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a> 1049 * the action of applying the {@code next} function to that element. The 1050 * action of applying the {@code next} function for one element 1051 * <i>happens-before</i> the action of applying the {@code hasNext} 1052 * predicate for subsequent elements. For any given element an action may 1053 * be performed in whatever thread the library chooses. 1054 * 1055 * @param seed the initial element 1056 * @param hasNext a predicate to apply to elements to determine when the 1057 * stream must terminate. 1058 * @param next a function to be applied to the previous element to produce 1059 * a new element 1060 * @return a new sequential {@code DoubleStream} 1061 * @since 9 1062 */ iterate(double seed, DoublePredicate hasNext, DoubleUnaryOperator next)1063 public static DoubleStream iterate(double seed, DoublePredicate hasNext, DoubleUnaryOperator next) { 1064 Objects.requireNonNull(next); 1065 Objects.requireNonNull(hasNext); 1066 Spliterator.OfDouble spliterator = new Spliterators.AbstractDoubleSpliterator(Long.MAX_VALUE, 1067 Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) { 1068 double prev; 1069 boolean started, finished; 1070 1071 @Override 1072 public boolean tryAdvance(DoubleConsumer action) { 1073 Objects.requireNonNull(action); 1074 if (finished) 1075 return false; 1076 double t; 1077 if (started) 1078 t = next.applyAsDouble(prev); 1079 else { 1080 t = seed; 1081 started = true; 1082 } 1083 if (!hasNext.test(t)) { 1084 finished = true; 1085 return false; 1086 } 1087 action.accept(prev = t); 1088 return true; 1089 } 1090 1091 @Override 1092 public void forEachRemaining(DoubleConsumer action) { 1093 Objects.requireNonNull(action); 1094 if (finished) 1095 return; 1096 finished = true; 1097 double t = started ? next.applyAsDouble(prev) : seed; 1098 while (hasNext.test(t)) { 1099 action.accept(t); 1100 t = next.applyAsDouble(t); 1101 } 1102 } 1103 }; 1104 return StreamSupport.doubleStream(spliterator, false); 1105 } 1106 1107 /** 1108 * Returns an infinite sequential unordered stream where each element is 1109 * generated by the provided {@code DoubleSupplier}. This is suitable for 1110 * generating constant streams, streams of random elements, etc. 1111 * 1112 * @param s the {@code DoubleSupplier} for generated elements 1113 * @return a new infinite sequential unordered {@code DoubleStream} 1114 */ generate(DoubleSupplier s)1115 public static DoubleStream generate(DoubleSupplier s) { 1116 Objects.requireNonNull(s); 1117 return StreamSupport.doubleStream( 1118 new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false); 1119 } 1120 1121 /** 1122 * Creates a lazily concatenated stream whose elements are all the 1123 * elements of the first stream followed by all the elements of the 1124 * second stream. The resulting stream is ordered if both 1125 * of the input streams are ordered, and parallel if either of the input 1126 * streams is parallel. When the resulting stream is closed, the close 1127 * handlers for both input streams are invoked. 1128 * 1129 * <p>This method operates on the two input streams and binds each stream 1130 * to its source. As a result subsequent modifications to an input stream 1131 * source may not be reflected in the concatenated stream result. 1132 * 1133 * @implNote 1134 * Use caution when constructing streams from repeated concatenation. 1135 * Accessing an element of a deeply concatenated stream can result in deep 1136 * call chains, or even {@code StackOverflowError}. 1137 * 1138 * @apiNote 1139 * To preserve optimization opportunities this method binds each stream to 1140 * its source and accepts only two streams as parameters. For example, the 1141 * exact size of the concatenated stream source can be computed if the exact 1142 * size of each input stream source is known. 1143 * To concatenate more streams without binding, or without nested calls to 1144 * this method, try creating a stream of streams and flat-mapping with the 1145 * identity function, for example: 1146 * <pre>{@code 1147 * DoubleStream concat = Stream.of(s1, s2, s3, s4).flatMapToDouble(s -> s); 1148 * }</pre> 1149 * 1150 * @param a the first stream 1151 * @param b the second stream 1152 * @return the concatenation of the two input streams 1153 */ concat(DoubleStream a, DoubleStream b)1154 public static DoubleStream concat(DoubleStream a, DoubleStream b) { 1155 Objects.requireNonNull(a); 1156 Objects.requireNonNull(b); 1157 1158 Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble( 1159 a.spliterator(), b.spliterator()); 1160 DoubleStream stream = StreamSupport.doubleStream(split, a.isParallel() || b.isParallel()); 1161 return stream.onClose(Streams.composedClose(a, b)); 1162 } 1163 1164 /** 1165 * A mutable builder for a {@code DoubleStream}. 1166 * 1167 * <p>A stream builder has a lifecycle, which starts in a building 1168 * phase, during which elements can be added, and then transitions to a built 1169 * phase, after which elements may not be added. The built phase 1170 * begins when the {@link #build()} method is called, which creates an 1171 * ordered stream whose elements are the elements that were added to the 1172 * stream builder, in the order they were added. 1173 * 1174 * @see DoubleStream#builder() 1175 * @since 1.8 1176 */ 1177 public interface Builder extends DoubleConsumer { 1178 1179 /** 1180 * Adds an element to the stream being built. 1181 * 1182 * @throws IllegalStateException if the builder has already transitioned 1183 * to the built state 1184 */ 1185 @Override accept(double t)1186 void accept(double t); 1187 1188 /** 1189 * Adds an element to the stream being built. 1190 * 1191 * @implSpec 1192 * The default implementation behaves as if: 1193 * <pre>{@code 1194 * accept(t) 1195 * return this; 1196 * }</pre> 1197 * 1198 * @param t the element to add 1199 * @return {@code this} builder 1200 * @throws IllegalStateException if the builder has already transitioned 1201 * to the built state 1202 */ add(double t)1203 default Builder add(double t) { 1204 accept(t); 1205 return this; 1206 } 1207 1208 /** 1209 * Builds the stream, transitioning this builder to the built state. 1210 * An {@code IllegalStateException} is thrown if there are further 1211 * attempts to operate on the builder after it has entered the built 1212 * state. 1213 * 1214 * @return the built stream 1215 * @throws IllegalStateException if the builder has already transitioned 1216 * to the built state 1217 */ build()1218 DoubleStream build(); 1219 } 1220 1221 /** 1222 * Represents an operation that accepts a {@code double}-valued argument 1223 * and a DoubleConsumer, and returns no result. This functional interface is 1224 * used by {@link DoubleStream#mapMulti(DoubleMapMultiConsumer) DoubleStream.mapMulti} 1225 * to replace a double value with zero or more double values. 1226 * 1227 * <p>This is a <a href="../function/package-summary.html">functional interface</a> 1228 * whose functional method is {@link #accept(double, DoubleConsumer)}. 1229 * 1230 * @see DoubleStream#mapMulti(DoubleMapMultiConsumer) 1231 * 1232 * @since 16 1233 */ 1234 @FunctionalInterface 1235 interface DoubleMapMultiConsumer { 1236 1237 /** 1238 * Replaces the given {@code value} with zero or more values by feeding the mapped 1239 * values to the {@code dc} consumer. 1240 * 1241 * @param value the double value coming from upstream 1242 * @param dc a {@code DoubleConsumer} accepting the mapped values 1243 */ accept(double value, DoubleConsumer dc)1244 void accept(double value, DoubleConsumer dc); 1245 } 1246 } 1247