And the starter code is...
import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException;
/** * Defines a library of selection methods on Collections. * * @author YOUR NAME (you@auburn.edu) * @author Dean Hendrix (dh@auburn.edu) * @version TODAY * */ public final class Selector {
/** * Can't instantiate this class. * * D O N O T C H A N G E T H I S C O N S T R U C T O R * */ private Selector() { }
/** * Returns the minimum value in the Collection coll as defined by the * Comparator comp. If either coll or comp is null, this method throws an * IllegalArgumentException. If coll is empty, this method throws a * NoSuchElementException. This method will not change coll in any way. * * @param coll the Collection from which the minimum is selected * @param comp the Comparator that defines the total order on T * @return the minimum value in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T min(Collection coll, Comparator comp) { return null; }
/** * Selects the maximum value in the Collection coll as defined by the * Comparator comp. If either coll or comp is null, this method throws an * IllegalArgumentException. If coll is empty, this method throws a * NoSuchElementException. This method will not change coll in any way. * * @param coll the Collection from which the maximum is selected * @param comp the Comparator that defines the total order on T * @return the maximum value in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T max(Collection coll, Comparator comp) { return null; }
/** * Selects the kth minimum value from the Collection coll as defined by the * Comparator comp. If either coll or comp is null, this method throws an * IllegalArgumentException. If coll is empty or if there is no kth minimum * value, this method throws a NoSuchElementException. This method will not * change coll in any way. * * @param coll the Collection from which the kth minimum is selected * @param k the k-selection value * @param comp the Comparator that defines the total order on T * @return the kth minimum value in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T kmin(Collection coll, int k, Comparator comp) { return null; }
/** * Selects the kth maximum value from the Collection coll as defined by the * Comparator comp. If either coll or comp is null, this method throws an * IllegalArgumentException. If coll is empty or if there is no kth maximum * value, this method throws a NoSuchElementException. This method will not * change coll in any way. * * @param coll the Collection from which the kth maximum is selected * @param k the k-selection value * @param comp the Comparator that defines the total order on T * @return the kth maximum value in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T kmax(Collection coll, int k, Comparator comp) { return null; }
/** * Returns a new Collection containing all the values in the Collection coll * that are greater than or equal to low and less than or equal to high, as * defined by the Comparator comp. The returned collection must contain only * these values and no others. The values low and high themselves do not have * to be in coll. Any duplicate values that are in coll must also be in the * returned Collection. If no values in coll fall into the specified range or * if coll is empty, this method throws a NoSuchElementException. If either * coll or comp is null, this method throws an IllegalArgumentException. This * method will not change coll in any way. * * @param coll the Collection from which the range values are selected * @param low the lower bound of the range * @param high the upper bound of the range * @param comp the Comparator that defines the total order on T * @return a Collection of values between low and high * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static Collection range(Collection coll, T low, T high, Comparator comp) { return null; }
/** * Returns the smallest value in the Collection coll that is greater than * or equal to key, as defined by the Comparator comp. The value of key * does not have to be in coll. If coll or comp is null, this method throws * an IllegalArgumentException. If coll is empty or if there is no * qualifying value, this method throws a NoSuchElementException. This * method will not change coll in any way. * * @param coll the Collection from which the ceiling value is selected * @param key the reference value * @param comp the Comparator that defines the total order on T * @return the ceiling value of key in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T ceiling(Collection coll, T key, Comparator comp) { return null; }
/** * Returns the largest value in the Collection coll that is less than * or equal to key, as defined by the Comparator comp. The value of key * does not have to be in coll. If coll or comp is null, this method throws * an IllegalArgumentException. If coll is empty or if there is no * qualifying value, this method throws a NoSuchElementException. This * method will not change coll in any way. * * @param coll the Collection from which the floor value is selected * @param key the reference value * @param comp the Comparator that defines the total order on T * @return the floor value of key in coll * @throws IllegalArgumentException as per above * @throws NoSuchElementException as per above */ public static T floor(Collection coll, T key, Comparator comp) { return null; }
}
Problem Overview This assignment focuses on implementing the methods of a class much like java.util.Collections. The Selector.java file defines a class with static methods that implement polymorphic algorithms that operate on and/or return Collections. Each method of Selector is very clearly specified, is independent of the other methods in the class, and is designed to provide relatively simple functionality. So, this is a great context for practicing what we've been discussing in lecture - generalized programming and test-based The Selector class You must correctly implement all the method bodies of the provided Selector class. Your implementation must adhere eractly to the API of the Selector class, as described in the provided source code comments and as described below public class Selector public static
T min (CollectionT c, Comparator comp) public static T> T max (Collection T> C, Comparator comp) public static T kmin (Collection c, int k, Comparator T kmax (Collection c, int k, Comparator CollectionT> range (Collection c, T low, high, Comparator comp) public public T> T T ceiling (CollectionT> c, floor(CollectionT> c, T key, ComparatorT> comp) key, ComparatorT> comp> static static The sections that follow provide details of each method's behavior as well as specific examples. The min method. This method selects the minimum value from a given collection, as defined by a given comparator. If either the collection or comparator is null, this method throws an IlegalArgumentException. If the collection is empty, the method throws a NoSuchElementException. The collection must not be changed by this method. T min(c, comp) 2, 8, 7, 3,4 5, 9, 1,7,3] 8, 7, 6, 5, IAS), (B.4). (.3), (D.2), (E. I)| 1(A,5), (B.4). (C.3), (D.2), (E. I)| comp ascending order descending order ascending order ascending by Stringfield ascending by Integer field (String, Integer) (String, Integer) (A5) (EJ) The max method. This method selects the maximu value from a given collection, as defined by a given comparator. If either the collection or comparator is nul, this method throws an IlegalArgumentException. If the collection is empty, the method throws a NoSuchElementException. The collection must not be changed by this method. Eramples: max(, comp) 2, 8, 7, 3, 4 5, 9, 1, 7,3) 8, 7, 6, 5,4 1(A.5), (B.4), (.3), (D.2), (E. 11 |(A.5), (B.4), (.3), (D.2). (E. 11 ascending order descending order ascending order ascending by Stringfield ascending by Integer field Integer (String, Integer) (E.1) (A5) (String, Integer) The kmin method. This method selects the kh miniu value from a given collection, as defined by a given comparator. A value is the kk minium if there are exactly k-1 values less than it in the collection. If either the collection or comparator is null, this method throws an IlegalArgumentExcepton I the collection is empty or if there is no khmini lu this method throws a NoSuchElementException. Note thatthere is no kth minimum value if k is less than 1, k is greater than the number of elements in the collection, or if k is greater than the number of distinet values in the collection. The collection must not be changed by this method. k comp T kmin(e, k, comp) 2, 8, 7, 3,4 5, 9, 1, 7,3) 8, 7, 6, 5,4 |(A.5), (B.4), (.3), (D.2), (E. 11 |(A.5), (B.4), (.3), (D.2). (E. 11 Integer I ascending order 2descending order 3 ascending order 4 2 Integer (String, Integer) ascending by Stringfield ascending by Integer field (D.2) (D.2) (String. Integer) The kmax method. This method selects thekumvl from a given collection, as defined by a given comparator. A value is the kth maximu if there are exactly k 1 values greater than it in the collection. If either the collection or comparator is nul, this method throws an IllegalArgument Exception I the collection is empty or if there is no kh mini vlue, this method throws a NoSuchElement Exception. Note that there is no kth minimum value if k is less than 1 k is greater than the b of elements in the collection, or if k is greater than the number of distinet values in the collection. The collection must not be changed by this method. k comp T kmax(c, k, comp) 2, 8, 7, 3,4 Integer Integer Integer (String, Integer) (String, Integer) I ascending order 2descending order 3 ascending order 4 2 1(A,5), (B.4), (.3), (D.2), (E. 11 |(A.5), (B.4), (.3), (D.2). (E. 11 ascending by Stringfield ascending by Integer jeld (B.4) (B.4) The range method. This method returns a collection of all valuesi from a given collection such that lousiS high, as defined by the given comparator, including duplicate values. (Note that lo and high do not have to be actual values in the given collection.) The returned collection contains only values in the range low..high, and no others. If there are no qualifying values, including the case where e is empty, this method throws a NoSuchEle ment Exception. This method throws an egalArgumentException if either the collection or comparator is null. The collection is not changed by this method. Eramples low high comp T-rauge ow, high, comp) 2, 8, 7, 3, 4 1 5 ascending onder2,3,4 ascending order descending order ascending order asc. by Stringfield ase. by Integer field Integer Integer Integer 7, 6, 5, 4 1(A,5), (B.4), (.3] 1(A.5), (B.4). (.3] 7, 6, 5, 4 I(B.4).(C3)| 1(A.5).(B.4)1 (String, Integer) (B.3) (F.4) (C,5) (G.7) (String, Integer) The ceiling method. This method returns the smallest value i in a given collection such that i 2 key, as defined by the given comparator. (Note that key does not have to be an actual value in the given collection.) If the given collec- tion or comparator is null, this method throws an legalArgumentExoeption. If the collection is empty or if there is no qualifying value i, this method throws a NoSuchElementException. Eram key comp T-ceiling(c, key, comp) 18, 7.6, 5, 4] |(A.5), (B.4), (C.3), (D.2). (E. 11 |(A.5), (B.4), (.3), (D.2). (E. 11 ascending order descending order ascending order ascending by Stringfield ascending by Integer field (String, Integer) (B.9) (F.0) (B.4) (E.1) (String, Integer) The floor method. This method returns the largest value i in a given collection such that i key, as defined by the given com- parator. (Note that key does not have to be an actual value in the given collection.) If the given collection or comparator is null, this method throws an IlegalArgument Exception. If the collection is empty or if there is no qualifying value i, this method throws a NoSuchElement Exception. key comp T Boor(e, key, comp) 2, 8, 7, 3, 4 5, 9, 1, 7,3) 18, 7.6, 54] ascending order descending order ascending order Integer String, Integer (A,5), (B4), C3) (D,2), (E(F,0) ascending by String field E.1) (String, Integer) 1(.5). (B.4). (.3). (D.2). (E. 11 (B.9) ascending by Integer field (AS) Notes and other rcquircments Here are other specifie requirements, notes, and suggestions. Read this handout carefully. Read the provided source code carefully. Ask questions on Piazza. Start early and be proactive The coustructor has been completed for you and must not be changed in any way. You may add any number of private methods that you like, but you may not add any public method or constructor, or may you change the signature of any public method or constructor You must not add any fields, either public or private, to the Selector class. You must not add any import statements to those already in the Selector class. You may not change or delete any import statement in the Selector class. You may not use fully-qualified names to cireuvent the restrictions on imports above, except in the one instance noted below None of the methods in the Selector class can modify the Collection parameter in any way. More generally, the methods in the Selector class should have no side-effects. You are only allowed to use sorting as part of your solution to kmin and kmax. You are not required to use sorting, but you are allowed to do so for these two methods only. If you use sorting, you ust do so by calling the java.util.Collections.sort (List, Comparator) method. You must use the fully-qualified name (no importing Collections) and you are allowed at most two calls to this method at most one in kmin and at most one in kmax The use of the ArrayList class is allowed only in kmin, kmax, and range. No other method is allowed to use any implementing class of Collection. The declaration or use of an array in any method is strictly prohibited. .Your code must be type safe; that is, your code must compile cleanly with no compiler warnings