Class PaginedStream<T>

Type Parameters:
T - the type of objects contained in the stream, as specified in Stream interface.
All Implemented Interfaces:
AutoCloseable, BaseStream<T,Stream<T>>, Stream<T>

public final class PaginedStream<T> extends StreamWrapper<T>
A stream on which skip and limit operations are delegated to a root stream. This is useful when the root stream is capable of some optimizations, for example using SQL. The redirection stops as soon as an operation may change the elements order or filtering.
Since:
1.1
Version:
1.1
  • Field Details

    • root

      private Stream<?> root
      The root stream on which to delegate skip and limit operations.
  • Constructor Details

    • PaginedStream

      public PaginedStream(Stream<T> source, Stream<?> root)
      Creates a new mapped stream.
      Parameters:
      source - the stream to wrap.
      root - the stream on which to delegate skip and limit operations.
  • Method Details

    • skip

      public Stream<T> skip(long n)
      Discards the specified number of elements. This method delegates the operation to the root stream.
      Specified by:
      skip in interface Stream<T>
      Overrides:
      skip in class StreamWrapper<T>
      Parameters:
      n - number of elements to skip.
      Returns:
      this.
    • limit

      public Stream<T> limit(long maxSize)
      Truncates this stream to the given number of elements. This method delegates the operation to the root stream.
      Specified by:
      limit in interface Stream<T>
      Overrides:
      limit in class StreamWrapper<T>
      Parameters:
      maxSize - number of elements to keep.
      Returns:
      this.
    • count

      public long count()
      Returns the number of elements in this stream. This method delegates the operation to the root stream.
      Specified by:
      count in interface Stream<T>
      Overrides:
      count in class StreamWrapper<T>
      Returns:
      number of elements in this stream.
    • mapToDouble

      public DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)
      Returns a stream with results of applying the given function to the elements of this stream.
      Specified by:
      mapToDouble in interface Stream<T>
      Overrides:
      mapToDouble in class StreamWrapper<T>
      Parameters:
      mapper - function to apply to each element.
      Returns:
      the new stream.
    • distinct

      public Stream<T> distinct()
      Description copied from class: StreamWrapper
      Returns a stream with distinct elements of this stream.
      Specified by:
      distinct in interface Stream<T>
      Overrides:
      distinct in class StreamWrapper<T>
    • unordered

      public Stream<T> unordered()
      Description copied from class: StreamWrapper
      Returns an equivalent stream that is unordered.
      Specified by:
      unordered in interface BaseStream<T,Stream<T>>
      Overrides:
      unordered in class StreamWrapper<T>
    • sorted

      public Stream<T> sorted()
      Description copied from class: StreamWrapper
      Returns a stream with elements of this stream sorted in natural order.
      Specified by:
      sorted in interface Stream<T>
      Overrides:
      sorted in class StreamWrapper<T>
    • sorted

      public Stream<T> sorted(Comparator<? super T> comparator)
      Description copied from class: StreamWrapper
      Returns a stream with elements of this stream sorted using the given comparator.
      Specified by:
      sorted in interface Stream<T>
      Overrides:
      sorted in class StreamWrapper<T>
    • filter

      public Stream<T> filter(Predicate<? super T> predicate)
      Description copied from class: StreamWrapper
      Returns a stream with elements of this stream that match the given predicate.
      Specified by:
      filter in interface Stream<T>
      Overrides:
      filter in class StreamWrapper<T>