import java.util.*; /** * Sample JUnit for SWE 619 * @author Paul Ammann * See also MinTest.java and AllTests.java */ public class Min1 { /** * Returns the mininum element in a list * @param list Comparable list of elements to search * @return the minimum element in the list * @throws NullPointerException if list is null or * if any list elements are null * @throws ClassCastException if list elements are not mutually comparable * @throws IllegalArgumentException if list is empty */ public static > T min (List list) { if (list.size() == 0) { throw new IllegalArgumentException("Min1.min"); } T result = list.get(0); if (result == null) throw new NullPointerException("Min1.min"); for (T comp : list) { if (comp.compareTo(result) < 0) { // throws NPE, CCE as needed result = comp; } } return result; } }