Class Subrange<P>

java.lang.Object
org.springframework.graphql.data.pagination.Subrange<P>
Type Parameters:
P - the type of position in the entire collection
Direct Known Subclasses:
ScrollSubrange

public class Subrange<P> extends Object
Container for parameters that limit result elements to a subrange including a relative position, number of elements, and direction.
Since:
1.2.0
Author:
Rossen Stoyanchev
  • Constructor Summary

    Constructors
    Constructor
    Description
    Subrange(P position, Integer count, boolean forward)
    Constructor with the relative position, count, and direction.
  • Method Summary

    Modifier and Type
    Method
    Description
    The number of elements in the subrange based on the "first" and "last" arguments from the GraphQL Cursor connection spec.
    boolean
    Whether the subrange is forward or backward from ths position, depending on whether the argument sent "first" or "last".
    The position of the result element the subrange is relative to.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Subrange

      public Subrange(@Nullable P position, @Nullable Integer count, boolean forward)
      Constructor with the relative position, count, and direction.
      Parameters:
      position - the position in the entire collection
      count - the number of elements in the subrange
      forward - whether the subrange is forward or backward from ths position
  • Method Details

    • position

      public Optional<P> position()
      The position of the result element the subrange is relative to. This is decoded from the "before" or "after" input arguments from the GraphQL Cursor connection spec via CursorStrategy.
    • count

      public OptionalInt count()
      The number of elements in the subrange based on the "first" and "last" arguments from the GraphQL Cursor connection spec.
    • forward

      public boolean forward()
      Whether the subrange is forward or backward from ths position, depending on whether the argument sent "first" or "last".

      Note: The direction may not always match the original value. For backward pagination, for example, an offset cursor could be adjusted down by the count of elements, switching backward to forward.