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.component.html.ext;
20  
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.NoSuchElementException;
24  
25  import javax.faces.component.UIComponent;
26  
27  /**
28   * @author Leonardo Uribe
29   * @since 1.1.10
30   */
31  class _DetailStampFacetAndChildrenIterator implements Iterator<UIComponent>
32  {
33      private UIComponent _detailStamp;
34      private Iterator<UIComponent> _childrenIterator;
35  
36      _DetailStampFacetAndChildrenIterator(UIComponent detailStamp, List<UIComponent> childrenList)
37      {
38          _detailStamp = detailStamp;
39          _childrenIterator = childrenList != null ? childrenList.iterator() : null;
40      }
41  
42      public boolean hasNext()
43      {
44          boolean hasNext = (_detailStamp != null)
45                  || (_childrenIterator != null && _childrenIterator.hasNext());
46          if (!hasNext)
47          {
48              _detailStamp = null;
49              _childrenIterator = null;
50          }
51          
52          return hasNext;
53      }
54  
55      public UIComponent next()
56      {
57          if (_detailStamp != null)
58          {
59              UIComponent detailStamp = _detailStamp;
60              _detailStamp = null;
61              return detailStamp;
62          }
63          else if (_childrenIterator != null && _childrenIterator.hasNext())
64          {
65              return _childrenIterator.next();
66          }
67          else
68          {
69              throw new NoSuchElementException();
70          }
71      }
72  
73      public void remove()
74      {
75          throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
76      }
77  }