01: // Copyright (c) Finn Bock
02:
03: package org.python.core;
04:
05: import java.util.Dictionary;
06: import java.util.Enumeration;
07: import java.util.Vector;
08:
09: class CollectionIter extends PyObject {
10: PyObject findCollection(Object object) {
11: if (object instanceof Vector) {
12: return new EnumerationIter(((Vector) object).elements());
13: }
14: if (object instanceof Enumeration) {
15: return new EnumerationIter(((Enumeration) object));
16: }
17: if (object instanceof Dictionary) {
18: return new EnumerationIter(((Dictionary) object).keys());
19: }
20:
21: return null;
22: }
23:
24: public PyObject next() {
25: PyObject ret = __iternext__();
26: if (ret == null) {
27: throw Py.StopIteration(null);
28: }
29: return ret;
30: }
31:
32: }
33:
34: class EnumerationIter extends CollectionIter {
35: private Enumeration proxy;
36:
37: public EnumerationIter(Enumeration proxy) {
38: this .proxy = proxy;
39: }
40:
41: public PyObject __iternext__() {
42: if (!this.proxy.hasMoreElements())
43: return null;
44: return Py.java2py(this.proxy.nextElement());
45: }
46: }
|