Class PageRange
java.lang.Object
io.github.thebusybiscuit.slimefun4.api.gps.PageRange
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic PageRangecompute(int total, int pageSize, int currentPage) intThis method returns the current page index after clamping the requested page into a valid range.intThis method returns the zero-based start index (inclusive) of this page range.intThis method returns the zero-based end index (exclusive) of this page range.intThis method returns the total amount of pages calculated for this page range.
-
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 least1.- 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
-