code: private int calcLastPage(int total, int pageSize) {
          if (total == 0) {
              return firstPage;
          } else {
              final int zeroBasedPageNo = total % pageSize > 0
                      ? total / pageSize
                      : total / pageSize - 1;
              return firstPage + zeroBasedPageNo;
          }
      }
docs: Returns the number of the last page, if the total number of items is known.
  
  @param total total number of items
  @param pageSize the current page size
  @return page number of the last page