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

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

package com.annimon.stream.operator;

import com.annimon.stream.internal.Operators;
import com.annimon.stream.iterator.LsaExtIterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class ObjSorted extends LsaExtIterator {

    private final Iterator iterator;
    private final Comparator comparator;
    private Iterator sortedIterator;

    public ObjSorted(Iterator iterator, Comparator comparator) {
        this.iterator = iterator;
        this.comparator = comparator;
    }

    @Override
    protected void nextIteration() {
        if (!isInit) {
            final List list = Operators.toList(iterator);
            Collections.sort(list, comparator);
            sortedIterator = list.iterator();
        }
        hasNext = sortedIterator.hasNext();
        if (hasNext) {
            next = sortedIterator.next();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy