Esempio n. 1
0
  public WebPageDto(Page<T> page, String url) {
    this.url = url;
    this.totalPages = page.getTotalPages();
    this.totalElements = page.getTotalElements();
    this.firstPage = page.isFirstPage();
    this.lastPage = page.isLastPage();
    this.hasPreviousPage = page.hasPreviousPage();
    this.hasNextPage = page.hasNextPage();
    this.size = page.getSize();
    this.number = page.getNumber() + 1;
    this.content = page.getContent();

    int start, size;
    if (totalPages <= DEFAULT_PAGES) {
      start = 1;
      size = totalPages;
    } else {
      if (number <= DEFAULT_PAGES - DEFAULT_PAGES / 2) {
        start = 1;
        size = DEFAULT_PAGES;
      } else if (number >= totalPages - DEFAULT_PAGES / 2) {
        start = totalPages - DEFAULT_PAGES + 1;
        size = DEFAULT_PAGES;
      } else {
        start = number - DEFAULT_PAGES / 2;
        size = DEFAULT_PAGES;
      }
    }

    for (int i = 0; i < size; i++) {
      items.add(new PageItem(start + i, (start + i) == number));
    }
  }
 private WebPage(Page<T> page) {
   number = page.getNumber();
   size = page.getSize();
   totalPages = page.getTotalPages();
   numberOfElements = page.getNumberOfElements();
   totalElements = page.getTotalElements();
   hasPreviousPage = page.hasPreviousPage();
   isFirstPage = page.isFirstPage();
   hasNextPage = page.hasNextPage();
   isLastPage = page.isLastPage();
   content = page.getContent();
   hasContent = page.hasContent();
   sort = new WebSort(page.getSort());
 }