no.ssb.lds.api.persistence.flattened.FlattenedDocumentIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linked-data-store-persistence-provider-api Show documentation
Show all versions of linked-data-store-persistence-provider-api Show documentation
LinkedDataStore Persistence Provider API
package no.ssb.lds.api.persistence.flattened;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class FlattenedDocumentIterator implements Iterable, Iterator {
private final Iterator iterator;
FlattenedDocumentIterator(List matches) {
if (matches == null) {
this.iterator = Collections.emptyListIterator();
} else {
this.iterator = matches.iterator();
}
}
/**
* Returns a completable future that when complete signals whether or not the next() method will return another
* element, and allows next to be called without blocking.
*
* This should be used as an asynchronous callback when the iterator has more elements.
*
* @return
*/
public CompletableFuture onHasNext() {
return CompletableFuture.completedFuture(hasNext());
}
@Override
public Iterator iterator() {
return this;
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public FlattenedDocument next() {
return iterator.next();
}
}