diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2020-09-10 17:12:59 -0300 |
| commit | 229054f4839ad99c8c9fc757cce7edc0d2ca3cf1 (patch) | |
| tree | f9de568967b82c46f6d22eda9c843529b6045b5d /src/main/java/bjc/inflexion/QueuedIterator.java | |
| parent | cb45132debdbce593a235323e9155b5c47906558 (diff) | |
| parent | e71ef0d03e87df19900db8328cda68d38d523b0b (diff) | |
Merge branch 'master' of https://github.com/bculkin2442/Inflexion
Diffstat (limited to 'src/main/java/bjc/inflexion/QueuedIterator.java')
| -rw-r--r-- | src/main/java/bjc/inflexion/QueuedIterator.java | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/src/main/java/bjc/inflexion/QueuedIterator.java b/src/main/java/bjc/inflexion/QueuedIterator.java index cbc9a00..0dc98a1 100644 --- a/src/main/java/bjc/inflexion/QueuedIterator.java +++ b/src/main/java/bjc/inflexion/QueuedIterator.java @@ -6,10 +6,11 @@ import java.util.Iterator; /** * An iterator that supports queuing elements after/before the current iterator; - * + * * @author bjculkin * * @param <E> + * The type of element this iterator iterates over */ public class QueuedIterator<E> implements Iterator<E> { private Iterator<E> cur; @@ -18,7 +19,7 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Static method for constructing iterators. - * + * * @return A queued iterator. */ public static <E> QueuedIterator<E> queued() { @@ -27,9 +28,9 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Static method for constructing iterators. - * + * * @param itrs - * The iterators to use. + * The iterators to use. * @return A queued iterator over the provided iterators. */ @SafeVarargs @@ -39,9 +40,9 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Static method for constructing iterators. - * + * * @param itrs - * The iterables to use. + * The iterables to use. * @return A queued iterator over the provided iterables. */ @SafeVarargs @@ -58,9 +59,9 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Create a new queued iterator with a set of initial sources. - * + * * @param inits - * The set of initial iterators to use. + * The set of initial iterators to use. */ @SafeVarargs public QueuedIterator(Iterator<E>... inits) { @@ -73,9 +74,9 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Create a new queued iterator with a set of initial sources. - * + * * @param inits - * The set of initial iterables to use. + * The set of initial iterables to use. */ @SafeVarargs public QueuedIterator(Iterable<E>... inits) { @@ -88,9 +89,9 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Add a new iterator who we will iterate through first. - * + * * @param itr - * The iterator to go through first. + * The iterator to go through first. */ public void before(Iterator<E> itr) { pending.push(cur); @@ -100,38 +101,39 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Add a new iterable who we will iterate through first. - * + * * @param itr - * The iterable to go through first. + * The iterable to go through first. */ public void before(Iterable<E> itr) { before(itr.iterator()); } - + /** * Add a new iterator who we will iterate through next. - * + * * @param itr - * The iterator to go through next. + * The iterator to go through next. */ public void after(Iterator<E> itr) { pending.push(itr); } + /** * Add a new iterable who we will iterate through next. - * + * * @param itr - * The iterable to go through next. + * The iterable to go through next. */ public void after(Iterable<E> itr) { after(itr.iterator()); } - + /** * Add a new iterator who we will iterate through last. - * + * * @param itr - * The iterator to go through last. + * The iterator to go through last. */ public void last(Iterator<E> itr) { pending.add(itr); @@ -139,17 +141,19 @@ public class QueuedIterator<E> implements Iterator<E> { /** * Add a new iterable who we will iterate through last. - * + * * @param itr - * The iterable to go through last. + * The iterable to go through last. */ public void last(Iterable<E> itr) { last(itr.iterator()); } + @Override public boolean hasNext() { while (cur == null || !cur.hasNext()) { - if (pending.isEmpty()) return false; + if (pending.isEmpty()) + return false; cur = pending.pop(); } @@ -160,7 +164,8 @@ public class QueuedIterator<E> implements Iterator<E> { @Override public E next() { while (cur == null || !cur.hasNext()) { - if (pending.isEmpty()) return null; + if (pending.isEmpty()) + return null; cur = pending.pop(); } |
