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

no.mnemonic.services.common.api.ResultSet Maven / Gradle / Ivy

There is a newer version: 0.6.11
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy