com.jnape.palatable.lambda.internal.iteration.InitIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
package com.jnape.palatable.lambda.internal.iteration;
import java.util.Iterator;
import java.util.NoSuchElementException;
public final class InitIterator extends ImmutableIterator {
private final Iterator asIterator;
private A queued;
public InitIterator(Iterable as) {
asIterator = as.iterator();
}
@Override
public boolean hasNext() {
if (queued == null)
if (asIterator.hasNext())
queued = asIterator.next();
return asIterator.hasNext();
}
@Override
public A next() {
if (!hasNext())
throw new NoSuchElementException();
A next = queued;
queued = asIterator.next();
return next;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy