KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > util > Page


1 package xpetstore.util;
2
3 import java.io.Serializable JavaDoc;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Collections JavaDoc;
8
9
10 /**
11  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
12  */

13 public class Page
14     implements Serializable JavaDoc
15 {
16     //~ Static fields/initializers ---------------------------------------------
17

18     public static final Page EMPTY_PAGE = new Page( Collections.EMPTY_LIST, 0, false );
19
20     //~ Instance fields --------------------------------------------------------
21

22     Collection JavaDoc list;
23     int start;
24     boolean hasNext;
25
26     //~ Constructors -----------------------------------------------------------
27

28     public Page( Collection JavaDoc col,
29                  int start,
30                  boolean hasNext )
31     {
32         this.list = new ArrayList JavaDoc( col );
33         this.start = start;
34         this.hasNext = hasNext;
35     }
36
37     //~ Methods ----------------------------------------------------------------
38

39     public Collection JavaDoc 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