source: java2python/core/src/test/hasnext/testcode/HasNext.java

Last change on this file was 1353, checked in by wouter, 20 hours ago

#417 fixed issue in translate(MethodReferenceExpr). However javaparser generally has an issue with the resolve() call needed and we now recommend avoiding this anyway.

File size: 1.1 KB
Line 
1package testcode;
2
3import java.util.Arrays;
4import java.util.Iterator;
5
6/**
7 * To test iterator hasNext() which is pretty special in python
8 */
9public class HasNext {
10
11 public String stringit(Iterator<?> it) {
12 String res = "";
13 while (it.hasNext())
14 res += it.next().toString();
15 return res;
16 }
17
18 private Iterator<?> itt;
19
20 /**
21 * Same test, but now it uses a field rather than a local var for the
22 * iteration process. This makes huge difference in python also related to
23 * all the hacks we need for hasnext().
24 *
25 * @param it
26 * @return
27 */
28 public String stringitfield(Iterator it) {
29 this.itt = it;
30 String res = "";
31 while (itt.hasNext())
32 res += itt.next().toString();
33 return res;
34 }
35
36 static public void main(String[] args) {
37 HasNext obj = new HasNext();
38 System.out.println(obj.stringit(Arrays.asList(1, 2, 3).iterator()));
39 System.out.println(obj.stringit(Arrays.asList().iterator()));
40 System.out.println(obj.stringit(Arrays.asList("a", "b").iterator()));
41 System.out.println(
42 obj.stringit(Arrays.asList("fielda", "fieldb").iterator()));
43 }
44}
Note: See TracBrowser for help on using the repository browser.