From 16e1e23250063d7885b790d082d2118f83693028 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Thu, 11 Apr 2019 18:59:02 -0300 Subject: QueuedIterator changes --- .../main/java/bjc/utils/data/QueuedIterator.java | 61 +++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'base/src/main/java/bjc/utils/data/QueuedIterator.java') diff --git a/base/src/main/java/bjc/utils/data/QueuedIterator.java b/base/src/main/java/bjc/utils/data/QueuedIterator.java index d75a9a3..0eeac4d 100644 --- a/base/src/main/java/bjc/utils/data/QueuedIterator.java +++ b/base/src/main/java/bjc/utils/data/QueuedIterator.java @@ -25,11 +25,24 @@ public class QueuedIterator implements Iterator { return new QueuedIterator<>(); } + /** + * Static method for constructing iterators. + * + * @param vals + * The values to iterate over. + * + * @return A queued iterator. + */ + public static QueuedIterator queued(E... vals) { + return new QueuedIterator<>(new ArrayIterator<>(vals)); + } + /** * Static method for constructing iterators. * * @param itrs - * The iterators to use. + * The iterators to use. + * * @return A queued iterator over the provided iterators. */ @SafeVarargs @@ -41,7 +54,8 @@ public class QueuedIterator implements Iterator { * Static method for constructing iterators. * * @param itrs - * The iterables to use. + * The iterables to use. + * * @return A queued iterator over the provided iterables. */ @SafeVarargs @@ -86,6 +100,17 @@ public class QueuedIterator implements Iterator { } } + /** + * Create a new queued iterator with a set of initial values. + * + * @param vals + * The set of initial values to use. + */ + @SafeVarargs + public QueuedIterator(E... vals) { + this(new ArrayIterator(vals)); + } + /** * Add a new iterator who we will iterate through first. * @@ -108,6 +133,16 @@ public class QueuedIterator implements Iterator { before(itr.iterator()); } + /** + * Add a new set of values who we will iterate through first. + * + * @param vals + * Values to iterate over first. + */ + public void before(E... vals) { + before(new ArrayIterator<>(vals)); + } + /** * Add a new iterator who we will iterate through next. * @@ -117,6 +152,7 @@ public class QueuedIterator implements Iterator { public void after(Iterator itr) { pending.push(itr); } + /** * Add a new iterable who we will iterate through next. * @@ -126,6 +162,16 @@ public class QueuedIterator implements Iterator { public void after(Iterable itr) { after(itr.iterator()); } + + /** + * Add a new set of values who we will iterate through next. + * + * @param vals + * The values to iterate over next. + */ + public void after(E... vals) { + after(new ArrayIterator<>(vals)); + } /** * Add a new iterator who we will iterate through last. @@ -146,6 +192,17 @@ public class QueuedIterator implements Iterator { public void last(Iterable itr) { last(itr.iterator()); } + + /** + * Add a new set of values who we will iterate through last. + * + * @param itr + * The iterable to go through last. + */ + public void last(E... vals) { + last(new ArrayIterator<>(vals)); + } + @Override public boolean hasNext() { while (cur == null || !cur.hasNext()) { -- cgit v1.2.3