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

com.happy3w.toolkits.iterator.StartActionIterator Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.happy3w.toolkits.iterator;

import java.util.Iterator;
import java.util.function.Consumer;

public class StartActionIterator implements IEasyIterator {
    protected final Iterator innerIterator;
    protected final Consumer startAction;
    protected boolean performed = false;

    public StartActionIterator(Iterator innerIterator, Consumer startAction) {
        this.innerIterator = innerIterator;
        this.startAction = startAction;
    }

    @Override
    public boolean hasNext() {
        return innerIterator.hasNext();
    }

    @Override
    public T next() {
        T nextValue = innerIterator.next();
        if (!performed) {
            startAction.accept(nextValue);
            performed = true;
        }
        return nextValue;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy