Mercurial > hg > Database > jungle-network
diff src/jungle/app/bbs/IterableConverter.java @ 66:29127ac788a6
move some files
author | one |
---|---|
date | Tue, 20 Aug 2013 17:38:09 +0900 |
parents | src/jungle/test/bbs/IterableConverter.java@d8ee57a1c2c6 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jungle/app/bbs/IterableConverter.java Tue Aug 20 17:38:09 2013 +0900 @@ -0,0 +1,52 @@ +package jungle.app.bbs; + +import java.util.Iterator; + +public class IterableConverter<A,B> implements Iterable<A> +{ + private final Iterable<B> iterable; + private final Converter<A,B> converter; + + public IterableConverter(Iterable<B> _iterable,Converter<A,B> _converter) + { + iterable = _iterable; + converter = _converter; + } + + public Iterator<A> iterator() + { + return new IteratorConverter<A,B>(iterable.iterator(),converter); + } + + private static final class IteratorConverter<A,B> implements Iterator<A> + { + private final Iterator<B> iterator; + private final Converter<A,B> converter; + + public IteratorConverter(Iterator<B> _iterator,Converter<A,B> _converter) + { + iterator = _iterator; + converter = _converter; + } + + public boolean hasNext() + { + return iterator.hasNext(); + } + + public A next() + { + return converter.conv(iterator.next()); + } + + public void remove() + { + iterator.remove(); + } + } + + public static interface Converter<A,B> + { + public A conv(B _b); + } +}