com.algolia.utils.AlgoliaIterableHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch Show documentation
Show all versions of algoliasearch Show documentation
Java client for Algolia Search API
The newest version!
package com.algolia.utils;
import java.util.Iterator;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
public class AlgoliaIterableHelper {
private AlgoliaIterableHelper() {
// Empty.
}
public static Iterable createIterable(Supplier> executeQuery, BooleanSupplier hasNext) {
return () ->
new Iterator() {
private boolean isFirstRequest = true;
private Iterator currentIterator = null;
@Override
public boolean hasNext() {
if (isFirstRequest || (hasNext.getAsBoolean() && !currentIterator.hasNext())) {
currentIterator = executeQuery.get();
isFirstRequest = false;
}
return currentIterator != null && currentIterator.hasNext();
}
@Override
public T next() {
if (currentIterator == null || !currentIterator.hasNext()) {
currentIterator = executeQuery.get();
isFirstRequest = false;
}
return currentIterator.next();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy