1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.repository.result

File AggregatedIterator.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
14
4
1
86
39
10
0.71
3.5
4
2.5

Classes

Class Line # Actions
AggregatedIterator 31 14 0% 10 24
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.repository.result;
21   
22    import java.util.Iterator;
23   
24    /**
25    * Makes several consecutive {@link Iterator}s look like one.
26    *
27    * @param <T> the type of the iterated values
28    * @version $Id: 435ba839a538dd6123737aa52354d7e6eff3a6f8 $
29    * @since 4.0M1
30    */
 
31    public class AggregatedIterator<T> implements Iterator<T>
32    {
33    /**
34    * The iterator of iterators.
35    */
36    private Iterator<Iterator<T>> iterators;
37   
38    /**
39    * The current iterator.
40    */
41    private Iterator<T> currentIterator;
42   
43    /**
44    * @param iterators the iterators to aggregated
45    */
 
46  0 toggle public AggregatedIterator(Iterator<Iterator<T>> iterators)
47    {
48  0 this.iterators = iterators;
49  0 this.currentIterator = iterators.next();
50    }
51   
 
52  0 toggle @Override
53    public boolean hasNext()
54    {
55  0 boolean hasNext = this.currentIterator.hasNext();
56   
57  0 if (!hasNext && this.iterators.hasNext()) {
58  0 this.currentIterator = this.iterators.next();
59  0 hasNext = this.currentIterator.hasNext();
60    }
61   
62  0 return hasNext;
63    }
64   
 
65  0 toggle @Override
66    public T next()
67    {
68  0 boolean hasNext = this.currentIterator.hasNext();
69   
70  0 if (!hasNext && this.iterators.hasNext()) {
71  0 this.currentIterator = this.iterators.next();
72    }
73   
74  0 return this.currentIterator.next();
75    }
76   
 
77  0 toggle @Override
78    public void remove()
79    {
80  0 this.currentIterator.remove();
81   
82  0 if (!this.currentIterator.hasNext() && this.iterators.hasNext()) {
83  0 this.currentIterator = this.iterators.next();
84    }
85    }
86    }