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

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

The newest version!
package com.annimon.stream.operator;

import com.landawn.abacus.util.function.IntBinaryOperator;
import com.annimon.stream.iterator.PrimitiveExtIterator;
import com.annimon.stream.iterator.PrimitiveIterator;

public class IntScanIdentity extends PrimitiveExtIterator.OfInt {

    private final PrimitiveIterator.OfInt iterator;
    private final int identity;
    private final IntBinaryOperator accumulator;

    public IntScanIdentity(PrimitiveIterator.OfInt iterator, int identity, IntBinaryOperator 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 int current = iterator.next();
            next = accumulator.applyAsInt(next, current);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy