1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.jsp;
22
23
24 /***
25 * The iterator tag can export an IteratorStatus object so that
26 * one can get information about the status of the iteration, such as
27 * the size, current index, and whether any more items are available.
28 *
29 */
30 public class IteratorStatus {
31 protected StatusState state;
32
33 public IteratorStatus(StatusState aState) {
34 state = aState;
35 }
36
37 public int getCount() {
38 return state.index + 1;
39 }
40
41 public boolean isEven() {
42 return ((state.index + 1) % 2) == 0;
43 }
44
45 public boolean isFirst() {
46 return state.index == 0;
47 }
48
49 public int getIndex() {
50 return state.index;
51 }
52
53 public boolean isLast() {
54 return state.last;
55 }
56
57 public boolean isOdd() {
58 return ((state.index + 1) % 2) == 1;
59 }
60
61 public int modulus(int operand) {
62 return (state.index + 1) % operand;
63 }
64
65 public static class StatusState {
66 boolean last = false;
67 int index = 0;
68
69 public void setLast(boolean isLast) {
70 last = isLast;
71 }
72
73 public void next() {
74 index++;
75 }
76 }
77 }