/*package*/ static ResponseList<UserList> createUserListList(HttpResponse res, Configuration conf) throws TwitterException { try { if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } JSONArray list = res.asJSONArray(); int size = list.length(); ResponseList<UserList> users = new ResponseListImpl<UserList>(size, res); for (int i = 0; i < size; i++) { JSONObject userListJson = list.getJSONObject(i); UserList userList = new UserListJSONImpl(userListJson); users.add(userList); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(userList, userListJson); } } if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(users, list); } return users; } catch (JSONException jsone) { throw new TwitterException(jsone); } }
/*package*/ static ResponseList<Relationship> createRelationshipList(HttpResponse res, Configuration conf) throws TwitterException { try { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } JSONArray list = res.asJSONArray(); int size = list.length(); ResponseList<Relationship> relationships = new ResponseListImpl<Relationship>(size, res); for (int i = 0; i < size; i++) { JSONObject json = list.getJSONObject(i); Relationship relationship = new RelationshipJSONImpl(json); if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(relationship, json); } relationships.add(relationship); } if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(relationships, list); } return relationships; } catch (JSONException jsone) { throw new TwitterException(jsone); } catch (TwitterException te) { throw te; } }
/*package*/ static ResponseList<Location> createLocationList(HttpResponse res, Configuration conf) throws TwitterException { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } return createLocationList(res.asJSONArray(), conf.isJSONStoreEnabled()); }
/*package*/ UserListJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { super(res); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } JSONObject json = res.asJSONObject(); init(json); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(this, json); } }
SavedSearchJSONImpl(HttpResponse httpresponse, Configuration configuration) throws TwitterException { super(httpresponse); if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } httpresponse = httpresponse.asJSONObject(); init(httpresponse); if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(this, httpresponse); } }
/*package*/ RelationshipJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { this(res, res.asJSONObject()); if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); DataObjectFactoryUtil.registerJSONObject(this, res.asJSONObject()); } }
public void testEmptyJSON() throws Exception { HttpClientImpl http = new HttpClientImpl(); // empty User list List<User> users = UserJSONImpl.createUserList( http.get("http://twitter4j.org/en/testcases/statuses/friends/T4J_hudson.json"), conf); Assert.assertTrue(users.size() == 0); assertDeserializedFormIsEqual(users); // empty Status list List<Status> statuses = StatusJSONImpl.createStatusList( http.get("http://twitter4j.org/en/testcases/statuses/friends/T4J_hudson.json"), conf); Assert.assertTrue(statuses.size() == 0); assertDeserializedFormIsEqual(statuses); // empty DirectMessages list List<DirectMessage> directMessages = DirectMessageJSONImpl.createDirectMessageList( http.get("http://twitter4j.org/en/testcases/statuses/friends/T4J_hudson.json"), conf); Assert.assertTrue(directMessages.size() == 0); assertDeserializedFormIsEqual(directMessages); // empty Trends list List<Trends> trends = TrendsJSONImpl.createTrendsList( http.get("http://twitter4j.org/en/testcases/trends/daily-empty.json"), conf.isJSONStoreEnabled()); Assert.assertTrue(trends.size() == 0); assertDeserializedFormIsEqual(trends); }
static ResponseList createDirectMessageList(HttpResponse httpresponse, Configuration configuration) { int i; JSONArray jsonarray; JSONObject jsonobject; DirectMessageJSONImpl directmessagejsonimpl; int j; try { if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } jsonarray = httpresponse.asJSONArray(); j = jsonarray.length(); httpresponse = new ResponseListImpl(j, httpresponse); } // Misplaced declaration of an exception variable catch (HttpResponse httpresponse) { throw new TwitterException(httpresponse); } i = 0; _L2: if (i >= j) { break MISSING_BLOCK_LABEL_89; } jsonobject = jsonarray.getJSONObject(i); directmessagejsonimpl = new DirectMessageJSONImpl(jsonobject); httpresponse.add(directmessagejsonimpl); if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(directmessagejsonimpl, jsonobject); } break MISSING_BLOCK_LABEL_116; if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(httpresponse, jsonarray); } return httpresponse; i++; if (true) goto _L2; else goto _L1
DirectMessageJSONImpl(HttpResponse httpresponse, Configuration configuration) { super(httpresponse); httpresponse = httpresponse.asJSONObject(); init(httpresponse); if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, httpresponse); } }
static ResponseList createSavedSearchList(HttpResponse httpresponse, Configuration configuration) throws TwitterException { int i; if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } JSONArray jsonarray = httpresponse.asJSONArray(); ResponseListImpl responselistimpl; JSONObject jsonobject; SavedSearchJSONImpl savedsearchjsonimpl; try { responselistimpl = new ResponseListImpl(jsonarray.length(), httpresponse); } // Misplaced declaration of an exception variable catch (Configuration configuration) { throw new TwitterException((new StringBuilder()).append(configuration.getMessage()).append(":").append(httpresponse.asString()).toString(), configuration); } i = 0; _L2: if (i < jsonarray.length()) { jsonobject = jsonarray.getJSONObject(i); savedsearchjsonimpl = new SavedSearchJSONImpl(jsonobject); responselistimpl.add(savedsearchjsonimpl); if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(savedsearchjsonimpl, jsonobject); } break MISSING_BLOCK_LABEL_146; } if (configuration.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(responselistimpl, jsonarray); } return responselistimpl; i++; if (true) goto _L2; else goto _L1
public void testLocation() throws Exception { JSONArray array = getJSONArrayFromClassPath("/dao/trends-available.json"); ResponseList<Location> locations = LocationJSONImpl.createLocationList(array, conf.isJSONStoreEnabled()); Assert.assertEquals(23, locations.size()); Location location = locations.get(0); Assert.assertEquals("GB", location.getCountryCode()); Assert.assertEquals("United Kingdom", location.getCountryName()); Assert.assertEquals("United Kingdom", location.getName()); Assert.assertEquals(12, location.getPlaceCode()); Assert.assertEquals("Country", location.getPlaceName()); Assert.assertEquals("http://where.yahooapis.com/v1/place/23424975", location.getURL()); Assert.assertEquals(23424975, location.getWoeid()); }