KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > PyIterator


1 // Copyright 2000 Finn Bock
2

3 package org.python.core;
4
5 /**
6  * An abstract helper class usefull when implementing an iterator object.
7  * This implementation supply a correct __iter__() and a next() method
8  * based on the __iternext__() implementation.
9  * The __iternext__() method must be supplied by the subclass.
10  */

11 public abstract class PyIterator extends PyObject {
12     public PyObject __iter__() {
13         return this;
14     }
15
16     public static PyString __doc__next = new PyString(
17         "x.next() -> the next value, or raise StopIteration"
18     );
19
20     public PyObject next() {
21         PyObject ret = __iternext__();
22         if (ret == null)
23             throw Py.StopIteration("");
24         return ret;
25     }
26
27     public abstract PyObject __iternext__();
28 }
29
Popular Tags