View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.component;
20  
21  import java.io.Serializable;
22  
23  /**
24   * This class is used as the bean that contains all the status
25   * information of UIRepeat during iteration. It is stored in the 
26   * RequestScope under the key specified in varStatus of UIRepeat.
27   * 
28   * @author Curtiss Howard (latest modification by $Author$)
29   * @version $Revision$ $Date$
30   */
31  public final class RepeatStatus implements Serializable
32  {
33  
34      private static final long serialVersionUID = 1L;
35      
36      private final int count;
37      
38      private final int index;
39  
40      private final boolean first;
41  
42      private final boolean last;
43  
44      private final Integer begin;
45  
46      private final Integer end;
47  
48      private final Integer step;
49      
50      public RepeatStatus(boolean first, boolean last, int count, int index, 
51              Integer begin, Integer end, Integer step)
52      {
53          this.count = count;
54          this.index = index;
55          this.begin = begin;
56          this.end = end;
57          this.step = step;
58          this.first = first;
59          this.last = last;
60      }
61  
62      public boolean isFirst()
63      {
64          return first;
65      }
66  
67      public boolean isLast()
68      {
69          return last;
70      }
71      
72      public boolean isEven ()
73      {
74          return ((count % 2) == 0);
75      }
76      
77      public boolean isOdd ()
78      {
79          return !isEven();
80      }
81      
82      public Integer getBegin()
83      {
84          if (begin == -1)
85          {
86              return null;
87          }
88          
89          return begin;
90      }
91      
92      public Integer getEnd()
93      {
94          if (end == -1)
95          {
96              return null;
97          }
98          
99          return end;
100     }
101 
102     public int getIndex()
103     {
104         return index;
105     }
106 
107     public Integer getStep()
108     {
109         if (step == -1)
110         {
111             return null;
112         }
113         
114         return step;
115     }
116 
117 }