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

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

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

import com.annimon.stream.DoubleStream;
import com.landawn.abacus.util.function.Function;
import com.annimon.stream.iterator.PrimitiveExtIterator;
import com.annimon.stream.iterator.PrimitiveIterator;
import java.util.Iterator;

public class ObjFlatMapToDouble extends PrimitiveExtIterator.OfDouble {

    private final Iterator iterator;
    private final Function mapper;
    private PrimitiveIterator.OfDouble inner;

    public ObjFlatMapToDouble(Iterator iterator,
            Function mapper) {
        this.iterator = iterator;
        this.mapper = mapper;
    }

    @Override
    protected void nextIteration() {
        if ((inner != null) && inner.hasNext()) {
            next = inner.next();
            hasNext = true;
            return;
        }
        while (iterator.hasNext()) {
            if (inner == null || !inner.hasNext()) {
                final T arg = iterator.next();
                final DoubleStream result = mapper.apply(arg);
                if (result != null) {
                    inner = result.iterator();
                }
            }
            if ((inner != null) && inner.hasNext()) {
                next = inner.next();
                hasNext = true;
                return;
            }
        }
        hasNext = false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy