Understanding orMap
Look at the first two variants of the orMap method (the
recursively defined variant and the variant that uses the
while 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 new ArrayList that contains all
elements of the original list that satisfy the given ISelect
predicate.
Test the methods by producing all red balloons or all small balloons.
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 checking whether a list contains all red balloons or all small balloons.
Repeat all the parts of the previous task 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.
Optionally, you may look at the ultimate abstraction of these traversals shown in the ForEach class.
Read the tests for for each variant of the compute method of the ForEach class shown in the Examples class. Make sure you understand how they work. Design additional tests for each of the three compute methods.