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.tag.jstl.core;
20  
21  import java.io.Serializable;
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  /**
27   * Holds the iteration state generated by c:forEach tag.
28   */
29  public class IterationState implements Serializable
30  {
31      /**
32       * This counter is used to generate an unique base per element
33       * in the collection that will be used later in the id
34       * generation algorithm.
35       */
36      private int counter;
37      
38      private List<Object[]> valueList;
39      
40      public IterationState()
41      {
42          this.valueList = new ArrayList<Object[]>();
43      }
44  
45      /**
46       * @return the valueList
47       */
48      public List<Object[]> getValueList()
49      {
50          return valueList;
51      }
52  
53      /**
54       * @param valueList the valueList to set
55       */
56      public void setValueList(List<Object[]> valueList)
57      {
58          this.valueList = valueList;
59      }
60  
61      /**
62       * @return the counter
63       */
64      public int getCounter()
65      {
66          return counter;
67      }
68  
69      /**
70       * @param counter the counter to set
71       */
72      public void setCounter(int counter)
73      {
74          this.counter = counter;
75      }
76      
77      public Iterator getIterator()
78      {
79          return new IteratorWrapper(valueList.iterator());
80      }
81  
82      private static class IteratorWrapper implements Iterator
83      {
84          private Iterator<Object[]> delegate;
85  
86          public IteratorWrapper(Iterator<Object[]> delegate)
87          {
88              this.delegate = delegate;
89          }
90  
91          @Override
92          public boolean hasNext()
93          {
94              return delegate.hasNext();
95          }
96  
97          @Override
98          public Object next()
99          {
100             return delegate.next()[1];
101         }
102 
103         @Override
104         public void remove()
105         {
106             delegate.remove();
107         }
108     }
109 }