01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.jsp;
06:
07: /**
08: * The iterator tag can export an IteratorStatus object so that
09: * one can get information about the status of the iteration, such as
10: * the size, current index, and whether any more items are available.
11: *
12: * @author Rickard Öberg (rickard@dreambean.com)
13: */
14: public class IteratorStatus {
15: protected StatusState state;
16:
17: public IteratorStatus(StatusState aState) {
18: state = aState;
19: }
20:
21: public int getCount() {
22: return state.index + 1;
23: }
24:
25: public boolean isEven() {
26: return ((state.index + 1) % 2) == 0;
27: }
28:
29: public boolean isFirst() {
30: return state.index == 0;
31: }
32:
33: public int getIndex() {
34: return state.index;
35: }
36:
37: public boolean isLast() {
38: return state.last;
39: }
40:
41: public boolean isOdd() {
42: return ((state.index + 1) % 2) == 1;
43: }
44:
45: public int modulus(int operand) {
46: return (state.index + 1) % operand;
47: }
48:
49: public static class StatusState {
50: boolean last = false;
51: int index = 0;
52:
53: public void setLast(boolean isLast) {
54: last = isLast;
55: }
56:
57: public void next() {
58: index++;
59: }
60: }
61: }
|