Top Description Fields Constructors Methods
org.python.core

public abstract Class PyIterator

extends PyObject
implements Iterable<Object>, Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc, java.lang.Iterable
Known Direct Subclasses
org.python.core.PyJavaType.EnumerationIter, org.python.core.PyListIterator, org.python.core.PyReversedIterator, org.python.core.PySequenceIter, org.python.core.PyTupleIterator, org.python.core.PyXRangeIter, org.python.jsr223.PyScriptEngineScope.ScopeIterator, org.python.modules.cStringIO.StringIO, org.python.modules.bz2.PyBZ2File.BZ2FileIterator, org.python.modules.itertools.ifilter, org.python.modules.itertools.chain, org.python.modules.itertools.combinations, org.python.modules.itertools.combinationsWithReplacement, org.python.modules.itertools.compress, org.python.modules.itertools.count, org.python.modules.itertools.cycle, org.python.modules.itertools.dropwhile, org.python.modules.itertools.groupby, org.python.modules.itertools.ifilterfalse, org.python.modules.itertools.imap, org.python.modules.itertools.islice, org.python.modules.itertools.itertools.ItertoolsIterator, org.python.modules.itertools.izip, org.python.modules.itertools.izipLongest, org.python.modules.itertools.permutations, org.python.modules.itertools.product, org.python.modules.itertools.PyTeeIterator, org.python.modules.itertools.repeat, org.python.modules.itertools.starmap, org.python.modules.itertools.takewhile, org.python.modules.jffi.ArrayCData.ArrayIter, org.python.modules._collections.PyDeque.PyDequeIter, org.python.modules._csv.PyReader, org.python.core.AbstractDict.AbstractDictIter, org.python.core.JavaIterator, org.python.core.PyCallIter, org.python.core.PyEnumerate, org.python.core.PyFastSequenceIter, org.python.core.PyGenerator
Imports
java.util.ArrayList, .Collection, .Iterator, .List

An abstract helper class useful when implementing an iterator object. This implementation supply a correct __iter__() and a next() method based on the __iternext__() implementation. The __iternext__() method must be supplied by the subclass. If the implementation raises a StopIteration exception, it should be stored in stopException so the correct exception can be thrown to preserve the line numbers in the traceback.

Field Summary

Modifier and TypeField and Description
public static PyString
protected PyException
Inherited from org.python.core.PyObject:
attributesgcMonitorGlobalobjtypeTYPE

Constructor Summary

AccessConstructor and Description
public
public
PyIterator(PyType subType)

Method Summary

Modifier and TypeMethod and Description
public PyObject
__iter__()

Overrides org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence.

public abstract PyObject
__iternext__()

Overrides org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for.

public Object
__tojava__(Class<?>
the Class to convert this PyObject to.
c
)

Overrides org.python.core.PyObject.__tojava__.

Equivalent to the Jython __tojava__ method.

protected final PyObject
public Iterator<Object>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public PyObject

Returns:

a PyObject result
next
()

The exposed next method.

public boolean
public int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

