/** * Creates a new empty JsonArray. This is equivalent to creating a new JsonArray using the constructor. * * @return a new empty JSON array */ public static JsonArray array() { return new JsonArray(); }
@Override public JsonArray startArray() { return new JsonArray(); }
/** * Returns an unmodifiable wrapper for the specified JsonArray. This method allows to provide read-only access to a * JsonArray. * <p> * The returned JsonArray is backed by the given array and reflects subsequent changes. Attempts to modify the * returned JsonArray result in an <code>UnsupportedOperationException</code>. * </p> * * @param array * the JsonArray for which an unmodifiable JsonArray is to be returned * @return an unmodifiable view of the specified JsonArray */ public static JsonArray unmodifiableArray(JsonArray array) { return new JsonArray(array, true); }
/** * Put a value in the JsonArray, where the value will be a JsonArray which is * produced from a Collection. * * @param value A Collection value. * @return this. */ public JsonArray put(Collection<?> value) { put(new JsonArray(value)); return this; }
/** * Put a key/value pair in the JsonObject, where the value will be a JsonArray * which is produced from a Collection. * * @param key A key string. * @param value A Collection value. * @return this. * @throws com.restfb.json.JsonException */ public JsonObject put(String key, Collection<?> value) throws JsonException { put(key, new JsonArray(value)); return this; }
/** * Put a value in the JsonArray, where the value will be a JsonArray which is * produced from a Collection. * * @param index The subscript. * @param value A Collection value. * @return this. * @throws JsonException If the index is negative or if the value is not finite. */ public JsonArray put(int index, Collection<?> value) throws JsonException { put(index, new JsonArray(value)); return this; }
/** * Creates a new JsonArray that contains the JSON representations of the given <code>boolean</code> values. * * @param values * the values to be included in the new JSON array * @return a new JSON array that contains the given values */ public static JsonArray array(boolean... values) { if (values == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (boolean value : values) { array.add(value); } return array; }
/** * Creates a new JsonArray that contains the JSON representations of the given <code>double</code> values. * * @param values * the values to be included in the new JSON array * @return a new JSON array that contains the given values */ public static JsonArray array(double... values) { if (values == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (double value : values) { array.add(value); } return array; }
/** * Creates a new JsonArray that contains the JSON representations of the given <code>int</code> values. * * @param values * the values to be included in the new JSON array * @return a new JSON array that contains the given values */ public static JsonArray array(int... values) { if (values == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (int value : values) { array.add(value); } return array; }
/** * Creates a new JsonArray that contains the JSON representations of the given <code>float</code> values. * * @param values * the values to be included in the new JSON array * @return a new JSON array that contains the given values */ public static JsonArray array(float... values) { if (values == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (float value : values) { array.add(value); } return array; }
/** * Creates a new JsonArray that contains the JSON representations of the given <code>long</code> values. * * @param values * the values to be included in the new JSON array * @return a new JSON array that contains the given values */ public static JsonArray array(long... values) { if (values == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (long value : values) { array.add(value); } return array; }
/** * Creates a new JsonArray that contains the JSON representations of the given strings. * * @param strings * the strings to be included in the new JSON array * @return a new JSON array that contains the given strings */ public static JsonArray array(String... strings) { if (strings == null) { throw new NullPointerException(VALUES_IS_NULL); } JsonArray array = new JsonArray(); for (String value : strings) { array.add(value); } return array; }
/** * 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<?> keys = keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
JsonArray idArray = new JsonArray();
case '(': back(); return new JsonArray(this);
/** * Accumulate values under a key. It is similar to the put method except that * if there is already an object stored under the key then a JsonArray is * stored under the key to hold all of the accumulated values. If there is * already a JsonArray, then the new value is appended to it. In contrast, the * put method replaces the previous value. * * @param key A key string. * @param value An object to be accumulated under the key. * @return this. * @throws com.restfb.json.JsonException If the value is an invalid number or if the key is null. */ public JsonObject accumulate(String key, Object value) throws JsonException { testValidity(value); Object o = opt(key); if (o == null) { put(key, value instanceof JsonArray ? new JsonArray().put(value) : value); } else if (o instanceof JsonArray) { ((JsonArray) o).put(value); } else { put(key, new JsonArray().put(o).put(value)); } return this; }
/** * 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 com.restfb.json.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; }
/** * Append values to the array under a key. If the key does not exist in the * JsonObject, then the key is put in the JsonObject with its value being a * JsonArray containing the value parameter. If the key was already associated * with a JsonArray, then the value parameter is appended to it. * * @param key A key string. * @param value An object to be accumulated under the key. * @return this. * @throws com.restfb.json.JsonException If the key is null or if the current value associated with the * key is not a JsonArray. */ public JsonObject append(String key, Object value) throws JsonException { testValidity(value); Object o = opt(key); if (o == null) { put(key, new JsonArray().put(value)); } else if (o instanceof JsonArray) { put(key, ((JsonArray) o).put(value)); } else { throw new JsonException("JsonObject[" + key + "] is not a JsonArray."); } return this; }