@Override public int getGroupCount() { return(model.length()); }
/** * @return the column size of this GfJsonObject */ public int size() { return jsonObject.length(); }
/** * Create a JSON object that represents this data structure. * @return a JSON serialization of this data structure. */ public JSONObject jsonSerialize() { JSONObject jsonObject = new JSONObject(); jsonObject.put(ID_KEY, mId); jsonObject.put(URL_KEY, mUrl); if (mExtraData.length() > 0) { jsonObject.put(EXTRA_KEY, mExtraData); } return jsonObject; }
/** * Get an array of field names from a JSONObject. * * @return An array of field names, or null if there are no names. */ public static String[] getNames(JSONObject jo) { int length = jo.length(); if (length == 0) { return null; } Iterator<String> iterator = jo.keys(); String[] names = new String[length]; int i = 0; while (iterator.hasNext()) { names[i] = iterator.next(); i += 1; } return names; }
@NonNull public Map<String, Object> toMap() { final Map<String, Object> map = new HashMap<>(content.length()); for (final Iterator<String> iterator = content.keys(); iterator.hasNext(); ) { final String key = iterator.next(); map.put(key, get(key)); } return map; } }
/** * Create a JSON object that represents this data structure. * @return a JSON serialization of this data structure. */ public JSONObject jsonSerialize() { JSONObject jsonObject = new JSONObject(); jsonObject.put(REQUESTURL_KEY, mRequestUrl); jsonObject.put(SITEURL_KEY, mSiteUrl); if (mTitle != null) { jsonObject.put(TITLE_KEY, mTitle); } if (mDescription != null) { jsonObject.put(DESCRIPTION_KEY, mDescription); } if (mIconUrl != null) { jsonObject.put(ICONURL_KEY, mIconUrl); } if (mGroupId != null) { jsonObject.put(GROUPID_KEY, mGroupId); } if (mExtraData.length() > 0) { jsonObject.put(EXTRA_KEY, mExtraData); } return jsonObject; }
/** * Get an array of field names from a JSONObject. * * @return An array of field names, or null if there are no names. */ public static String[] getNames(JSONObject jo) { int length = jo.length(); if (length == 0) { return null; } return jo.keySet().toArray(new String[length]); }
@Override public List<String> getURLsFromPage(Document doc) { List<String> result = new ArrayList<>(); for (Element script : doc.select("script")) { if (script.data().contains("var images = ")) { String s = script.data(); s = s.replaceAll("var seriesId = \\d+;", ""); s = s.replaceAll("var chapterId = \\d+;", ""); s = s.replaceAll("var pages = \\d+;", ""); s = s.replaceAll("var page = \\d+;", ""); s = s.replaceAll("var prevCha = null;", ""); s = s.replaceAll("var nextCha = \\.*;", ""); String json = s.replaceAll("var images = ", "").replaceAll(";", ""); JSONObject images = new JSONObject(json); for (int i = 1; i < images.length() +1; i++) { result.add(images.getString(Integer.toString(i))); } } } return result; }
@Override public int length(Object obj) { if (isArray(obj)) { return toJsonArray(obj).length(); } else if (isMap(obj)) { return toJsonObject(obj).length(); } else { if (obj instanceof String) { return ((String) obj).length(); } } throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null"); }
/** * cleanup deletes all old entries and frees up the memory. * some outside process muss call this frequently * @return self */ public Accounting cleanup() { if (!this.has("requests")) return this; JSONObject requests = this.getJSONObject("requests"); for (String path: requests.keySet()) { JSONObject events = requests.getJSONObject(path); // shrink that map and delete everything which is older than now minus one hour long pivotTime = System.currentTimeMillis() - ONE_HOUR_MILLIS; while (events.length() > 0 && Long.parseLong(events.keys().next()) < pivotTime) events.remove(events.keys().next()); if (events.length() == 0) requests.remove(path); } return this; }
public void extractStagesAndPlans(JSONObject inputObject) throws Exception { // extract stages JSONObject dependency = inputObject.getJSONObject("STAGE DEPENDENCIES"); if (dependency != null && dependency.length() > 0) { // iterate for the first time to get all the names of stages. for (String stageName : JSONObject.getNames(dependency)) { this.stages.put(stageName, new Stage(stageName, this)); } // iterate for the second time to get all the dependency. for (String stageName : JSONObject.getNames(dependency)) { JSONObject dependentStageNames = dependency.getJSONObject(stageName); this.stages.get(stageName).addDependency(dependentStageNames, this.stages); } } // extract stage plans JSONObject stagePlans = inputObject.getJSONObject("STAGE PLANS"); if (stagePlans != null && stagePlans.length() > 0) { for (String stageName : JSONObject.getNames(stagePlans)) { JSONObject stagePlan = stagePlans.getJSONObject(stageName); this.stages.get(stageName).extractVertex(stagePlan); } } }
if (data.length() > 0) { newJsonObject.put("data", data);
Map<String, String> attrs = new TreeMap<>(); Vertex v = null; if (opObj.length() > 0) { String[] names = JSONObject.getNames(opObj); for (String name : names) { } else if (o instanceof JSONObject) { JSONObject attrObj = (JSONObject) o; if (attrObj.length() > 0) { if (name.equals("Processor Tree:")) { JSONObject object = new JSONObject(new LinkedHashMap<>());
@Test public void testJsonObjectPutAll() throws JSONException { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("hello", "world"); map.put("hocus", "pocus"); JSONObject jsonObject = new JSONObject(); JsonUtil.jsonObjectPutAll(jsonObject, map); assertEquals("pocus", jsonObject.get("hocus")); assertEquals(2, jsonObject.length()); }
@Test public void testJsonObjectClear() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put("hello", "world"); jsonObject.put("hocus", "pocus"); JsonUtil.jsonObjectClear(jsonObject); assertEquals(0, jsonObject.length()); }
@Override public JSONObject[] service(Query call, Authorization rights) throws APIException { // make call to the embedded api if (this.serverProtocolHostStub == null) return new JSONObject[]{serviceImpl(call, null, rights, rights.getPermissions(this))}; // make call(s) to a remote api(s) JSONObject[] results = new JSONObject[this.serverProtocolHostStub.length]; for (int rc = 0; rc < results.length; rc++) { try { StringBuilder urlquery = new StringBuilder(); for (String key: call.getKeys()) { urlquery.append(urlquery.length() == 0 ? '?' : '&').append(key).append('=').append(call.get(key, "")); } String urlstring = this.serverProtocolHostStub[rc] + this.getAPIPath() + urlquery.toString(); byte[] jsonb = ClientConnection.download(urlstring); if (jsonb == null || jsonb.length == 0) throw new IOException("empty content from " + urlstring); String jsons = UTF8.String(jsonb); JSONObject json = new JSONObject(jsons); if (json == null || json.length() == 0) { results[rc] = null; continue; }; results[rc] = json; } catch (Throwable e) { DAO.severe(e); } } return results; }
@Override public void onRemoveSearch(String searchName) { Timber.d("OnRemoveSelection using search named: %s", searchName); try { JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters"); if (savedFiltersObj != null && savedFiltersObj.has(searchName)) { savedFiltersObj.remove(searchName); getCol().getConf().put("savedFilters", savedFiltersObj); getCol().flush(); if (savedFiltersObj.length() == 0) { mMySearchesItem.setVisible(false); } } } catch (JSONException e) { throw new RuntimeException(e); } }
@Override public boolean matches(Object item) { if(!String.class.isInstance(item)){ return false; } if(this.expected == null && "null".equals(item)){ return true; } JSONObject actual = null; try { actual = new JSONObject(new JSONTokener(item.toString())); } catch (JSONException e) { return false; } if(this.expected.length() != actual.length()) { return false; } JSONArray names = actual.names(); for(int i = 0, len = names.length(); i < len; i++){ try { String name = names.getString(i); if(!Objects.equals(expected.get(name), actual.get(name))){ return false; } } catch (JSONException e) { return false; } } return true; }
plan.getOptimizedQueryString()); if (jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES) != null && jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES).length() <= conf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_MAX_GRAPH_SIZE)) { ret = jsonPlan.toString();
public static JSONObject getUser(String screen_name, boolean forceReload) throws TwitterException, IOException { if (!forceReload) { JsonFactory mapcapsule = DAO.user_dump.get("screen_name",screen_name); if (mapcapsule == null) mapcapsule = DAO.user_dump.get("id_str", screen_name); if (mapcapsule != null) { JSONObject json = mapcapsule.getJSON(); if (json.length() > 0) { // check if the entry is maybe outdated, i.e. if it is empty or too old try { Date d = DAO.user_dump.parseDate(json); if (d.getTime() + DateParser.DAY_MILLIS > System.currentTimeMillis()) return json; } catch (ParseException e) { return json; } } } } TwitterFactory tf = getUserTwitterFactory(screen_name); if (tf == null) tf = getAppTwitterFactory(); if (tf == null) return new JSONObject(); Twitter twitter = tf.getInstance(); User user = twitter.showUser(screen_name); RateLimitStatus rateLimitStatus = user.getRateLimitStatus(); getUserResetTime = System.currentTimeMillis() + rateLimitStatus.getSecondsUntilReset() * 1000; getUserRemaining = rateLimitStatus.getRemaining(); JSONObject json = user2json(user); enrichLocation(json); DAO.user_dump.putUnique(json); return json; }