summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/data/GeneratingIterator.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/data/GeneratingIterator.java')
-rw-r--r--base/src/main/java/bjc/utils/data/GeneratingIterator.java22
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;
}
-
}