/** * Get the optional object value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return An object value, or null if there is no object at that index. */ public Object opt(int index) { return (index < 0 || index >= length()) ? null : this.myArrayList.get(index); }
/** * Get the optional object value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return An object value, or null if there is no object at that index. */ public Object opt(int index) { return (index < 0 || index >= length()) ? null : this.myArrayList.get(index); }
/** * Make a string from the contents of this JSONArray. The * <code>separator</code> string is inserted between each element. Warning: * This method assumes that the data structure is acyclical. * * @param separator * A string that will be inserted between the elements. * @return a string. * @throws JSONException * If the array contains an invalid number. */ public String join(String separator) throws JSONException { int len = length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator); } sb.append(JSONObject.valueToString(this.myArrayList.get(i))); } return sb.toString(); }
/** * Make a string from the contents of this JSONArray. The * <code>separator</code> string is inserted between each element. Warning: * This method assumes that the data structure is acyclical. * * @param separator * A string that will be inserted between the elements. * @return a string. * @throws JSONException * If the array contains an invalid number. */ public String join(String separator) throws JSONException { int len = length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i += 1) { if (i > 0) { sb.append(separator); } sb.append(JSONObject.valueToString(this.myArrayList.get(i))); } return sb.toString(); }
for (int i = 0; i < ja.length(); i += 1) { if (i > 0) { sb.append(',');
private JSONObject getLatestClassificationObjectOnBranch(String branchPath) throws RestClientException { final String classificationsUrl = urlHelper.getClassificationsUrl(branchPath); try { final JSONArray items = getItems(classificationsUrl); if (items != null && items.length() > 0) { return items.getJSONObject(items.length() - 1); } return null; } catch (Exception e) { throw new RestClientException("Failed to retrieve list of classifications.", e); } }
/** * Produce a JSONObject by combining a JSONArray of names with the values of * this JSONArray. * * @param names * A JSONArray containing a list of key strings. These will be paired * with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException * If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }
/** * Produce a JSONObject by combining a JSONArray of names with the values of * this JSONArray. * * @param names * A JSONArray containing a list of key strings. These will be paired * with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @throws JSONException * If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }
/** * Produce a comma delimited text from a JSONArray of JSONObjects using * a provided list of names. The list of names is not included in the * output. * @param names A JSONArray of strings. * @param ja A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ public static String toString(JSONArray names, JSONArray ja) throws JSONException { if (names == null || names.length() == 0) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < ja.length(); i += 1) { JSONObject jo = ja.optJSONObject(i); if (jo != null) { sb.append(rowToString(jo.toJSONArray(names))); } } return sb.toString(); } }
/** * Produce a comma delimited text from a JSONArray of JSONObjects using * a provided list of names. The list of names is not included in the * output. * @param names A JSONArray of strings. * @param ja A JSONArray of JSONObjects. * @return A comma delimited text. * @throws JSONException */ public static String toString(JSONArray names, JSONArray ja) throws JSONException { if (names == null || names.length() == 0) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < ja.length(); i += 1) { JSONObject jo = ja.optJSONObject(i); if (jo != null) { sb.append(rowToString(jo.toJSONArray(names))); } } return sb.toString(); } }
public List<String> retrieveValidationStatuses(List<String> branchPaths) throws Exception { StringBuilder url = new StringBuilder(orchestrationUrl + VALIDATIONS_ENDPOINT + "/bulk/latest/statuses"); url.append("?paths="); boolean first = true; for (String branchPath : branchPaths) { if (!first) { url.append(","); } else { first = false; } url.append(branchPath); } final JSONResource resource = getResource(url.toString()); if (resource == null) { return null; } final JSONArray array = resource.array(); List<String> statuses = new ArrayList<>(); for (int a = 0; a < array.length(); a++) { final String string = array.getString(a); statuses.add(!string.equals("null") ? string : null); } return statuses; }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator<String> keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param x A JSONTokener of the source text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (;;) { JSONObject jo = rowToJSONObject(names, x); if (jo == null) { break; } ja.put(jo); } if (ja.length() == 0) { return null; } return ja; }
/** * Produce a JSONArray containing the names of the elements of this * JSONObject. * * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray names() { JSONArray ja = new JSONArray(); Iterator<String> keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
/** * Produce a JSONArray of JSONObjects from a comma delimited text string * using a supplied JSONArray as the source of element names. * @param names A JSONArray of strings. * @param x A JSONTokener of the source text. * @return A JSONArray of JSONObjects. * @throws JSONException */ public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (;;) { JSONObject jo = rowToJSONObject(names, x); if (jo == null) { break; } ja.put(jo); } if (ja.length() == 0) { return null; } return ja; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * * @param names * A JSONArray containing a list of key strings. This determines the * sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException * If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
/** * Produce a JSONArray containing the values of the members of this * JSONObject. * * @param names * A JSONArray containing a list of key strings. This determines the * sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException * If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
public List<Vehicle> queryVehicles() { List<Vehicle> list = new ArrayList<>(2); try { JSONResource r = api.json(apiEndpoint("vehicles")); JSONArray rawVehicleData = r.object().getJSONArray("response"); int numVehicles = rawVehicleData.length(); for (int i = 0; i < numVehicles; i++) { Vehicle vehicle = new Vehicle(this, rawVehicleData.getJSONObject(i)); list.add(vehicle); } } catch (IOException | JSONException ex) { logger.warning("Problem fetching vehicle list: " + ex); } return list; }
char c = x.next(); if (value == null || (ja.length() == 0 && value.length() == 0 && c != ',')) { return null;
@Override public List<IMetadata> search(String query, String authorityId) { ArrayList<IMetadata> ret = new ArrayList<IMetadata>(); try { JSONResource res = new Resty().json(getSearchURL(query)); JSONArray ares = res.array(); // JSONArray ares = (JSONArray) res.get("results"); for (int i = 0; i < ares.length(); i++) { JSONObject ores = (JSONObject) ares.get(i); if (ores != null) { Object rank = ores.get("rank"); if (!rankOK(rank)) continue; Metadata md = new Metadata(); md.put("ID", ores.get("speciesKey")); md.put("Label", ores.get("canonicalName")); ret.add(md); } } } catch (Exception e) { } return ret; }