import java.util.*; /** * Sample JUnit for SWE 619 * @author Paul Ammann * See also MinTest.java and AllTests.java */ public class Min { /** * 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 Comparable min (List list) { Iterator itr = list.iterator(); if (itr.hasNext() == false) { throw new IllegalArgumentException("min: Empty list"); } Comparable result = (Comparable) itr.next(); if (result == null) throw new NullPointerException("Assignment3.min"); while (itr.hasNext()) { Comparable comp = (Comparable) itr.next(); if (comp.compareTo(result) < 0) { // throws NPE, CCE as needed result = comp; } } return result; } }