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/TransformIterator.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/TransformIterator.java')
| -rw-r--r-- | src/main/java/bjc/data/TransformIterator.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/bjc/data/TransformIterator.java b/src/main/java/bjc/data/TransformIterator.java new file mode 100644 index 0000000..0fc127a --- /dev/null +++ b/src/main/java/bjc/data/TransformIterator.java @@ -0,0 +1,46 @@ +package bjc.data; + +import java.util.Iterator; +import java.util.function.Function; + +/** + * An iterator that transforms values from one type to another. + * + * @author EVE + * + * @param <S> + * The source iterator type. + * + * @param <D> + * The destination iterator type. + */ +public class TransformIterator<S, D> implements Iterator<D> { + /* Our source of values. */ + private final Iterator<S> source; + /* Transform function. */ + private final Function<S, D> transform; + + /** + * Create a new transform iterator. + * + * @param source + * The source iterator to use. + * + * @param transform + * The transform to apply. + */ + public TransformIterator(final Iterator<S> source, final Function<S, D> transform) { + this.source = source; + this.transform = transform; + } + + @Override + public boolean hasNext() { + return source.hasNext(); + } + + @Override + public D next() { + return transform.apply(source.next()); + } +} |
