Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
18   92   12   2.25
6   61   0.67   8
8     1.5  
1    
 
 
  PagerFilter       Line # 22 18 12 0% 0.0
 
No Tests
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: mike
4    * Date: Jan 22, 2002
5    * Time: 11:31:29 AM
6    * To change template for new class use
7    * Code Style | Class Templates options (Tools | IDE Options).
8    */
9    package com.atlassian.core.util.bean;
10   
11    import java.io.Serializable;
12    import java.util.ArrayList;
13    import java.util.Collection;
14    import java.util.Collections;
15    import java.util.List;
16   
17    /**
18    * This is a super class that implements paging for browsers.
19    *
20    * Most other filters (which want paging ability) will extend this.
21    */
 
22    public class PagerFilter implements Serializable
23    {
24    int max = 20;
25    int start = 0;
26   
27    /**
28    * Get the current page out of a list of items - won't work well on any collection that isn't a list
29    */
 
30  0 toggle public Collection getCurrentPage(Collection itemsCol)
31    {
32  0 List items = null;
33   
34  0 if (itemsCol instanceof List)
35  0 items = (List) itemsCol;
36    else
37  0 items = new ArrayList(itemsCol); // should never call this but just incase!
38   
39  0 if (items == null || items.size() == 0)
40    {
41  0 start = 0;
42  0 return Collections.EMPTY_LIST;
43    }
44   
45    // now return the appropriate page of issues
46    // now make sure that the start is valid
47  0 if (start > items.size())
48    {
49  0 start = 0;
50  0 return items.subList(0, max);
51    }
52    else
53    {
54  0 return items.subList(start, Math.min(start + max, items.size()));
55    }
56    }
57   
 
58  0 toggle public int getMax()
59    {
60  0 return max;
61    }
62   
 
63  0 toggle public void setMax(int max)
64    {
65  0 this.max = max;
66    }
67   
 
68  0 toggle public int getStart()
69    {
70  0 return start;
71    }
72   
 
73  0 toggle public void setStart(int start)
74    {
75  0 this.start = start;
76    }
77   
 
78  0 toggle public int getEnd()
79    {
80  0 return start + max;
81    }
82   
 
83  0 toggle public int getNextStart()
84    {
85  0 return start + max;
86    }
87   
 
88  0 toggle public int getPreviousStart()
89    {
90  0 return Math.max(0, start - max);
91    }
92    }