Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.cbean.paging.numberlink.group;
 
 import java.util.List;
 
The bean of page group.

Author(s):
jflute
 
 public class PageGroupBean implements Serializable {
 
     // ===================================================================================
     //                                                                          Definition
     //                                                                          ==========
     
The serial version UID for object serialization. (Default)
 
     private static final long serialVersionUID = 1L;
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     protected int _currentPageNumber;
     protected int _allPageCount;
     protected PageGroupOption _pageGroupOption;
     protected List<Integer_cachedPageNumberList;
 
     // ===================================================================================
     //                                                                    Page Number List
     //                                                                    ================
     
Build the list of page number link.
 page.setPageGroupSize(10);
 List<PageNumberLink> linkList = page.pageGroup().buildPageNumberLinkList(new PageNumberLinkSetupper<PageNumberLink>() {
     public PageNumberLink setup(int pageNumberElement, boolean current) {
         String href = buildPagingHref(pageNumberElement); // for paging navigation links
         return new PageNumberLink().initialize(pageNumberElement, current, href);
     }
 });
 

Parameters:
<LINK> The type of link.
manyArgLambda Page number link set-upper. (NotNull and Required LINK)
Returns:
The list of Page number link. (NotNull)
 
     public <LINK extends PageNumberLinkList<LINK> buildPageNumberLinkList(PageNumberLinkSetupper<LINK> manyArgLambda) {
         final List<IntegerpageNumberList = createPageNumberList();
         final List<LINK> pageNumberLinkList = new ArrayList<LINK>();
         for (Integer pageNumber : pageNumberList) {
             pageNumberLinkList.add(manyArgLambda.setup(pageNumberpageNumber.equals()));
         }
         return pageNumberLinkList;
     }

    
Create the list of page number.
 e.g. group-size=10, current-page=8 
 page.setPageGroupSize(10);
 List<Integer> numberList = page.pageGroup().createPageNumberList();
 
 //  8 / 23 pages (453 records)
 // 1 2 3 4 5 6 7 8 9 10 next
 

Returns:
The list of page number. (NotNull)
 
     public List<IntegercreatePageNumberList() {
         assertPageGroupValid();
         if ( != null) {
             return ;
         }
         final int pageGroupSize = .getPageGroupSize();
         final int allPageCount = ;
         final int currentPageGroupStartPageNumber = calculateStartPageNumber();
         if (!(currentPageGroupStartPageNumber > 0)) {
             String msg = "currentPageGroupStartPageNumber should be greater than 0. {> 0} But:";
             msg = msg + " currentPageGroupStartPageNumber=" + currentPageGroupStartPageNumber;
             throw new IllegalStateException(msg);
         }
         final int nextPageGroupStartPageNumber = currentPageGroupStartPageNumber + pageGroupSize;
 
         final List<IntegerresultList = new ArrayList<Integer>();
        for (int i = currentPageGroupStartPageNumberi < nextPageGroupStartPageNumber && i <= allPageCounti++) {
            resultList.add(Integer.valueOf(i));
        }
         = resultList;
        return ;
    }

    
Calculate start page number.

Returns:
Start page number.
    protected int calculateStartPageNumber() {
        assertPageGroupValid();
        final int pageGroupSize = .getPageGroupSize();
        final int currentPageNumber = ;
        int currentPageGroupNumber = (currentPageNumber / pageGroupSize);
        if ((currentPageNumber % pageGroupSize) == 0) {
            currentPageGroupNumber--;
        }
        final int currentPageGroupStartPageNumber = (pageGroupSize * currentPageGroupNumber) + 1;
        if (!(currentPageNumber >= currentPageGroupStartPageNumber)) {
            String msg = "currentPageNumber should be greater equal currentPageGroupStartPageNumber. But:";
            msg = msg + " currentPageNumber=" + currentPageNumber;
            msg = msg + " currentPageGroupStartPageNumber=" + currentPageGroupStartPageNumber;
            throw new IllegalStateException(msg);
        }
        return currentPageGroupStartPageNumber;
    }
    // ===================================================================================
    //                                                                       Determination
    //                                                                       =============
    
Does the previous group exist?
Using values are currentPageNumber and pageGroupSize.
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns existence of 10
 

Returns:
The determination, true or false.
    public boolean existsPreviousGroup() {
        assertPageGroupValid();
    }

    
Does the next group exist?
Using values are currentPageNumber and pageGroupSize and allPageCount.
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns existence of 21
 

Returns:
The determination, true or false.
    public boolean existsNextGroup() {
        assertPageGroupValid();
        final int currentStartPageNumber = calculateStartPageNumber();
        if (!(currentStartPageNumber > 0)) {
            String msg = "currentStartPageNumber should be greater than 0. {> 0} But:";
            msg = msg + " currentStartPageNumber=" + currentStartPageNumber;
            throw new IllegalStateException(msg);
        }
        final int nextStartPageNumber = currentStartPageNumber + .getPageGroupSize();
        return (nextStartPageNumber <= );
    }

    
Is existing previous page-group? Using values are currentPageNumber and pageGroupSize.
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns existence of 10
 

Deprecated:
use existsPreviousGroup()
Returns:
The determination, true or false.
    public boolean isExistPrePageGroup() {
        return existsPreviousGroup();
    }

    
Is existing next page-group? Using values are currentPageNumber and pageGroupSize and allPageCount.
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns existence of 21
 

Deprecated:
use existsNextGroup()
Returns:
The determination, true or false.
    public boolean isExistNextPageGroup() {
        return existsNextGroup();
    }
    // ===================================================================================
    //                                                                       Assist Helper
    //                                                                       =============
    protected int[] convertListToIntArray(List<Integerls) {
        final int[] resultArray = new int[ls.size()];
        int arrayIndex = 0;
        for (int pageNumber : resultArray) {
            resultArray[arrayIndex] = pageNumber;
            arrayIndex++;
        }
        return resultArray;
    }
    protected void assertPageGroupValid() {
        if ( == null) {
            String msg = "The pageGroupOption should not be null. Please call setPageGroupOption().";
            throw new IllegalStateException(msg);
        }
        if (.getPageGroupSize() == 0) {
            String msg = "The pageGroupSize should be greater than 1. But the value is zero.";
            msg = msg + " pageGroupSize=" + .getPageGroupSize();
            throw new IllegalStateException(msg);
        }
        if (.getPageGroupSize() == 1) {
            String msg = "The pageGroupSize should be greater than 1. But the value is one.";
            msg = msg + " pageGroupSize=" + .getPageGroupSize();
            throw new IllegalStateException(msg);
        }
    }
    // ===================================================================================
    //                                                                      Basic Override
    //                                                                      ==============
    

Returns:
The view string of all attribute values. (NotNull)
    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("currentPageNumber=").append();
        sb.append(", allPageCount=").append();
        sb.append(", pageGroupOption=").append();
        sb.append("}");
        return sb.toString();
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public void setCurrentPageNumber(int currentPageNumber) {
         = currentPageNumber;
    }
    public void setAllPageCount(int allPageCount) {
         = allPageCount;
    }
        return ;
    }
    public void setPageGroupOption(PageGroupOption pageGroupOption) {
         = pageGroupOption;
    }
    // -----------------------------------------------------
    //                                   Calculated Property
    //                                   -------------------
    
