Here you can find the source of minOrMax(int sign, Collection
private static <T extends Comparable> T minOrMax(int sign, Collection<T> values)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static <T extends Comparable> T minOrMax(int sign, Collection<T> values) { if (values.isEmpty()) { return null; }/*from ww w . j av a2 s . co m*/ T result = values.iterator().next(); for (T value : values) { if (value == null) { continue; } if ((result == null) || (result.compareTo(value) * sign < 0)) { result = value; } } return result; } private static <T extends Comparable> T minOrMax(int sign, T... values) { if (values.length == 0) { return null; } T result = values[0]; for (T value : values) { if (value == null) { continue; } if ((result == null) || (result.compareTo(value) * sign < 0)) { result = value; } } return result; } private static int minOrMax(int sign, int... values) { if (values.length == 0) { return 0; } int result = values[0]; for (int value : values) { if ((result - value) * sign < 0) { result = value; } } return result; } public static boolean isEmpty(Object[] array) { return array == null || array.length == 0; } }