gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / util / MappedIterator.java @ 2335
History | View | Annotate | Download (568 Bytes)
1 | 1886 | jjdelcerro | package org.gvsig.tools.util; |
---|---|---|---|
2 | |||
3 | import java.util.Iterator; |
||
4 | import java.util.function.Function; |
||
5 | |||
6 | /**
|
||
7 | *
|
||
8 | * @author jjdelcerro
|
||
9 | */
|
||
10 | public class MappedIterator<S,T> implements Iterator<T> { |
||
11 | |||
12 | private final Iterator<S> it; |
||
13 | private final Function<S,T> mapping; |
||
14 | |||
15 | public MappedIterator(Iterator<S> it, Function<S,T> mapping) { |
||
16 | this.it = it;
|
||
17 | this.mapping = mapping;
|
||
18 | } |
||
19 | |||
20 | @Override
|
||
21 | public boolean hasNext() { |
||
22 | return this.it.hasNext(); |
||
23 | } |
||
24 | |||
25 | @Override
|
||
26 | public T next() {
|
||
27 | return this.mapping.apply(it.next()); |
||
28 | } |
||
29 | |||
30 | } |