From 946cab444bc301d8a7c756a1bab039558288de89 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Wed, 11 Oct 2017 13:41:07 -0300 Subject: Cleanup work --- .../java/bjc/utils/data/GeneratingIterator.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'base/src/main/java/bjc/utils/data/GeneratingIterator.java') diff --git a/base/src/main/java/bjc/utils/data/GeneratingIterator.java b/base/src/main/java/bjc/utils/data/GeneratingIterator.java index 9abca7c..92d10a5 100644 --- a/base/src/main/java/bjc/utils/data/GeneratingIterator.java +++ b/base/src/main/java/bjc/utils/data/GeneratingIterator.java @@ -10,27 +10,28 @@ import java.util.function.UnaryOperator; * @author bjculkin * * @param - * The type of element generated. + * The type of element generated. */ public class GeneratingIterator implements Iterator { + /* Our current state. */ private E state; - + /* The function to use to transition states. */ private UnaryOperator transtion; - + /* The predicate to indicate where to stop. */ private Predicate stpper; /** * Create a new generative iterator. * * @param initial - * The initial state of the generator. + * The initial state of the generator. * * @param transition - * The function to apply to the state. + * The function to apply to the state. * * @param stopper - * The predicate applied to the current state to - * determine when to stop. + * The predicate applied to the current state to + * determine when to stop. */ public GeneratingIterator(E initial, UnaryOperator transition, Predicate stopper) { state = initial; @@ -43,11 +44,16 @@ public class GeneratingIterator implements Iterator { return stpper.test(state); } + /* + * @NOTE + * As this currently is, it only works correctly assuming that + * next() is only called when hasNext() is true. Should we + * safeguard against people who are not doing the right thing? + */ @Override public E next() { state = transtion.apply(state); return state; } - } -- cgit v1.2.3