diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-07-02 18:05:22 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-07-02 18:05:22 -0400 |
| commit | 843329de434bb334d90927c4d22345373a388530 (patch) | |
| tree | b0ad1f764bd29ff43841e1095a5b58194c20cb37 /src/main/java/bjc/data/SingleIterator.java | |
| parent | ac36f171a3cebb0993cc28548635e3f654f8e325 (diff) | |
Rename package root
The package root is now bjc, not io.github.bculkin2442.
Diffstat (limited to 'src/main/java/bjc/data/SingleIterator.java')
| -rw-r--r-- | src/main/java/bjc/data/SingleIterator.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/bjc/data/SingleIterator.java b/src/main/java/bjc/data/SingleIterator.java new file mode 100644 index 0000000..3144447 --- /dev/null +++ b/src/main/java/bjc/data/SingleIterator.java @@ -0,0 +1,42 @@ +package bjc.data; + +import java.util.Iterator; + +/** + * An iterator that will only ever yield one item. + * + * @author EVE + * + * @param <T> + * The type of the item. + */ +public class SingleIterator<T> implements Iterator<T> { + /* The item being held. */ + private final T itm; + /* Whether we've yielded the item yet. */ + private boolean yielded; + + /** + * Create a iterator that yields a single item. + * + * @param item + * The item to yield. + */ + public SingleIterator(final T item) { + itm = item; + + yielded = false; + } + + @Override + public boolean hasNext() { + return !yielded; + } + + @Override + public T next() { + yielded = true; + + return itm; + } +} |
