Class Page


  • public class Page
    extends Object

    Utility class to represent paging information. Page instances are immutable.

    Usage:

     Page page = Page.ofSize(25);
     Page secondPage = page.next();
     
    Author:
    Stéphane Épardaud
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int index
      The current page index (0-based).
      int size
      The current page size;
    • Constructor Summary

      Constructors 
      Constructor Description
      Page​(int size)
      Builds a page of the given size.
      Page​(int index, int size)
      Builds a page of the given index and size.
    • Field Detail

      • index

        public final int index
        The current page index (0-based).
      • size

        public final int size
        The current page size;
    • Constructor Detail

      • Page

        public Page​(int size)
        Builds a page of the given size.
        Parameters:
        size - the page size
        Throws:
        IllegalArgumentException - if the page size is less than or equal to 0
        See Also:
        ofSize(int)
      • Page

        public Page​(int index,
                    int size)
        Builds a page of the given index and size.
        Parameters:
        index - the page index (0-based)
        size - the page size
        Throws:
        IllegalArgumentException - if the page index is less than 0
        IllegalArgumentException - if the page size is less than or equal to 0
        See Also:
        of(int, int)
    • Method Detail

      • of

        public static Page of​(int index,
                              int size)
        Builds a page of the given index and size.
        Parameters:
        index - the page index (0-based)
        size - the page size
        Throws:
        IllegalArgumentException - if the page index is less than 0
        IllegalArgumentException - if the page size is less than or equal to 0
      • ofSize

        public static Page ofSize​(int size)
        Builds a page of the given size.
        Parameters:
        size - the page size
        Throws:
        IllegalArgumentException - if the page size is less than or equal to 0
      • next

        public Page next()
        Returns a new page with the next page index and the same size.
        Returns:
        a new page with the next page index and the same size.
        See Also:
        previous()
      • previous

        public Page previous()
        Returns a new page with the previous page index and the same size, or this page if it is the first page.
        Returns:
        a new page with the next page index and the same size, or this page if it is the first page.
        See Also:
        next()
      • first

        public Page first()
        Returns a new page with the first page index (0) and the same size, or this page if it is the first page.
        Returns:
        a new page with the first page index (0) and the same size, or this page if it is the first page.
      • index

        public Page index​(int newIndex)
        Returns a new page at the given page index and the same size, or this page if the page index is the same.
        Parameters:
        newIndex - the new page index
        Returns:
        a new page at the given page index and the same size, or this page if the page index is the same.