Inherited from org.python.core.PyObject:
__abs____add____and____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____cmp____coerce____coerce_ex____complex____contains____delattr____delattr____delete____delitem____delitem____delslice____delslice____dir____div____divmod____ensure_finalizer____eq____findattr____findattr____findattr_ex____finditem____finditem____finditem____float____floordiv____format____ge____get____getattr____getattr____getitem____getitem____getnewargs____getslice____getslice____gt____hash____hex____iadd____iand____idiv____idivmod____ifloordiv____ilshift____imod____imul____index____int____invert____ior____ipow____irshift____isub____itruediv____ixor____le____len____long____lshift____lt____mod____mul____ne____neg____nonzero____not____oct____or____pos____pow____pow____radd____rand____rawdir____rdiv____rdivmod____reduce____reduce_ex____reduce_ex____repr____rfloordiv____rlshift____rmod____rmul____ror____rpow____rrshift____rshift____rsub____rtruediv____rxor____set____setattr____setattr____setitem____setitem____setitem____setslice____setslice____str____sub____truediv____trunc____unicode____xor___add_and_basic_add_basic_and_basic_div_basic_divmod_basic_floordiv_basic_iadd_basic_iand_basic_idiv_basic_idivmod_basic_ifloordiv_basic_ilshift_basic_imod_basic_imul_basic_ior_basic_ipow_basic_irshift_basic_isub_basic_itruediv_basic_ixor_basic_lshift_basic_mod_basic_mul_basic_or_basic_pow_basic_rshift_basic_sub_basic_truediv_basic_xor_callextra_cmp_coerce_div_divmod_doget_doget_doset_eq_floordiv_ge_gt_iadd_iand_idiv_idivmod_ifloordiv_ilshift_imod_imul_in_ior_ipow_irshift_is_isnot_isub_itruediv_ixor_jcall_jcallexc_jthrow_le_lshift_lt_mod_mul_ne_notin_or_pow_rshift_sub_truediv_unsupportedop_xoradaptToCoerceTupleasDoubleasIndexasIndexasIntasIntasIterableasLongasLongasNameasNameasStringasStringasStringOrNullasStringOrNullbit_lengthconjugatedelDictdelTypedispatch__init__equalsfastGetClassfastGetDictfinalizegetDictgetJavaProxygetTypehashCodeimpAttrimplementsDescrDeleteimplementsDescrGetimplementsDescrSetinvokeinvokeinvokeinvokeinvokeinvokeisCallableisDataDescrisIndexisIntegerisMappingTypeisNumberTypeisSequenceTypejdontdelmergeClassDictmergeDictAttrmergeListAttrnoAttributeErrorobject___contains__object___delattr__object___delattr__object___findattr__object___format__object___getattribute__object___hash__object___init__object___new__object___reduce__object___reduce_ex__object___setattr__object___setattr__object___subclasshook__object_toStringproxyInitreadonlyAttributeErrorrunsupportedopMessagesetDictsetTypetoStringunsupportedopMessage

Field Detail

__doc__nextback to summary
public static PyString __doc__next
stopExceptionback to summary
protected PyException stopException

Constructor Detail

PyIteratorback to summary
public PyIterator()
PyIteratorback to summary
public PyIterator(PyType subType)

Method Detail

__iter__back to summary
public PyObject __iter__()

Overrides org.python.core.PyObject.__iter__.

Doc from org.python.core.PyObject.__iter__.

Return an iterator that is used to iterate the element of this sequence. From version 2.2, this method is the primary protocol for looping over sequences.

If a PyObject subclass should support iteration based in the __finditem__() method, it must supply an implementation of __iter__() like this:

public PyObject __iter__() {
    return new PySequenceIter(this);
}
When iterating over a python sequence from java code, it should be done with code like this:
for (PyObject item : seq.asIterable()) {
    // Do something with item
}
__iternext__back to summary
public abstract PyObject __iternext__()

Overrides org.python.core.PyObject.__iternext__.

Doc from org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for. Returns null when the end of the sequence is reached.

__tojava__back to summary
public Object __tojava__(Class<?> c)

Overrides org.python.core.PyObject.__tojava__.

Doc from org.python.core.PyObject.__tojava__.

Equivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special object Py.NoConversion if this PyObject can not be converted to the desired Java class.

Parameters
c:Class<?>

the Class to convert this PyObject to.

Annotations
@Override
doNextback to summary
protected final PyObject doNext(PyObject ret)
iteratorback to summary
public Iterator<Object> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Object>

an Iterator.

nextback to summary
public PyObject next()

The exposed next method. Note that exposed derivable subclasses of PyIterator should override next to call doNext(custom___iternext__), as __iternext__ is overridden by the Derived classes.

Returns:PyObject

a PyObject result

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob)

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
traverseback to summary
public int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override