-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
LazyJSONImplFactory.java
318 lines (259 loc) · 10.8 KB
/
LazyJSONImplFactory.java
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package twitter4j;
import twitter4j.api.HelpResources;
import twitter4j.conf.Configuration;
import java.util.Map;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.2.4
*/
class LazyJSONImplFactory implements ObjectFactory {
private static final long serialVersionUID = -8140872181877586582L;
private final ObjectFactory factory;
private final Configuration conf;
public LazyJSONImplFactory(Configuration conf) {
factory = new JSONImplFactory(conf);
this.conf = conf;
}
@Override
public Status createStatus(JSONObject json) throws TwitterException {
return new StatusJSONImpl(json);
}
@Override
public User createUser(JSONObject json) throws TwitterException {
return new UserJSONImpl(json);
}
@Override
public UserList createAUserList(JSONObject json) throws TwitterException {
return new UserListJSONImpl(json);
}
@Override
public Map<String, RateLimitStatus> createRateLimitStatuses(HttpResponse res) throws TwitterException {
return factory.createRateLimitStatuses(res);
}
@Override
public Status createStatus(HttpResponse res) throws TwitterException {
return new LazyStatus(res, factory);
}
@Override
public ResponseList<Status> createStatusList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Status>() {
private static final long serialVersionUID = 7409380696188770069L;
@Override
protected ResponseList<Status> createActualResponseList() throws TwitterException {
return StatusJSONImpl.createStatusList(res, conf);
}
};
}
@Override
public Trends createTrends(HttpResponse res) throws TwitterException {
return new LazyTrends(res, factory);
}
public ResponseList<Trends> createTrendsList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Trends>() {
private static final long serialVersionUID = 4409084320158745041L;
@Override
protected ResponseList<Trends> createActualResponseList() throws TwitterException {
return TrendsJSONImpl.createTrendsList(res, conf.isJSONStoreEnabled());
}
};
}
@Override
public User createUser(HttpResponse res) throws TwitterException {
return new LazyUser(res, factory);
}
@Override
public ResponseList<User> createUserList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<User>() {
private static final long serialVersionUID = -2342604239975503212L;
@Override
protected ResponseList<User> createActualResponseList() throws TwitterException {
return UserJSONImpl.createUserList(res, conf);
}
};
}
@Override
public ResponseList<User> createUserListFromJSONArray(final HttpResponse res) throws TwitterException {
return new LazyPagableResponseList<User>() {
private static final long serialVersionUID = -4560012795625599671L;
@Override
protected ResponseList<User> createActualResponseList() throws TwitterException {
return UserJSONImpl.createUserList(res.asJSONArray(), res, conf);
}
};
}
@Override
public ResponseList<User> createUserListFromJSONArray_Users(final HttpResponse res) throws TwitterException {
return new LazyPagableResponseList<User>() {
private static final long serialVersionUID = 3138828209116873524L;
@Override
protected ResponseList<User> createActualResponseList() throws TwitterException {
try {
return UserJSONImpl.createUserList(res.asJSONObject().getJSONArray("users"), res, conf);
} catch (JSONException jsone) {
throw new TwitterException(jsone);
}
}
};
}
@Override
public QueryResult createQueryResult(HttpResponse res, Query query) throws TwitterException {
return new LazyQueryResult(res, factory, query);
}
@Override
public IDs createIDs(HttpResponse res) throws TwitterException {
return new LazyIDs(res, factory);
}
@Override
public PagableResponseList<User> createPagableUserList(final HttpResponse res) throws TwitterException {
return new LazyPagableResponseList<User>() {
private static final long serialVersionUID = 5621780922424425436L;
@Override
protected ResponseList<User> createActualResponseList() throws TwitterException {
return UserJSONImpl.createUserList(res, conf);
}
};
}
@Override
public UserList createAUserList(HttpResponse res) throws TwitterException {
return new LazyUserList(res, factory);
}
@Override
public PagableResponseList<UserList> createPagableUserListList(final HttpResponse res) throws TwitterException {
return new LazyPagableResponseList<UserList>() {
private static final long serialVersionUID = -1744513840306430678L;
@Override
protected PagableResponseList<UserList> createActualResponseList() throws TwitterException {
return UserListJSONImpl.createPagableUserListList(res, conf);
}
};
}
@Override
public ResponseList<UserList> createUserListList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<UserList>() {
private static final long serialVersionUID = -688537134684737190L;
@Override
protected ResponseList<UserList> createActualResponseList() throws TwitterException {
return UserListJSONImpl.createUserListList(res, conf);
}
};
}
@Override
public ResponseList<Category> createCategoryList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Category>() {
private static final long serialVersionUID = -499989158452701469L;
@Override
protected ResponseList<Category> createActualResponseList() throws TwitterException {
return CategoryJSONImpl.createCategoriesList(res, conf);
}
};
}
@Override
public DirectMessage createDirectMessage(HttpResponse res) throws TwitterException {
return new LazyDirectMessage(res, factory);
}
@Override
public DirectMessageList createDirectMessageList(final HttpResponse res) throws TwitterException {
throw new TwitterException("Not Implemented");
}
@Override
public Relationship createRelationship(HttpResponse res) throws TwitterException {
return new LazyRelationship(res, factory);
}
@Override
public ResponseList<Friendship> createFriendshipList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Friendship>() {
private static final long serialVersionUID = 2000670419499499826L;
@Override
protected ResponseList<Friendship> createActualResponseList() throws TwitterException {
return FriendshipJSONImpl.createFriendshipList(res, conf);
}
};
}
@Override
public AccountTotals createAccountTotals(HttpResponse res) throws TwitterException {
return new LazyAccountTotals(res, factory);
}
@Override
public AccountSettings createAccountSettings(HttpResponse res) throws TwitterException {
return new LazyAccountSettings(res, factory);
}
@Override
public SavedSearch createSavedSearch(HttpResponse res) throws TwitterException {
return new LazySavedSearch(res, factory);
}
@Override
public ResponseList<SavedSearch> createSavedSearchList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<SavedSearch>() {
private static final long serialVersionUID = 5885155689227833223L;
@Override
protected ResponseList<SavedSearch> createActualResponseList() throws TwitterException {
return SavedSearchJSONImpl.createSavedSearchList(res, conf);
}
};
}
@Override
public ResponseList<Location> createLocationList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Location>() {
private static final long serialVersionUID = -5502050661491788149L;
@Override
protected ResponseList<Location> createActualResponseList() throws TwitterException {
return LocationJSONImpl.createLocationList(res, conf);
}
};
}
@Override
public Place createPlace(HttpResponse res) throws TwitterException {
return new LazyPlace(res, factory);
}
@Override
public ResponseList<Place> createPlaceList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<Place>() {
private static final long serialVersionUID = 3477694658457823153L;
@Override
protected ResponseList<Place> createActualResponseList() throws TwitterException {
return PlaceJSONImpl.createPlaceList(res, conf);
}
};
}
@Override
public <T> ResponseList<T> createEmptyResponseList() {
return new ResponseListImpl<T>(0, null);
}
@Override
public OEmbed createOEmbed(HttpResponse res) throws TwitterException {
return new LazyOEmbed(res, factory);
}
@Override
public TwitterAPIConfiguration createTwitterAPIConfiguration(HttpResponse res) throws TwitterException {
return new LazyTwitterAPIConfiguration(res, factory);
}
@Override
public ResponseList<HelpResources.Language> createLanguageList(final HttpResponse res) throws TwitterException {
return new LazyResponseList<HelpResources.Language>() {
private static final long serialVersionUID = -7722971198897121377L;
@Override
protected ResponseList<HelpResources.Language> createActualResponseList() throws TwitterException {
return LanguageJSONImpl.createLanguageList(res, conf);
}
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof LazyJSONImplFactory)) return false;
LazyJSONImplFactory that = (LazyJSONImplFactory) o;
if (factory != null ? !factory.equals(that.factory) : that.factory != null)
return false;
return true;
}
@Override
public int hashCode() {
return factory != null ? factory.hashCode() : 0;
}
@Override
public String toString() {
return "LazyFactory{" +
"factory=" + factory +
'}';
}
}