Skip to content

Commit 80cc8a5

Browse files
committed
Extract ifilterfalse.
1 parent 58a5f98 commit 80cc8a5

2 files changed

Lines changed: 73 additions & 14 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Copyright (c) Jython Developers */
2+
package org.python.modules.itertools;
3+
import org.python.core.ArgParser;
4+
import org.python.core.Py;
5+
import org.python.core.PyIterator;
6+
import org.python.core.PyObject;
7+
import org.python.core.PyString;
8+
import org.python.core.PyTuple;
9+
import org.python.core.PyType;
10+
import org.python.expose.ExposedClassMethod;
11+
import org.python.expose.ExposedGet;
12+
import org.python.expose.ExposedNew;
13+
import org.python.expose.ExposedMethod;
14+
import org.python.expose.ExposedType;
15+
16+
import java.util.ArrayList;
17+
18+
@ExposedType(name = "itertools.ifilterfalse", base = PyObject.class)
19+
public class ifilterfalse extends PyObject {
20+
21+
public static final PyType TYPE = PyType.fromClass(ifilterfalse.class);
22+
private PyIterator iter;
23+
24+
public ifilterfalse() {
25+
super();
26+
}
27+
28+
public ifilterfalse(PyType subType) {
29+
super(subType);
30+
}
31+
32+
public ifilterfalse(PyObject predicate, PyObject iterable) {
33+
super();
34+
ifilterfalse___init__(predicate, iterable);
35+
}
36+
37+
@ExposedGet
38+
public static PyString __doc__ = new PyString(
39+
"'ifilterfalse(function or None, sequence) --> ifilterfalse object\n\n"
40+
+ "Return those items of sequence for which function(item) is false.\nIf function is None, "
41+
+ "return the items that are false.'");
42+
43+
/**
44+
* Creates an iterator that returns the items of the iterable for which
45+
* <code>predicate(item)</code> is <code>false</code>. If <code>predicate</code> is null
46+
* (None) return the items that are false.
47+
*/
48+
@ExposedNew
49+
@ExposedMethod
50+
final void ifilterfalse___init__(PyObject[] args, String[] kwds) {
51+
ArgParser ap = new ArgParser("ifilterfalse", args, kwds, "predicate", "iterable");
52+
ap.noKeywords();
53+
PyObject predicate = ap.getPyObject(0);
54+
PyObject iterable = ap.getPyObject(1);
55+
ifilterfalse___init__(predicate, iterable);
56+
}
57+
58+
public void ifilterfalse___init__(PyObject predicate, PyObject iterable) {
59+
iter = new itertools.FilterIterator(predicate, iterable, false);
60+
}
61+
62+
@ExposedMethod
63+
public PyObject __iter__() {
64+
return iter;
65+
}
66+
67+
@ExposedMethod
68+
public PyObject next() {
69+
return iter.next();
70+
}
71+
72+
}

src/org/python/modules/itertools/itertools.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static void classDictInit(PyObject dict) {
8585
dict.__setitem__("chain", chain.TYPE);
8686
dict.__setitem__("imap", imap.TYPE);
8787
dict.__setitem__("ifilter", ifilter.TYPE);
88+
dict.__setitem__("ifilterfalse", ifilterfalse.TYPE);
8889
dict.__setitem__("izip", izip.TYPE);
8990

9091
// Hide from Python
@@ -367,20 +368,6 @@ public PyObject __iternext__() {
367368
}
368369
}
369370

370-
public static PyString __doc__ifilterfalse = new PyString(
371-
"'ifilterfalse(function or None, sequence) --> ifilterfalse object\n\n"
372-
+ "Return those items of sequence for which function(item) is false.\nIf function is None, "
373-
+ "return the items that are false.'");
374-
375-
/**
376-
* Creates an iterator that returns the items of the iterable for which
377-
* <code>predicate(item)</code> is <code>false</code>. If <code>predicate</code> is null
378-
* (None) return the items that are false.
379-
*/
380-
public static PyIterator ifilterfalse(PyObject predicate, PyObject iterable) {
381-
return new FilterIterator(predicate, iterable, false);
382-
}
383-
384371
public static PyString __doc__starmap = new PyString(
385372
"starmap(function, sequence) --> starmap object\n\nReturn an "
386373
+ "iterator whose values are returned from the function evaluated\nwith an argument tuple taken from the "

0 commit comments

Comments
 (0)