| 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) { |