diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 13:41:07 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 13:41:07 -0300 |
| commit | 946cab444bc301d8a7c756a1bab039558288de89 (patch) | |
| tree | 419f27c39a509bcd83cae0e6630be8eb7ff95a30 /base/src/main/java/bjc/utils/data/GeneratingIterator.java | |
| parent | c82e3b3b2de0633317ec8fc85925e91422820597 (diff) | |
Cleanup work
Diffstat (limited to 'base/src/main/java/bjc/utils/data/GeneratingIterator.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/data/GeneratingIterator.java | 22 |
1 files changed, 14 insertions, 8 deletions
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 <E> - * The type of element generated. + * The type of element generated. */ public class GeneratingIterator<E> implements Iterator<E> { + /* Our current state. */ private E state; - + /* The function to use to transition states. */ private UnaryOperator<E> transtion; - + /* The predicate to indicate where to stop. */ private Predicate<E> 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<E> transition, Predicate<E> stopper) { state = initial; @@ -43,11 +44,16 @@ public class GeneratingIterator<E> implements Iterator<E> { 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; } - } |
