/*--------------------------------------------------------------------------- TEMPLATE - ANALYSIS: -------------------- ReturnType method-name(Traversal<T> tr){ +--------------------+ // invoke the methodAcc: | acc <-- BASE-VALUE | +--------------------+ method-name-acc(Traversal<T> tr, BASE-VALUE); } ReturnType method-name-acc(Traversal<T> tr, ReturnType acc) ... tr.isEmpty() ... -- boolean ::PREDICATE if true: ... acc -- ReturnType ::BASE-VALUE if false: +---------------+ ...| tr.getFirst() | ... -- T ::CURRENT +---------------+ ... update(T, ReturnType) -- ReturnType ::UPDATE +----------------------------+ i.e.: ...| update(tr.getFirst(), acc) | ... +----------------------------+ +--------------+ ... | tr.getRest() | -- Traversal<T> ::ADVANCE +--------------+ ... method-name(tr.getRest(), ReturnType) -- ReturnType i.e.: ... method-name-acc(tr.getRest(), update(tr.getFirst(), acc)) /---------------------------------------------------------------------------- COMPLETE METHOD TEMPLATE: ------------------------- <T> ReturnType method-name(Traversal<T> tr){ +----base-value------+ // invoke the methodAcc: | acc <-- BASE-VALUE | +--------------------+ method-name-acc(Traversal tr, BASE-VALUE); } <T> ReturnType method-name(Traversal<T> tr, ReturnType acc){ +---predicate--+ if (| tr.isEmpty() |) +--------------+ return acc; else +----advance---+ +----update-using-current----+ return method-name-acc(| tr.getRest() |, | update(tr.getFirst(), acc) |); +--------------+ +----------------------------+ } <T> return-type update(T t, return-type acc){ ... }