KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > IteratorStatus


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7
8 /**
9  * The iterator tag can export an IteratorStatus object so that
10  * one can get information about the status of the iteration, such as
11  * the size, current index, and whether any more items are available.
12  *
13  * @author Rickard Öberg (rickard@dreambean.com)
14  */

15 public class IteratorStatus {
16     //~ Instance fields ////////////////////////////////////////////////////////
17

18     // Attributes ----------------------------------------------------
19
protected StatusState state;
20
21     //~ Constructors ///////////////////////////////////////////////////////////
22

23     // Static --------------------------------------------------------
24
// Constructors --------------------------------------------------
25
public IteratorStatus(StatusState aState) {
26         state = aState;
27     }
28
29     //~ Methods ////////////////////////////////////////////////////////////////
30

31     public int getCount() {
32         return state.index + 1;
33     }
34
35     public boolean isEven() {
36         return ((state.index + 1) % 2) == 0;
37     }
38
39     // Public --------------------------------------------------------
40
public boolean isFirst() {
41         return state.index == 0;
42     }
43
44     public int getIndex() {
45         return state.index;
46     }
47
48     public boolean isLast() {
49         return state.last;
50     }
51
52     public boolean isOdd() {
53         return ((state.index + 1) % 2) == 1;
54     }
55
56     public int modulus(int operand) {
57         return (state.index + 1) % operand;
58     }
59
60     //~ Inner Classes //////////////////////////////////////////////////////////
61

62     public static class StatusState {
63         boolean last = false;
64         int index = 0;
65
66         public void setLast(boolean isLast) {
67             last = isLast;
68         }
69
70         public void next() {
71             index++;
72         }
73     }
74 }
75
Popular Tags