/** * Append a float value. This increases the array's length by one. * This will store the value as a double, since there are no floats in JSON. * * @param value a float value * @throws RuntimeException if the value is not finite. * @return this. */ public JSONArray append(float value) { return append((double) value); }
/** * Append an String value. This increases the array's length by one. * * @webref jsonarray:method * @brief Appends a value, increasing the array's length by one * @param value a String value * @return this. * @see JSONArray#size() * @see JSONArray#remove(int) */ public JSONArray append(String value) { this.append((Object)value); return this; }
/** * Append a boolean value. This increases the array's length by one. * * @param value a boolean value * @return this. */ public JSONArray append(boolean value) { this.append(value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Append a float value. This increases the array's length by one. * This will store the value as a double, since there are no floats in JSON. * * @param value a float value * @throws JSONException if the value is not finite. * @return this. */ public JSONArray append(float value) { return append((double) value); }
/** * Append a boolean value. This increases the array's length by one. * * @param value a boolean value * @return this. */ public JSONArray append(boolean value) { this.append(value ? Boolean.TRUE : Boolean.FALSE); return this; }
/** * Append an String value. This increases the array's length by one. * * @webref jsonarray:method * @brief Appends a value, increasing the array's length by one * @param value a String value * @return this. * @see JSONArray#size() * @see JSONArray#remove(int) */ public JSONArray append(String value) { this.append((Object)value); return this; }
/** * Append an long value. This increases the array's length by one. * * @nowebref * @param value A long value. * @return this. */ public JSONArray append(long value) { this.append(Long.valueOf(value)); return this; }
/** * Append an long value. This increases the array's length by one. * * @nowebref * @param value A long value. * @return this. */ public JSONArray append(long value) { this.append(new Long(value)); return this; }
/** * Append an int value. This increases the array's length by one. * * @param value an int value * @return this. */ public JSONArray append(int value) { this.append(Integer.valueOf(value)); return this; }
/** * Append an int value. This increases the array's length by one. * * @param value an int value * @return this. */ public JSONArray append(int value) { this.append(new Integer(value)); return this; }
/** * Construct a JSONArray from an array * @throws RuntimeException If not an array. */ protected JSONArray(Object array) { this(); if (array.getClass().isArray()) { int length = Array.getLength(array); for (int i = 0; i < length; i += 1) { this.append(JSONObject.wrap(Array.get(array, i))); } } else { throw new RuntimeException("JSONArray initial value should be a string or collection or array."); } }
/** * Construct a JSONArray from an array * @throws JSONException If not an array. */ protected JSONArray(Object array) { this(); if (array.getClass().isArray()) { int length = Array.getLength(array); for (int i = 0; i < length; i += 1) { this.append(JSONObject.wrap(Array.get(array, i))); } } else { throw new RuntimeException("JSONArray initial value should be a string or collection or array."); } }
/** * Append a double value. This increases the array's length by one. * * @nowebref * @param value A double value. * @throws RuntimeException if the value is not finite. * @return this. */ public JSONArray append(double value) { Double d = value; JSONObject.testValidity(d); this.append(d); return this; }
/** * Append a double value. This increases the array's length by one. * * @nowebref * @param value A double value. * @throws JSONException if the value is not finite. * @return this. */ public JSONArray append(double value) { Double d = new Double(value); JSONObject.testValidity(d); this.append(d); return this; }
/** * Put or replace an object value in the JSONArray. If the index is greater * than the length of the JSONArray, then null elements will be added as * necessary to pad it out. * @param index The subscript. * @param value The value to put into the array. The value should be a * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the * JSONObject.NULL object. * @return this. * @throws JSONException If the index is negative or if the the value is * an invalid number. */ private JSONArray set(int index, Object value) { JSONObject.testValidity(value); if (index < 0) { throw new RuntimeException("JSONArray[" + index + "] not found."); } if (index < this.size()) { this.myArrayList.set(index, value); } else { while (index != this.size()) { this.append(JSONObject.NULL); } this.append(value); } return this; }
/** * Put or replace an object value in the JSONArray. If the index is greater * than the length of the JSONArray, then null elements will be added as * necessary to pad it out. * @param index The subscript. * @param value The value to put into the array. The value should be a * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the * JSONObject.NULL object. * @return this. * @throws RuntimeException If the index is negative or if the the value is * an invalid number. */ private JSONArray set(int index, Object value) { JSONObject.testValidity(value); if (index < 0) { throw new RuntimeException("JSONArray[" + index + "] not found."); } if (index < this.size()) { this.myArrayList.set(index, value); } else { while (index != this.size()) { this.append(JSONObject.NULL); } this.append(value); } return this; }