Class PaginationState

java.lang.Object
dev.crafty.core.gui.PaginationState

public class PaginationState extends Object
Manages pagination state and logic for GUI components. Handles navigation between pages and provides utility methods for index calculations.
Since:
1.0.0
  • Constructor Details

    • PaginationState

      public PaginationState(int itemsPerPage, int totalItems)
      Creates a new pagination state.
      Parameters:
      itemsPerPage - Number of items to display per page (must be > 0)
      totalItems - Total number of items available (must be >= 0)
      Throws:
      IllegalArgumentException - if itemsPerPage invalid input: '<'= 0
  • Method Details

    • goNextPage

      public boolean goNextPage()
      Navigate to the next page if available.
      Returns:
      true if navigation was successful, false if already on last page
    • goPreviousPage

      public boolean goPreviousPage()
      Navigate to the previous page if available.
      Returns:
      true if navigation was successful, false if already on first page
    • setPage

      public boolean setPage(int pageNum)
      Jump directly to a specific page.
      Parameters:
      pageNum - The page number to navigate to (0-based)
      Returns:
      true if navigation was successful, false if page number is invalid
    • getCurrentPage

      public int getCurrentPage()
      Get the current page number (0-based).
      Returns:
      Current page number
    • getCurrentPageDisplay

      public int getCurrentPageDisplay()
      Get the current page number (1-based) for display purposes.
      Returns:
      Current page number starting from 1
    • getTotalPages

      public int getTotalPages()
      Calculate the total number of pages.
      Returns:
      Total number of pages (minimum 1 if there are any items)
    • hasNextPage

      public boolean hasNextPage()
      Check if there is a next page available.
      Returns:
      true if next page exists
    • hasPreviousPage

      public boolean hasPreviousPage()
      Check if there is a previous page available.
      Returns:
      true if previous page exists
    • isValidPage

      public boolean isValidPage(int pageNum)
      Check if a page number is valid.
      Parameters:
      pageNum - The page number to validate (0-based)
      Returns:
      true if page number is valid
    • getStartIndex

      public int getStartIndex()
      Get the starting index for the current page in the data collection.
      Returns:
      Starting index (inclusive)
    • getEndIndex

      public int getEndIndex()
      Get the ending index for the current page in the data collection.
      Returns:
      Ending index (exclusive)
    • getItemsPerPage

      public int getItemsPerPage()
      Get the number of items per page.
      Returns:
      Items per page
    • getTotalItems

      public int getTotalItems()
      Get the total number of items.
      Returns:
      Total items
    • getItemsOnCurrentPage

      public int getItemsOnCurrentPage()
      Get the number of items on the current page.
      Returns:
      Number of items on current page
    • toString

      public String toString()
      Overrides:
      toString in class Object