1 package xpetstore.util; 2 3 import java.io.Serializable ; 4 5 import java.util.ArrayList ; 6 import java.util.Collection ; 7 import java.util.Collections ; 8 9 10 13 public class Page 14 implements Serializable 15 { 16 18 public static final Page EMPTY_PAGE = new Page( Collections.EMPTY_LIST, 0, false ); 19 20 22 Collection list; 23 int start; 24 boolean hasNext; 25 26 28 public Page( Collection col, 29 int start, 30 boolean hasNext ) 31 { 32 this.list = new ArrayList ( col ); 33 this.start = start; 34 this.hasNext = hasNext; 35 } 36 37 39 public Collection getList( ) 40 { 41 return list; 42 } 43 44 public boolean isNextPageAvailable( ) 45 { 46 return hasNext; 47 } 48 49 public boolean isPreviousPageAvailable( ) 50 { 51 return start > 0; 52 } 53 54 public int getStartOfNextPage( ) 55 { 56 return start + list.size( ); 57 } 58 59 public int getStartOfPreviousPage( ) 60 { 61 return Math.max( start - list.size( ), 0 ); 62 } 63 64 public int getSize( ) 65 { 66 return list.size( ); 67 } 68 } 69 | Popular Tags |