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

com.annimon.stream.operator.ObjScanIdentity Maven / Gradle / Ivy

package com.annimon.stream.operator;

import com.annimon.stream.function.BiFunction;
import com.annimon.stream.iterator.LsaExtIterator;
import java.util.Iterator;

public class ObjScanIdentity extends LsaExtIterator {

    private final Iterator iterator;
    private final R identity;
    private final BiFunction accumulator;

    public ObjScanIdentity(Iterator iterator, R identity,
            BiFunction accumulator) {
        this.iterator = iterator;
        this.identity = identity;
        this.accumulator = accumulator;
    }

    @Override
    protected void nextIteration() {
        if (!isInit) {
            // Return identity
            hasNext = true;
            next = identity;
            return;
        }
        hasNext = iterator.hasNext();
        if (hasNext) {
            final T t = iterator.next();
            next = accumulator.apply(next, t);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy