/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, boolean value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, int value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, long value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same * name. * * @param name The name of the value to insert. * @param value The value to insert. * @return this object. * @throws JSONException Should not be possible. */ public JSONObject put(String name, boolean value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same * name. * * @param name The name for the new value. * @param value The new value. * @return this object. * @throws JSONException Should not be possible. */ public JSONObject put(String name, int value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same * name. * * @param name The name of the new value. * @param value The new value to insert. * @return this object. * @throws JSONException Should not be possible. */ public JSONObject put(String name, long value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @param value a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this object. */ public JSONObject put(String name, double value) throws JSONException { nameValuePairs.put(checkName(name), JSON.checkDouble(value)); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same * name. * * @param name The name for the new value. * @param value a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this object. * @throws JSONException if value is NaN or infinite. */ public JSONObject put(String name, double value) throws JSONException { nameValuePairs.put(checkName(name), JSON.checkDouble(value)); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. If the value is {@code null}, any existing * mapping for {@code name} is removed. * * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, * Integer, Long, Double, {@link #NULL}, or {@code null}. May not be * {@link Double#isNaN() NaNs} or {@link Double#isInfinite() * infinities}. * @return this object. */ public JSONObject put(String name, Object value) throws JSONException { if (value == null) { nameValuePairs.remove(name); return this; } if (value instanceof Number) { // deviate from the original by checking all Numbers, not just floats & doubles JSON.checkDouble(((Number) value).doubleValue()); } nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value mapping with the same * name. If the value is {@code null}, any existing mapping for {@code name} is removed. * * @param name The name of the new value. * @param value a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double, * {@link #NULL}, or {@code null}. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this object. * @throws JSONException if the value is an invalid double (infinite or NaN). */ public JSONObject put(String name, Object value) throws JSONException { if (value == null) { nameValuePairs.remove(name); return this; } if (value instanceof Number) { // deviate from the original by checking all Numbers, not just floats & doubles JSON.checkDouble(((Number) value).doubleValue()); } nameValuePairs.put(checkName(name), value); return this; }
Object current = nameValuePairs.get(checkName(name)); if (current == null) { return put(name, value);
/** * Appends values to the array mapped to {@code name}. A new {@link JSONArray} mapping for * {@code name} will be inserted if no mapping exists. If the existing mapping for {@code name} is * not a {@link JSONArray}, a {@link JSONException} will be thrown. * * @param name The name of the array to which the value should be appended. * @param value The value to append. * @return this object. * @throws JSONException if {@code name} is {@code null} or if the mapping for {@code name} is * non-null and is not a {@link JSONArray}. */ public JSONObject append(String name, Object value) throws JSONException { Object current = nameValuePairs.get(checkName(name)); final JSONArray array; if (current instanceof JSONArray) { array = (JSONArray) current; } else if (current == null) { JSONArray newArray = new JSONArray(); nameValuePairs.put(name, newArray); array = newArray; } else { throw new JSONException("Key " + name + " is not a JSONArray"); } array.checkedPut(value); return this; }
Object current = nameValuePairs.get(checkName(name)); if (current == null) { return put(name, value);
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, long value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, int value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, boolean value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, long value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, boolean value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @return this object. */ public JSONObject put(String name, int value) throws JSONException { nameValuePairs.put(checkName(name), value); return this; }
/** * Maps {@code name} to {@code value}, clobbering any existing name/value * mapping with the same name. * * @param value a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. * @return this object. */ public JSONObject put(String name, double value) throws JSONException { nameValuePairs.put(checkName(name), JSON.checkDouble(value)); return this; }