Interface Window<T>

All Superinterfaces:
Iterable<T>, Streamable<T>, Supplier<Stream<T>>

public interface Window<T> extends Streamable<T>
A set of data consumed from an underlying query result. A Window is similar to Slice in the sense that it contains a subset of the actual query results for easier scrolling across large result sets. The window is less opinionated about the actual data retrieval, whether the query has used index/offset, keyset-based pagination or cursor resume tokens.
Since:
3.1
Author:
Mark Paluch, Christoph Strobl
See Also:
  • Method Details

    • from

      static <T> Window<T> from(List<T> items, IntFunction<? extends ScrollPosition> positionFunction)
      Construct a Window.
      Type Parameters:
      T -
      Parameters:
      items - the list of data.
      positionFunction - the list of data.
      Returns:
      the Window.
    • from

      static <T> Window<T> from(List<T> items, IntFunction<? extends ScrollPosition> positionFunction, boolean hasNext)
      Construct a Window.
      Type Parameters:
      T -
      Parameters:
      items - the list of data.
      positionFunction - the list of data.
      hasNext -
      Returns:
      the Window.
    • size

      int size()
      Returns the number of elements in this window.
      Returns:
      the number of elements in this window.
    • isEmpty

      boolean isEmpty()
      Returns true if this window contains no elements.
      Specified by:
      isEmpty in interface Streamable<T>
      Returns:
      true if this window contains no elements
    • getContent

      List<T> getContent()
      Returns the windows content as List.
      Returns:
    • isLast

      default boolean isLast()
      Returns whether the current window is the last one.
      Returns:
    • hasNext

      boolean hasNext()
      Returns if there is a next window.
      Returns:
      if there is a next window.
    • hasPosition

      default boolean hasPosition(int index)
      Returns whether the underlying scroll mechanism can provide a ScrollPosition at index.
      Parameters:
      index -
      Returns:
      true if a ScrollPosition can be created; false otherwise.
      See Also:
    • positionAt

      ScrollPosition positionAt(int index)
      Returns the ScrollPosition at index.
      Parameters:
      index -
      Returns:
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).
      IllegalStateException - if the underlying scroll mechanism cannot provide a scroll position for the given object.
    • positionAt

      default ScrollPosition positionAt(T object)
      Returns the ScrollPosition for object.
      Parameters:
      object -
      Returns:
      Throws:
      NoSuchElementException - if the object is not part of the result.
      IllegalStateException - if the underlying scroll mechanism cannot provide a scroll position for the given object.
    • map

      <U> Window<U> map(Function<? super T,? extends U> converter)
      Returns a new Window with the content of the current one mapped by the given converter.
      Specified by:
      map in interface Streamable<T>
      Parameters:
      converter - must not be null.
      Returns:
      a new Window with the content of the current one mapped by the given converter.
      See Also: