code: private int calcLastPageSkip(int total, int skip, int limit) {
          if (skip > total - limit) {
              return skip;
          }
          if (total % limit > 0) {
              return total - total % limit;
          }
          return total - limit;
      }
docs: Calculate the number of items to skip for the last page.
  
  @param total total number of items.
  @param skip number of items to skip for the current page.
  @param limit page size
  @return skipped items