no.mnemonic.services.common.api.ResultSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of service-api Show documentation
Show all versions of service-api Show documentation
Common basic API and interfaces for services
package no.mnemonic.services.common.api;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public interface ResultSet extends Iterable, Resource {
int getCount();
int getLimit();
int getOffset();
/**
* Allow client to signal that this resultset may be closed.
* The implementation may choose to ignore that.
*/
@Override
default void close() {}
/**
* A resultset iterator iterates the values of the resultset, which may be lazily loaded
* as the client iterates them, depending on the implementation.
* Implementation should wrap any errors during lazy loading into a
* {@link ResultSetStreamInterruptedException} to signal that the exception is caused by
* an interrupted result stream.
*
* @see Iterable#iterator()
* @throws ResultSetStreamInterruptedException if initiating the resultset fails
*/
@Override
Iterator iterator() throws ResultSetStreamInterruptedException;
@Override
default Spliterator spliterator() {
return Spliterators.spliteratorUnknownSize(
iterator(),
Spliterator.ORDERED
);
}
/**
* @return a stream based on this iterable
*/
default Stream stream() {
return StreamSupport.stream(spliterator(), false);
}
}