Given the UserPage number, this method restrict it
to be sure it's an existing page. It takes care of
using the user defined pages if any.
@param userPage A page number.
@return A restricted valid page number (example : -2 => 0)
184848
private int determineValidPageNumberFrom(int userPage) {
        if (userPage <= 0) {
            return 0;
        }
        if (originalUserPages != null) {
            if (userPage >= originalUserPages.length) {
                return originalUserPages.length - 1;
            }
        } else {
            if (userPage >= documentPageCount) {
                return documentPageCount - 1;
            }
        }
        return userPage;
    }
1283391
public static <E> Page<E> offsetPage(int offset, int limit) {
        return offsetPage(offset, limit, DEFAULT_COUNT);
    }
979706
public void setCurrentPage(int currentPage) throws CmsIllegalArgumentException {

        if (getSize() != 0) {
            if ((currentPage < 1) || (currentPage > getNumberOfPages())) {
                throw new CmsIllegalArgumentException(
                    Messages.get().container(Messages.ERR_LIST_INVALID_PAGE_1, new Integer(currentPage)));
            }
        }
        m_currentPage = currentPage;
    }
982321
protected static int binarySearchGuessUnsafe(@NotNull final BasePage page, @NotNull final ByteIterable key) {
        int index = page.binarySearch(key);
        if (index < 0) {
            index = -index - 2;
        }
        return index;
    }
675828
private void setPageParam(int page) {
        pageParam.set(0, Integer.toString(page));
        queryParams.put(PAGE_PARAM, pageParam);
    }
49691
function () {
            var min = this.state.currentPage - 1,
                max = min + 1;
            return util.constrainRange(min, max, this.numPages);
        }
642297
public static <E> Page<E> startPage(int pageNum, int pageSize, boolean count) {
        return startPage(pageNum, pageSize, count, null, null);
    }
567006
public ClientFilter withPage(int pageNumber, int amountPerPage) {
        parameters.put("page", pageNumber);
        parameters.put("per_page", amountPerPage);
        return this;
    }
175694
final protected AbstractIndexPage getPrevInnerPage(AbstractIndexPage indexPage) {
		int pos = getPagePosition(indexPage);
		if (pos > 0) {
			AbstractIndexPage page = getPageByPos(pos-1);
			if (page.isLeaf) {
				return null;
			}
			return page;
		}
		if (getParent() == null) {
			return null;
		}
		//TODO we really should return the last leaf page of the previous inner page.
		//But if they get merged, then we have to shift minimal values, which is
		//complicated. For now we ignore this case, hoping that it doesn't matter much.
		return null;
	}
1011808
final protected AbstractIndexPage getPrevLeafPage(AbstractIndexPage indexPage) {
		int pos = getPagePosition(indexPage);
		if (pos > 0) {
			AbstractIndexPage page = getPageByPos(pos-1);
			return page.getLastLeafPage();
		}
		if (getParent() == null) {
			return null;
		}
		//TODO we really should return the last leaf page of the previous inner page.
		//But if they get merged, then we have to shift minimal values, which is
		//complicated. For now we ignore this case, hoping that it doesn't matter much.
		return null;
	}
191931
public static <E> Page<E> startPage(int pageNum, int pageSize) {
        return startPage(pageNum, pageSize, DEFAULT_COUNT);
    }
947826
public boolean setPage(int p) {
		p--;
		if( p < 0 ) {
			return false;
		}
		if( p >= pages.size() ) {
			return false;
		}
		pageIndex = p;
		currentPage = null;
		return true;
	}
1043379
public PaginatedList<User> listFromCurrentCompany(Integer page, Integer pageSize) {

		if (page == null || page < 1) {
			page = 1;
		}
		if (pageSize == null) {
			pageSize = PAGESIZE;
		}
		PaginatedList<User> results = new PaginatedList<User>();
		if (this.domain == null) {
			Criteria criteria = this.dao.newCriteria(User.class).setFirstResult((page - 1) * pageSize)
					.setMaxResults(pageSize).addOrder(Order.asc("name"));
			Criteria counting = this.dao.newCriteria(User.class).setProjection(Projections.countDistinct("id"));
			results.setList(this.dao.findByCriteria(criteria, User.class));
			results.setTotal((Long) counting.uniqueResult());

		} else {
			Criteria criteria = this.dao.newCriteria(CompanyUser.class).setFirstResult((page - 1) * pageSize)
					.setMaxResults(pageSize).add(Restrictions.eq("company", this.domain.getCompany()))
					.createAlias("user", "user", JoinType.INNER_JOIN).addOrder(Order.asc("user.name"));
			Criteria counting = this.dao.newCriteria(CompanyUser.class)
					.add(Restrictions.eq("company", this.domain.getCompany()))
					.createAlias("user", "user", JoinType.INNER_JOIN)
					.setProjection(Projections.countDistinct("user.id"));
			List<CompanyUser> companyUsers = this.dao.findByCriteria(criteria, CompanyUser.class);
			ArrayList<User> users = new ArrayList<User>(companyUsers.size());
			for (CompanyUser companyUser : companyUsers) {
				User user = companyUser.getUser();
				user.setAccessLevel(Math.max(user.getAccessLevel(), companyUser.getAccessLevel()));
				users.add(user);
			}
			results.setList(users);
			results.setTotal((Long) counting.uniqueResult());
		}
		return results;
	}
1343823
private void setCurrentPage(int page) {
        if (page >= totalPages) {
            this.currentPage = totalPages;
        } else if (page <= 1) {
            this.currentPage = 1;
        } else {
            this.currentPage = page;
        }

        // now work out where the sub-list should start and end
        startingIndex = pageSize * (currentPage -1);
        if (startingIndex < 0) {
            startingIndex = 0;
        }
        endingIndex = startingIndex + pageSize;
        if (endingIndex > list.size()) {
            endingIndex = list.size();
        }
    }
626791
public int getPage() {
        int row = getRow();
        assert row % getPageSize() == 0 : "Invalid current row \"" + row + "\" for page size \"" + getPageSize() + "\"";
        assert getPageSize() > 0;
        return row / getPageSize();
    }
338735
public void setPage(int page, boolean fireChanged) {

        m_page = page;
        m_label.setValue("( " + (1 + m_page) + " / " + (m_lastPage + 1) + " )");
        int start = (m_page * m_pageSize) + 1;
        int end = Math.min((start + m_pageSize) - 1, m_resultCount);
        String resultsMsg = CmsVaadinUtils.getMessageText(
            Messages.GUI_DATAVIEW_RESULTS_3,
            "" + start,
            "" + end,
            "" + m_resultCount);
        m_resultsLabel.setValue(start <= end ? resultsMsg : "");
        if (fireChanged) {
            firePageChanged(page);
        }
    }
709980
protected static int binarySearchGuess(@NotNull final BasePage page, @NotNull final ByteIterable key) {
        int index = binarySearchGuessUnsafe(page, key);
        if (index < 0) index = 0;
        return index;
    }