66
|
1 package jungle.app.bbs;
|
38
|
2
|
|
3 import java.util.Iterator;
|
|
4
|
|
5 public class IterableConverter<A,B> implements Iterable<A>
|
|
6 {
|
|
7 private final Iterable<B> iterable;
|
|
8 private final Converter<A,B> converter;
|
|
9
|
|
10 public IterableConverter(Iterable<B> _iterable,Converter<A,B> _converter)
|
|
11 {
|
|
12 iterable = _iterable;
|
|
13 converter = _converter;
|
|
14 }
|
|
15
|
|
16 public Iterator<A> iterator()
|
|
17 {
|
|
18 return new IteratorConverter<A,B>(iterable.iterator(),converter);
|
|
19 }
|
|
20
|
|
21 private static final class IteratorConverter<A,B> implements Iterator<A>
|
|
22 {
|
|
23 private final Iterator<B> iterator;
|
|
24 private final Converter<A,B> converter;
|
|
25
|
|
26 public IteratorConverter(Iterator<B> _iterator,Converter<A,B> _converter)
|
|
27 {
|
|
28 iterator = _iterator;
|
|
29 converter = _converter;
|
|
30 }
|
|
31
|
|
32 public boolean hasNext()
|
|
33 {
|
|
34 return iterator.hasNext();
|
|
35 }
|
|
36
|
|
37 public A next()
|
|
38 {
|
|
39 return converter.conv(iterator.next());
|
|
40 }
|
|
41
|
|
42 public void remove()
|
|
43 {
|
|
44 iterator.remove();
|
|
45 }
|
|
46 }
|
|
47
|
|
48 public static interface Converter<A,B>
|
|
49 {
|
|
50 public A conv(B _b);
|
|
51 }
|
|
52 }
|