public PaginationAttributeAdder setPageSize(int pageSize) {
   if (!IntegerUtils.isPositive(pageSize)) {
     pageSize = Integer.MAX_VALUE;
   }
   this.pageSize = pageSize;
   return this;
 }
  public PaginationAttributeAdder setVisibleButtonSize(int visibleButtonSize) {
    if (!IntegerUtils.isPositive(visibleButtonSize)) {
      visibleButtonSize = Integer.MAX_VALUE;
    }

    this.visibleButtonSize = visibleButtonSize;
    return this;
  }
  public void add() {
    Integer pageNumber = getIntParameter(PAGE_NUMBER_KEY);

    if (!IntegerUtils.isPositive(pageNumber)) {
      pageNumber = 1;
    }

    long itemCount = factory.getCount();
    int pageCount = PaginationUtils.getPageCount(itemCount, pageSize);
    if (pageNumber > pageCount) {
      pageNumber = pageCount;
    }

    String pageUrl = request.getRequestURI();

    List<String> parameters = new ArrayList<>();
    @SuppressWarnings("unchecked")
    Set<Map.Entry<String, Object>> entries = request.getParameterMap().entrySet();
    for (Map.Entry<String, Object> entry : entries) {
      if (entry.getKey().equals(PAGE_NUMBER_KEY)) {
        continue;
      }

      Object value = entry.getValue();
      if (value == null) {
        continue;
      }

      if (value instanceof String) {
        parameters.add(entry.getKey() + "=" + UrlUtils.encode((String) value));
      } else if (value.getClass().isArray()) {
        String[] strings = (String[]) value;
        if (strings.length > 0) {
          parameters.add(entry.getKey() + "=" + UrlUtils.encode(strings[0]));
        }
      }
    }
    if (parameters.size() > 0) {
      pageUrl += "?" + Joiner.on("&").join(parameters);
    }

    List<PaginationAnchor> anchors =
        PaginationAnchor.create(pageUrl, pageCount, visibleButtonSize, pageNumber);

    request.setAttribute("paginationAnchors", anchors);
    request.setAttribute("rowStartIndex", (pageNumber - 1) * pageSize + 1);
    request.setAttribute(rowItemsName, factory.getInstances((pageNumber - 1) * pageSize, pageSize));
    request.setAttribute(rowItemCountName, itemCount);
  }