-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathBaseDictionaryView.java
More file actions
176 lines (142 loc) · 4.39 KB
/
BaseDictionaryView.java
File metadata and controls
176 lines (142 loc) · 4.39 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package org.python.core;
/*
* See these for details on the dictionary views
* http://docs.python.org/dev/whatsnew/2.7.html#pep-3106-dictionary-views
* http://hg.python.org/cpython/rev/d9805a96351c
*/
import java.util.Iterator;
public abstract class BaseDictionaryView extends PyObject implements Traverseproc {
protected final AbstractDict dvDict;
public BaseDictionaryView(AbstractDict dvDict) {
this.dvDict = dvDict;
}
final boolean allContainedIn(PyObject self, PyObject other) {
for (PyObject ob_value: self.asIterable()) {
if (!other.__contains__(ob_value)) {
return false;
}
}
return true;
}
static final boolean isSetDictViewInstance(PyObject otherObj) {
if (otherObj instanceof BaseSet || otherObj instanceof BaseDictionaryView) {
return true;
}
return false;
}
public int __len__() {
return dict_view___len__();
}
final int dict_view___len__() {
return dvDict.getMap().size();
}
public PyObject __eq__(PyObject otherObj) {
return dict_view___eq__(otherObj);
}
final PyObject dict_view___eq__(PyObject otherObj) {
if (!isSetDictViewInstance(otherObj)) {
return Py.False;
}
if (this.__len__() != otherObj.__len__()) {
return Py.False;
}
if (!allContainedIn(this, otherObj)) {
return Py.False;
}
return Py.True;
}
public PyObject __ne__(PyObject otherObj) {
return dict_view___ne__(otherObj);
}
final PyObject dict_view___ne__(PyObject otherObj) {
if (dict_view___eq__(otherObj) == Py.True) {
return Py.False;
}
return Py.True;
}
public PyObject __lt__(PyObject otherObj) {
return dict_view___lt__(otherObj);
}
final PyObject dict_view___lt__(PyObject otherObj) {
if (!isSetDictViewInstance(otherObj)) {
return Py.False;
}
if (this.__len__() < otherObj.__len__()) {
if (allContainedIn(this, otherObj)) {
return Py.False;
}
}
return Py.True;
}
public PyObject __le__(PyObject otherObj) {
return dict_view___le__(otherObj);
}
final PyObject dict_view___le__(PyObject otherObj) {
if (!isSetDictViewInstance(otherObj)) {
return Py.False;
}
if (this.__len__() <= otherObj.__len__()) {
if (allContainedIn(this, otherObj)) {
return Py.False;
}
}
return Py.True;
}
public PyObject __gt__(PyObject otherObj) {
return dict_view___gt__(otherObj);
}
final PyObject dict_view___gt__(PyObject otherObj) {
if (!isSetDictViewInstance(otherObj)) {
return Py.False;
}
if (this.__len__() > otherObj.__len__()) {
if (allContainedIn(otherObj, this)) {
return Py.False;
}
}
return Py.True;
}
public PyObject __ge__(PyObject otherObj) {
return dict_view___ge__(otherObj);
}
final PyObject dict_view___ge__(PyObject otherObj) {
if (!isSetDictViewInstance(otherObj)) {
return Py.False;
}
if (this.__len__() >= otherObj.__len__()) {
if (allContainedIn(otherObj, this)) {
return Py.False;
}
}
return Py.True;
}
public String toString() {
return dict_view_toString();
}
final String dict_view_toString() {
String name = getType().fastGetName();
ThreadState ts = Py.getThreadState();
if (!ts.enterRepr(this)) {
return name + "([])";
}
StringBuilder buf = new StringBuilder(name).append("([");
for (Iterator<PyObject> i = this.asIterable().iterator(); i.hasNext();) {
buf.append((i.next()).__repr__().toString());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append("])");
ts.exitRepr(this);
return buf.toString();
}
/* Traverseproc implementation */
@Override
public int traverse(Visitproc visit, Object arg) {
return dvDict != null ? visit.visit(dvDict, arg) : 0;
}
@Override
public boolean refersDirectlyTo(PyObject ob) {
return ob != null && dvDict == ob;
}
}