KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright (c) Finn Bock
2

3 package org.python.core;
4 import java.util.*;
5
6 class CollectionIter2 extends CollectionIter {
7     CollectionIter2() throws Exception JavaDoc {
8         Class.forName("java.util.Collection");
9     }
10
11     PyObject findCollection(Object JavaDoc object) {
12         if (object instanceof Map) {
13             return new IteratorIter(((Map)object).keySet().iterator());
14         }
15         if (object instanceof Collection) {
16             return new IteratorIter(((Collection)object).iterator());
17         }
18         if (object instanceof Iterator) {
19             return new IteratorIter(((Iterator)object));
20         }
21
22         return null;
23     }
24 }
25
26 class IteratorIter extends CollectionIter {
27     private Iterator proxy;
28
29     public IteratorIter(Iterator proxy) {
30         this.proxy = proxy;
31     }
32
33     public PyObject __iternext__() {
34         if (!proxy.hasNext())
35             return null;
36         return Py.java2py(proxy.next());
37     }
38 }
39
Popular Tags