Skip to content

Instantly share code, notes, and snippets.

@disc99
Created November 22, 2014 09:22
Show Gist options
  • Save disc99/ce937b89e42af7d6f01f to your computer and use it in GitHub Desktop.
Save disc99/ce937b89e42af7d6f01f to your computer and use it in GitHub Desktop.
PagingUtil
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