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

org.echocat.jsu.ContinuingGenerator Maven / Gradle / Ivy

There is a newer version: 2.0.6
Show newest version
package org.echocat.jsu;

import org.echocat.jsu.Generator.Value;

import javax.annotation.Nonnull;
import java.util.Spliterators.AbstractSpliterator;
import java.util.function.Consumer;

public class ContinuingGenerator extends AbstractSpliterator {

    @Nonnull
    private final Generator generator;

    public ContinuingGenerator(@Nonnull Generator generator) {
        super(Long.MAX_VALUE, ORDERED | IMMUTABLE);
        this.generator = generator;
    }

    @Override
    public boolean tryAdvance(Consumer action) {
        final Value value = generator().generate();
        if (value == null) {
            return false;
        }
        action.accept(value.get());
        return true;
    }

    @Nonnull
    protected Generator generator() {
        return generator;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy