MCPcopy Create free account
hub / github.com/apache/tomcat / average

Method average

java/org/apache/el/stream/Stream.java:451–465  ·  view source on GitHub ↗

Calculates the average of all numeric elements in the stream. @return an Optional containing the average, or empty if the stream is empty

()

Source from the content-addressed store, hash-verified

449 * @return an Optional containing the average, or empty if the stream is empty
450 */
451 public Optional average() {
452 long count = 0;
453 Number sum = Long.valueOf(0);
454
455 while (iterator.hasNext()) {
456 count++;
457 sum = ELArithmetic.add(sum, iterator.next());
458 }
459
460 if (count == 0) {
461 return Optional.EMPTY;
462 } else {
463 return new Optional(ELArithmetic.divide(sum, Long.valueOf(count)));
464 }
465 }
466
467
468 /**

Callers 1

getRoundTripTimeNanoMethod · 0.80

Calls 5

addMethod · 0.95
divideMethod · 0.95
hasNextMethod · 0.65
nextMethod · 0.65
valueOfMethod · 0.45

Tested by

no test coverage detected