annotate src/jungle/test/bbs/IterableConverter.java @ 38:d8ee57a1c2c6

add pom.xml and bbs
author one
date Mon, 08 Jul 2013 20:25:58 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
1 package jungle.test.bbs;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
2
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
3 import java.util.Iterator;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
4
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
5 public class IterableConverter<A,B> implements Iterable<A>
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
6 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
7 private final Iterable<B> iterable;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
8 private final Converter<A,B> converter;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
9
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
10 public IterableConverter(Iterable<B> _iterable,Converter<A,B> _converter)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
11 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
12 iterable = _iterable;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
13 converter = _converter;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
14 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
15
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
16 public Iterator<A> iterator()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
17 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
18 return new IteratorConverter<A,B>(iterable.iterator(),converter);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
19 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
20
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
21 private static final class IteratorConverter<A,B> implements Iterator<A>
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
22 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
23 private final Iterator<B> iterator;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
24 private final Converter<A,B> converter;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
25
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
26 public IteratorConverter(Iterator<B> _iterator,Converter<A,B> _converter)
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
27 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
28 iterator = _iterator;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
29 converter = _converter;
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
30 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
31
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
32 public boolean hasNext()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
33 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
34 return iterator.hasNext();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
35 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
36
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
37 public A next()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
38 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
39 return converter.conv(iterator.next());
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
40 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
41
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
42 public void remove()
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
43 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
44 iterator.remove();
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
45 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
46 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
47
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
48 public static interface Converter<A,B>
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
49 {
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
50 public A conv(B _b);
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
51 }
d8ee57a1c2c6 add pom.xml and bbs
one
parents:
diff changeset
52 }