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

com.jnape.palatable.lambda.iterators.GroupingIterator Maven / Gradle / Ivy

package com.jnape.palatable.lambda.iterators;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GroupingIterator extends ImmutableIterator> {
    private final Integer     k;
    private final Iterator asIterator;

    public GroupingIterator(Integer k, Iterator asIterator) {
        this.k = k;
        this.asIterator = asIterator;
    }

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

    @Override
    public Iterable next() {
        List group = new ArrayList<>();
        int i = 0;
        while (i++ < k && asIterator.hasNext())
            group.add(asIterator.next());
        return group;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy