1 package org.infoglue.cms.entities.publishing; 2 3 import java.io.Serializable ; 4 import java.math.BigDecimal ; 5 import java.util.ArrayList ; 6 import java.util.List ; 7 8 15 public class EditionBrowser implements Serializable 16 { 17 private int totalEditions = 0; 18 private int startIndex = 0; 19 private int pageSize = 0; 20 private int totalPages = 0; 21 private int currentPage = 0; 22 private List editions = new ArrayList (); 23 24 public EditionBrowser(int totalEditions, int pageSize, int startIndex) 25 { 26 this.totalEditions = totalEditions; 27 this.pageSize = pageSize; 28 this.startIndex = startIndex; 29 init(); 30 } 31 32 private void init() 33 { 34 BigDecimal total = new BigDecimal (totalEditions); 35 BigDecimal page = new BigDecimal (pageSize); 36 BigDecimal start = new BigDecimal (startIndex + 0.5d); totalPages = Math.max(1, total.divide(page, 0, BigDecimal.ROUND_UP).intValue()); 38 currentPage = start.divide(page, 0, BigDecimal.ROUND_UP).intValue(); 39 } 40 41 public int getTotalEditions() { return totalEditions; } 42 public void setTotalEditions(int i) { totalEditions = i; } 43 44 public int getStartIndex() { return startIndex; } 45 public void setStartIndex(int i) { startIndex = i; } 46 47 public int getPageSize() { return pageSize; } 48 public void setPageSize(int i) { pageSize = i; } 49 50 public List getEditions() { return editions; } 51 public void setEditions(List c) { editions = (c != null)? c : new ArrayList (); } 52 53 public int getTotalPages() { return totalPages; } 54 public int getCurrentPage() { return currentPage; } 55 56 59 public boolean hasPreviousPage() 60 { 61 return getPreviousPageSize() != 0; 62 } 63 64 67 public boolean hasNextPage() 68 { 69 return getNextPageSize() != 0; 70 } 71 72 75 public int getPreviousPageSize() 76 { 77 return Math.min(pageSize, Math.max(0, startIndex)); 78 } 79 80 83 public int getNextPageSize() 84 { 85 return Math.min(pageSize, Math.max(0, totalEditions - (startIndex + pageSize))); 86 } 87 88 91 public int getPreviousPageIndex() 92 { 93 return getStartIndex() - getPreviousPageSize(); 94 } 95 96 99 public int getNextPageIndex() 100 { 101 return getStartIndex() + getEditions().size(); 102 } 103 } 104 | Popular Tags |