| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jeffpalm.util.AbstractIterator
public abstract class AbstractIterator
This makes it easy to define type-safe iterators.
 Simply define an inner interface called Iterator, then
 implement it with a static inner class that extends this
 class and implements the interface, then add a factory
 method called iterator(java.util.Iterator).
 Here's an example:
 
  public class Outer {
    public interface Iterator {
      Outer next();
      boolean hasNext();
    }
    public final static Iterator iterator(java.util.Iterator it) {
      return new IteratorImpl(it);
    }
    private final static class IteratorImpl
      extends com.jeffpalm.util.AbstractIterator
      implements Iterator {
      private IteratorImpl(java.util.Iterator it) { super(it); }
 public Outer next() { return (Outer)it.next(); }
    }
  }
 
 
There you go... enjoy!
| Field Summary | |
|---|---|
| protected  java.util.Iterator | itThe underlying Iterator. | 
| Constructor Summary | |
|---|---|
| AbstractIterator(java.util.Iterator it)Sets the underlying iterator. | |
| Method Summary | |
|---|---|
|  boolean | hasNext()Same as java.util.Iterator.hasNext(). | 
| static void | main(java.lang.String[] args)For generating one. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
protected final java.util.Iterator it
| Constructor Detail | 
|---|
public AbstractIterator(java.util.Iterator it)
| Method Detail | 
|---|
public final boolean hasNext()
java.util.Iterator.hasNext().
public static void main(java.lang.String[] args)
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||