Exercise 7.1 The given code implements a list of Strings with four methods: count which counts the number of items in the list, using the traditional technique; mapStringToString and mapStringToBool, each of which creates a new list by applying the specified method to every item in the original list; and orMapString which returns true if one of the list items satisfied the given predicates. The last three methods take as argument an object which implements one of the two functional interfaces. The examples in the test suite illustrate the implementation which uses the anonymous inner classes.
In the test suite develop the test which consumes a list of String and produces a new list of Strings in which each String has been converted to all upper case letters.
In the test suite develop the test which consumes a list of Strings and determines whether a given String is one of the items in this list.
Develop a new method andMap in the class
AListStrings and its variants. The method will take as
argument an object which implements the Obj2Boolean
interface and returns true if every item in the
list satisfies the predicate defined in the class which implements
this interface.
Hint: Think of Scheme andmap.
Develop two tests for this method - selecting the predicates on your own. Make sure you explain clearly the purpose of your test!
Exercise 7.2 The given example sorts the list of
Persons by their full names, first names, and by the year of
birth, using the anonymous inner classes to implement the desired
Comparator interface.
Using the same technique, first develop a
list of CDs, where each CD has a title, artist name and the number
of tracks. Implement three different ways of sorting this list: by
titles, by artists, and by the number of tracks.