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 extends T> iterator;
private final Comparator super T> comparator;
private Iterator sortedIterator;
public ObjSorted(Iterator extends T> iterator, Comparator super T> 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