Created
November 22, 2014 09:22
-
-
Save disc99/ce937b89e42af7d6f01f to your computer and use it in GitHub Desktop.
PagingUtil
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
public class PagingUtil { | |
public static boolean isDisplayPage(int i, int pageNum, int maxPage) { | |
int distance = pageNum - i; | |
int min = 2; | |
int max = min * 2; | |
if (distance == 0) { | |
return true; | |
} | |
if (distance < 0) { | |
int left = pageNum <= min ? pageNum - 1 : min; | |
if (left - distance <= max) { | |
return true; | |
} | |
} | |
if (distance > 0) { | |
int right = (maxPage - pageNum) < min ? (maxPage - pageNum) : min; | |
if (right + distance <= max) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment