KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright (c) Finn Bock
2

3 package org.python.core;
4 import java.util.*;
5
6 class CollectionIter extends PyObject {
7     PyObject findCollection(Object JavaDoc object) {
8         if (object instanceof Vector) {
9             return new EnumerationIter(((Vector)object).elements());
10         }
11         if (object instanceof Enumeration) {
12             return new EnumerationIter(((Enumeration)object));
13         }
14         if (object instanceof Dictionary) {
15             return new EnumerationIter(((Dictionary)object).keys());
16         }
17
18         return null;
19     }
20
21     public PyObject next() {
22         PyObject ret = __iternext__();
23         if (ret == null)
24             throw Py.StopIteration(null);
25         return ret;
26     }
27         
28 }
29
30 class EnumerationIter extends CollectionIter {
31     private Enumeration proxy;
32
33     public EnumerationIter(Enumeration proxy) {
34         this.proxy = proxy;
35     }
36
37     public PyObject __iternext__() {
38         if (!proxy.hasMoreElements())
39             return null;
40         return Py.java2py(proxy.nextElement());
41     }
42 }
43
Popular Tags