1 2 package org.python.modules.sets; 3 4 import org.python.core.PyObject; 5 import org.python.core.Py; 6 7 import java.util.Iterator ; 8 import java.util.Set ; 9 import java.util.ConcurrentModificationException ; 10 11 public class PySetIterator extends PyObject { 12 private Set _set; 13 private int _count; 14 private Iterator _iterator; 15 16 public PySetIterator(Set set) { 17 super(); 18 this._set = set; 19 this._count = 0; 20 this._iterator = set.iterator(); 21 } 22 23 public PyObject __iter__() { 24 return this; 25 } 26 27 39 public PyObject next() { 40 PyObject o = this.__iternext__(); 41 if (o == null) { 42 if (this._count != this._set.size()) { 43 throw Py.RuntimeError("dictionary changed size during iteration"); 46 } 47 throw Py.StopIteration(""); 48 } 49 return o; 50 } 51 52 58 public PyObject __iternext__() { 59 if (this._iterator.hasNext()) { 60 this._count++; 61 try { 62 return Py.java2py(this._iterator.next()); 63 } catch (ConcurrentModificationException e) { 64 throw Py.RuntimeError("dictionary changed size during iteration"); 65 } 66 } 67 return null; 68 } 69 } 70 | Popular Tags |