Created
July 15, 2011 18:29
-
-
Save timoteoponce/1085230 to your computer and use it in GitHub Desktop.
Paginator usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.logging.Logger; | |
import org.timo.paginator.ListProvider; | |
import org.timo.paginator.Paginator; | |
import org.timo.paginator.Segment; | |
import org.timo.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" | |
log.info("Page 1: " + paginator.getList()); | |
paginator.goNextPage(); | |
// "Mustang", "Hawkeye", "Lusty" | |
log.info("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) | |
*/ | |
@Override | |
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()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment