summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/inflexion/QueuedIterator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bjc/inflexion/QueuedIterator.java')
-rw-r--r--src/main/java/bjc/inflexion/QueuedIterator.java59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/main/java/bjc/inflexion/QueuedIterator.java b/src/main/java/bjc/inflexion/QueuedIterator.java
index ab4a447..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
+ * @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();
}