java.lang.Object
io.github.thebusybiscuit.slimefun4.api.gps.PageRange

public class PageRange extends Object
Represents a calculated, immutable page window over a linear collection.

A PageRange encapsulates the zero-based half-open index range from (inclusive) to to (exclusive) that should be displayed for a given page, along with the resolved 1-based current page number and the total number of pages totalPages.

This utility is intended for use in GUIs and APIs that paginate lists, such as waypoint lists or transmitter panels, where callers need a safe, clamped window even when the requested page or sizes are out of bounds.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PageRange(int from, int to, int totalPages, int page)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static PageRange
    compute(int total, int pageSize, int currentPage)
     
    int
    This method returns the current page index after clamping the requested page into a valid range.
    int
    This method returns the zero-based start index (inclusive) of this page range.
    int
    This method returns the zero-based end index (exclusive) of this page range.
    int
    This method returns the total amount of pages calculated for this page range.

    Methods inherited from class java.lang.Object

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

    • PageRange

      public PageRange(int from, int to, int totalPages, int page)
  • Method Details

    • compute

      @ParametersAreNonnullByDefault @Nonnull public static PageRange compute(int total, int pageSize, int currentPage)
    • getFromIndex

      public int getFromIndex()
      This method returns the zero-based start index (inclusive) of this page range.
      Returns:
      The start index for this page
    • getToIndex

      public int getToIndex()
      This method returns the zero-based end index (exclusive) of this page range. The range [from, to) contains all items shown on this page.
      Returns:
      The end index for this page
    • getTotalPages

      public int getTotalPages()
      This method returns the total amount of pages calculated for this page range. The returned value will always be at least 1.
      Returns:
      The total amount of pages
    • getCurrentPage

      public int getCurrentPage()
      This method returns the current page index after clamping the requested page into a valid range.
      Returns:
      The current page index