@Test public void max() { Comparator<Integer> reversed = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); assertEquals(Integer.valueOf(10), ComparatorUtils.max(1, 10, null)); assertEquals(Integer.valueOf(10), ComparatorUtils.max(10, -10, null)); assertEquals(Integer.valueOf(1), ComparatorUtils.max(1, 10, reversed)); assertEquals(Integer.valueOf(-10), ComparatorUtils.max(10, -10, reversed)); try { ComparatorUtils.max(1, null, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } try { ComparatorUtils.max(null, 10, null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
@SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private  ComparatorUtils(); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private  ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator,
            final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private  ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... comparators); @SuppressWarnings("unchecked") static Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators); static Comparator<E> reversedComparator(final Comparator<E> comparator); static Comparator<Boolean> booleanComparator(final boolean trueFirst); @SuppressWarnings("unchecked") static Comparator<E> nullLowComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<E> nullHighComparator(Comparator<E> comparator); @SuppressWarnings("unchecked") static Comparator<I> transformedComparator(Comparator<O> comparator,
            final Transformer<? super I, ? extends O> transformer); @SuppressWarnings("unchecked") static E min(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings("unchecked") static E max(final E o1, final E o2, Comparator<E> comparator); @SuppressWarnings({ "rawtypes", "unchecked" }) // explicit type needed for Java 1.5 compilation
    static final Comparator NATURAL_COMPARATOR; }