Generic stateless paginator component for Java

Project maintained by timoteoponce Hosted on GitHub Pages — Theme by mattgraham


After searching for a generic (without third-party dependencies) pagination component for several hours, I decided to start my own from scratch. After a few days I have a workable version of it:

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

import com.github.timoteoponce.paginator.ListProvider;
import com.github.timoteoponce.paginator.Paginator;
import com.github.timoteoponce.paginator.Segment;
import com.github.timoteoponce.paginator.SegmentProvider;

 * @author Timoteo Ponce
public class TestPaginator {
    private static final Logger log = Logger.getAnonymousLogger();

    public static void main(final String[] args) {
        Paginator<String> paginator = new Paginator<String>(new MyListProvider(), 3);
        // "Akira", "Edward", "Alphonse""Page 1: " + paginator.getList());
        // "Mustang", "Hawkeye", "Lusty""Page 2: " + paginator.getList());

    private static class MyListProvider implements ListProvider<String> {

        List<String> sourceList = Arrays.asList("Akira", "Edward", "Alphonse", "Mustang", "Hawkeye", "Lusty", "Gluton", "Envy", "Lust", "Wrath");

         * (non-Javadoc)
         * @see org.timo.paginator.ListProvider#provideList(org.timo.paginator.SegmentProvider)
        public List<String> provideList(final SegmentProvider segmentProvider) {
            // we need the total source list size for calculations and checkings
            Segment segment = segmentProvider.getSegment(sourceList.size());
            return sourceList.subList(segment.getFromIndex(), segment.getToIndex());


As you can see, it's very simple to use and you can extend it as much as you want to. The core of the component is the pages-size-limits calculation defined in the class PaginationData.

Maven setup: