All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnape.palatable.lambda.internal.iteration.InitIterator Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
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