Task 3:
Look at the first two variants of the
orMap
method (the recursively defined variant and the variant that uses thewhile
loop. Identify the four parts (BASE-VALUE, Termination/Continuation PREDICATE, UPDATE, and ADVANCE) in each of them.Look also at the tests in the
Examples
class.After you understand how the
while
loop works, design two variants of the method that produces a newArrayList
that contains all elements of the original list that satisfy the givenISelect
predicate.Test the methods by producing all albums released before the given year.
Design and test two variants of the andMap method that determines whether all elements of a given list satisfy the given
ISelect
predicate.Test the methods by producing all albums released before the given year.
10.4 Converting while loops into for loops
If you have the time left, repeat al the parts of Task 3 with
the remaining two variants of the orMap
-- namely the one
that uses the for
loop with the Traversal
and the
one that uses counted for
loop.