MCPcopy Index your code
hub / github.com/apache/tomcat / compare

Method compare

java/org/apache/el/stream/Stream.java:579–610  ·  view source on GitHub ↗
(boolean isMax)

Source from the content-addressed store, hash-verified

577
578
579 @SuppressWarnings({ "rawtypes", "unchecked" })
580 private Optional compare(boolean isMax) {
581 Comparable result = null;
582
583 if (iterator.hasNext()) {
584 Object obj = iterator.next();
585 if ((obj instanceof Comparable)) {
586 result = (Comparable) obj;
587 } else {
588 throw new ELException(MessageFactory.get("stream.compare.notComparable"));
589 }
590 }
591
592 while (iterator.hasNext()) {
593 Object obj = iterator.next();
594 if ((obj instanceof Comparable)) {
595 if (isMax && ((Comparable) obj).compareTo(result) > 0) {
596 result = (Comparable) obj;
597 } else if (!isMax && ((Comparable) obj).compareTo(result) < 0) {
598 result = (Comparable) obj;
599 }
600 } else {
601 throw new ELException(MessageFactory.get("stream.compare.notComparable"));
602 }
603 }
604
605 if (result == null) {
606 return Optional.EMPTY;
607 } else {
608 return new Optional(result);
609 }
610 }
611
612
613 private Optional compare(boolean isMax, LambdaExpression le) {

Callers 2

maxMethod · 0.95
minMethod · 0.95

Calls 6

getMethod · 0.95
coerceToNumberMethod · 0.95
hasNextMethod · 0.65
nextMethod · 0.65
compareToMethod · 0.65
invokeMethod · 0.65

Tested by

no test coverage detected