/** * Finds the maximum of the elements according to their natural ordering. If there are several maxima, the first one * will be returned. * * @param iterator * the mutually comparable elements. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterator is empty * @since 2.7 */ public static <T extends Comparable<? super T>> T max(final Iterator<T> iterator) { return max(iterator, Ordering.natural()); }
/** * Finds the maximum element according to <code>comparator</code>. If there are several maxima, the first one will * be returned. * * @param iterable * the elements to find the maximum of. May not be <code>null</code>. * @param comparator * the comparison function. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterable is empty * @since 2.7 */ public static <T> T max(final Iterable<T> iterable, Comparator<? super T> comparator) { return IteratorExtensions.max(iterable.iterator(), comparator); } }
/** * Finds the maximum of the elements according to their natural ordering. If there are several maxima, the first one * will be returned. * * @param iterator * the mutually comparable elements. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterator is empty * @since 2.7 */ public static <T extends Comparable<? super T>> T max(final Iterator<T> iterator) { return max(iterator, Ordering.natural()); }
/** * Finds the maximum element according to <code>comparator</code>. If there are several maxima, the first one will * be returned. * * @param iterable * the elements to find the maximum of. May not be <code>null</code>. * @param comparator * the comparison function. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterable is empty * @since 2.7 */ public static <T> T max(final Iterable<T> iterable, Comparator<? super T> comparator) { return IteratorExtensions.max(iterable.iterator(), comparator); } }
/** * Finds the maximum of the elements according to their natural ordering. If there are several maxima, the first one * will be returned. * * @param iterable * the mutually comparable elements. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterable is empty * @since 2.7 */ public static <T extends Comparable<? super T>> T max(final Iterable<T> iterable) { // cannot special-case for SortedSet since we want to find the first one that is a maximum // where Set.last would return the last of the seemingly equal maximum elements return IteratorExtensions.max(iterable.iterator()); }
/** * Finds the maximum of the elements according to their natural ordering. If there are several maxima, the first one * will be returned. * * @param iterable * the mutually comparable elements. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterable is empty * @since 2.7 */ public static <T extends Comparable<? super T>> T max(final Iterable<T> iterable) { // cannot special-case for SortedSet since we want to find the first one that is a maximum // where Set.last would return the last of the seemingly equal maximum elements return IteratorExtensions.max(iterable.iterator()); }
/** * Finds the element that yields the maximum value when passed to <code>compareBy</code> If there are several * maxima, the first one will be returned. * * @param iterator * the elements to find the maximum of. May not be <code>null</code>. * @param compareBy * a function that returns a comparable characteristic to compare the elements by. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterator is empty * @since 2.7 */ public static <T, C extends Comparable<? super C>> T maxBy(final Iterator<T> iterator, final Function1<? super T, C> compareBy) { if (compareBy == null) throw new NullPointerException("compareBy"); return max(iterator, new KeyComparator<T, C>(compareBy)); }
/** * Finds the element that yields the maximum value when passed to <code>compareBy</code> If there are several * maxima, the first one will be returned. * * @param iterator * the elements to find the maximum of. May not be <code>null</code>. * @param compareBy * a function that returns a comparable characteristic to compare the elements by. May not be <code>null</code>. * @return the maximum * @throws NoSuchElementException * if the iterator is empty * @since 2.7 */ public static <T, C extends Comparable<? super C>> T maxBy(final Iterator<T> iterator, final Function1<? super T, C> compareBy) { if (compareBy == null) throw new NullPointerException("compareBy"); return max(iterator, new KeyComparator<T, C>(compareBy)); }