Digg-Style Pagination in Java

Posted by Jessica Thu, 18 Feb 2010 22:35:00 GMT

The following is something like a translation of Digg-Style Pagination into java.
public ArrayList getPagingLinks(){
    ArrayList pages = new ArrayList();
    if (pageCount < (7 + (adjacents * 2))){
        for(int i=1; i<=pageCount; i++){
            pages.add(i);
        }                
    } else if(currentPage < ((adjacents * 3) + 1)){
        for(int i=1; i<=(4 + (adjacents * 2)); i++){
            pages.add(i);
        }
        pages.add("e");
        pages.add(pageCount);
    } else if(((pageCount - (adjacents * 2)) > currentPage) && (currentPage > (adjacents * 2))){
        pages.add(1);
        pages.add("e");
        for(int i=currentPage -adjacents; i<=currentPage +adjacents; i++){
            pages.add(i);
        }
        pages.add("e");
        pages.add(pageCount);
    } else{
        pages.add(1);
        pages.add("e");
        for(int i=pageCount - (adjacents *3); i<=pageCount; i++){
            pages.add(i);
        }  
    }
    return pages;
  }

Basically, it creates a list of links to pages determined by the displayCount. If the page number equals the current page or the page number is greater than the page count, then no link will be added, only the page number.

Multiline Comments with Ruby

Posted by Jessica Thu, 25 Jan 2007 05:00:00 GMT

I didn’t know that ruby has multiline comments.

    =begin

    Name:

    Last Updated:

    Location:

    ...

    =end

Well, at least I wasn’t the only one.


designed by jowensbysandifer