KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > iterators > TransformIterator


1 package uk.co.jezuk.mango.iterators;
2
3 /**
4  * A <code>TransfromIterator</code> applies a <code>UnaryFunction</code> to
5  * each element in the sequence, returning the the function result at each step.
6  *
7  * @author Jez Higgins, jez@jezuk.co.uk
8  * @version $Id: TransformIterator.java 72 2003-03-28 20:32:54Z jez $
9  */

10 public class TransformIterator implements java.util.Iterator JavaDoc
11 {
12   public TransformIterator(java.util.Iterator JavaDoc iterator, uk.co.jezuk.mango.UnaryFunction transform)
13   {
14     iter_ = iterator;
15     transform_ = transform;
16   } // TransformIterator
17

18   public boolean hasNext()
19   {
20     return iter_.hasNext();
21   } // hasNext
22

23   public Object JavaDoc next()
24   {
25     return transform_.fn(iter_.next());
26   } // next
27

28   public void remove()
29   {
30     iter_.remove();
31   } // remove
32

33   ////////////////////////
34
private java.util.Iterator JavaDoc iter_;
35   private uk.co.jezuk.mango.UnaryFunction transform_;
36 } // TransformIterator
37

38
39
Popular Tags