-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathCompareOp.java
More file actions
70 lines (62 loc) · 1.72 KB
/
Copy pathCompareOp.java
File metadata and controls
70 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.python.core;
public enum CompareOp {
LT(0), LE(1), EQ(2), NE(3), GT(4), GE(5);
private int n;
private static final CompareOp[] swappedOps = new CompareOp[] {
GT, GE, EQ, NE, LT, LE
};
private static final String[] stringOps = new String[] {
"<", "<=", "==", "!=", ">", ">="
};
private static final String[] methOps = new String[] {
"__lt__", "__le__", "__eq__", "__ne__", "__gt__", "__ge__"
};
CompareOp(int n) {
this.n = n;
}
public CompareOp reflectedOp() {
return swappedOps[n];
}
public PyObject bool(int result) {
if (result < -1) {
// if (this == EQ) {
// return Py.False;
// } else if (this == NE) {
// return Py.True;
// }
return Py.NotImplemented;
}
switch(this) {
case LT:
return Py.newBoolean(result < 0);
case LE:
return Py.newBoolean(result <= 0);
case EQ:
return Py.newBoolean(result == 0);
case NE:
return Py.newBoolean(result != 0);
case GT:
return Py.newBoolean(result > 0);
case GE:
return Py.newBoolean(result >= 0);
default:
return Py.NotImplemented;
}
}
public PyObject neq() {
switch (this) {
case EQ:
return Py.False;
case NE:
return Py.True;
default:
return Py.NotImplemented;
}
}
public String toString() {
return stringOps[n];
}
public String meth() {
return methOps[n];
}
}