| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GIteratorWithAction |
|
| 0.0;0 |
| 1 | /* | |
| 2 | This file is part of Combean. | |
| 3 | ||
| 4 | Combean is free software; you can redistribute it and/or modify | |
| 5 | it under the terms of the GNU General Public License as published by | |
| 6 | the Free Software Foundation; either version 2 of the License, or | |
| 7 | (at your option) any later version. | |
| 8 | ||
| 9 | Combean is distributed in the hope that it will be useful, | |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | GNU General Public License for more details. | |
| 13 | ||
| 14 | You should have received a copy of the GNU General Public License | |
| 15 | along with Foobar; if not, write to the Free Software | |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | */ | |
| 18 | package net.sourceforge.combean.util | |
| 19 | ||
| 20 | /** | |
| 21 | * Iterator with a Closure that is evaluated every time next() is called. | |
| 22 | * | |
| 23 | * The Closure gets the current value of the Iteration as argument. | |
| 24 | */ | |
| 25 | class GIteratorWithAction implements Iterator { | |
| 26 | ||
| 27 | private Iterator iter; | |
| 28 | private Closure action; | |
| 29 | ||
| 30 | /** | |
| 31 | * Constructor | |
| 32 | * | |
| 33 | * @params iter Iterator which controls the iteration process | |
| 34 | * @params action Closure which is called for every next() step | |
| 35 | */ | |
| 36 | public GIteratorWithAction(Iterator iter, Closure action) { | |
| 37 | 2095 | this.iter = iter; |
| 38 | 2095 | this.action = action; |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | public boolean hasNext() { | |
| 43 | 9350 | return this.iter.hasNext(); |
| 44 | } | |
| 45 | ||
| 46 | public Object next() { | |
| 47 | 7245 | Object result = this.iter.next(); |
| 48 | 7245 | this.action.call(result); |
| 49 | 7245 | return result; |
| 50 | } | |
| 51 | ||
| 52 | public void remove() { | |
| 53 | 0 | this.iter.remove(); |
| 54 | } | |
| 55 | ||
| 56 | } |