/** * Get the optional int value associated with an index. Zero is returned if * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * * @param index * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
/** * Returns the value at {@code index} if it exists and is an int or * can be coerced to an int. Returns 0 otherwise. */ public int optInt(int index) { return optInt(index, 0); }
/** * Returns the value at {@code index} if it exists and is an int or can be coerced to an int. * Returns 0 otherwise. * * @param index Which value to get. * @return the value at the specified location. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. Zero is returned if * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * * @param index * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
private static Map<Integer, Set<Integer>> parseJSONDefinition(JSONObject definition) { JSONArray itemsArray = definition.optJSONArray("items"); if (itemsArray.length() == 0) { return null; } Map<Integer, Set<Integer>> items = new HashMap<>(); for (int i = 0; i < itemsArray.length(); i++) { JSONObject item = itemsArray.optJSONObject(i); if (item == null) { continue; } int code = item.optInt("code"); if (code == 0) { continue; } Set<Integer> subcodes = null; JSONArray subcodesArray = item.optJSONArray("subcodes"); if (subcodesArray != null && subcodesArray.length() > 0) { subcodes = new HashSet<>(); for (int j = 0; j < subcodesArray.length(); j++) { int subCode = subcodesArray.optInt(j); if (subCode != 0) { subcodes.add(subCode); } } } items.put(code, subcodes); } return items; }
private static int[] parseVersionSpec(JSONArray versionsJSON) { // Null signifies no overrides to the min-version as specified by the SDK. // An empty array would basically turn off the dialog (i.e no supported versions), so // DON'T default to that. int[] versionSpec = null; if (versionsJSON != null) { int numVersions = versionsJSON.length(); versionSpec = new int[numVersions]; for (int i = 0; i < numVersions; i++) { // See if the version was stored directly as an Integer int version = versionsJSON.optInt(i, NativeProtocol.NO_PROTOCOL_AVAILABLE); if (version == NativeProtocol.NO_PROTOCOL_AVAILABLE) { // If not, then see if it was stored as a string that can be parsed out. // If even that fails, then we will leave it as NO_PROTOCOL_AVAILABLE String versionString = versionsJSON.optString(i); if (!Utility.isNullOrEmpty(versionString)) { try { version = Integer.parseInt(versionString); } catch (NumberFormatException nfe) { Utility.logd(Utility.LOG_TAG, nfe); version = NativeProtocol.NO_PROTOCOL_AVAILABLE; } } } versionSpec[i] = version; } } return versionSpec; }
/** * Get the optional int value associated with an index. Zero is returned if * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * * @param index * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
/** * Returns the value at {@code index} if it exists and is an int or * can be coerced to an int. Returns 0 otherwise. */ public int optInt(int index) { return optInt(index, 0); }
/** * Returns the value at {@code index} if it exists and is an int or * can be coerced to an int. Returns 0 otherwise. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. Zero is returned if * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * * @param index * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Returns the value at {@code index} if it exists and is an int or * can be coerced to an int. Returns 0 otherwise. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, * or if the value is not a number and cannot be converted to a number. * * @param index The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return optInt(index, 0); }
/** * Get the optional int value associated with an index. Zero is returned if * there is no value for the index, or if the value is not a number and * cannot be converted to a number. * * @param index * The index must be between 0 and length() - 1. * @return The value. */ public int optInt(int index) { return this.optInt(index, 0); }
private static Set<Integer> getIntSet(JSONObject obj, String field, int defaultVal) { HashSet<Integer> intSet = null; JSONArray array = obj.optJSONArray(field); if (array != null) { int count = array.length(); intSet = new HashSet<Integer>(count); for (int i = 0; i < count; ++i) { intSet.add(array.optInt(i, defaultVal)); } } return intSet; }