Get the value of previousGroupNearestPageNumber that is calculated.
You should use this.existsPreviousGroup() before calling this. (call only when true)
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns 10
 

Returns:
The number of previous group-nearest page.
    public int getPreviousGroupNearestPageNumber() {
        if (!existsPreviousGroup()) {
            String msg = "The previous page range should exist when you use previousGroupNearestPageNumber:";
            msg = msg + " currentPageNumber=" +  + " allPageCount=" + ;
            msg = msg + " pageGroupOption=" + ;
            throw new IllegalStateException(msg);
        }
        return createPageNumberList().get(0) - 1;
    }

    
Get the value of nextGroupNearestPageNumber that is calculated.
You should use this.existsNextGroup() before calling this. (call only when true)
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns 21
 

Returns:
The number of next group-nearest page.
    public int getNextGroupNearestPageNumber() {
        if (!existsNextGroup()) {
            String msg = "The next page range should exist when you use nextGroupNearestPageNumber:";
            msg = msg + " currentPageNumber=" +  + " allPageCount=" + ;
            msg = msg + " pageGroupOption=" + ;
            throw new IllegalStateException(msg);
        }
        final List<Integerls = createPageNumberList();
        return ls.get(ls.size() - 1) + 1;
    }

    
Get the value of preGroupNearestPageNumber that is calculated.
You should use this.existsPreviousGroup() before calling this. (call only when true)
 e.g. group-size=10, current-page=12
  12 / 23 pages (453 records)
 previous 11 12 13 14 15 16 17 18 19 20 next
 
 // this method returns 10
 

Deprecated:
use getPreviousGroupNearestPageNumber()
Returns:
The value of preGroupNearestPageNumber.
    public int getPreGroupNearestPageNumber() {
        return getPreviousGroupNearestPageNumber();
    }
New to GrepCode? Check out our FAQ X