diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index f615d23de..dc1ba1915 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -71,7 +71,7 @@ of this software and associated documentation files (the "Software"), to deal * myString = new JSONObject() * .put("JSON", "Hello, World!").toString(); * - *
+ *
* produces the string {"JSON": "Hello, World"}
.
*
* The texts produced by the
*
- * @param bean An object that has getter methods that should be used to make
- * a JSONObject.
+ * @param bean
+ * An object that has getter methods that should be used to make
+ * a JSONObject.
*/
public JSONObject(Object bean) {
this();
@@ -359,12 +366,14 @@ public JSONObject(Object bean) {
* those keys in the object. If a key is not found or not visible, then it
* will not be copied into the new JSONObject.
*
- * @param object An object that has fields that should be used to make a
- * JSONObject.
- * @param names An array of strings, the names of the fields to be obtained
- * from the object.
+ * @param object
+ * An object that has fields that should be used to make a
+ * JSONObject.
+ * @param names
+ * An array of strings, the names of the fields to be obtained
+ * from the object.
*/
- public JSONObject(Object object, String... names) {
+ public JSONObject(Object object, String ... names) {
this(names.length);
Class> c = object.getClass();
for (int i = 0; i < names.length; i += 1) {
@@ -380,11 +389,13 @@ public JSONObject(Object object, String... names) {
* Construct a JSONObject from a source JSON text string. This is the most
* commonly used JSONObject constructor.
*
- * @param source A string beginning with
+ *
* If only one value is accumulated that is not a JSONArray, then the result
* will be the same as using put. But if multiple values are accumulated,
* then the result will be like append.
*
- * @param key A key string.
- * @param value An object to be accumulated under the key.
+ * @param key
+ * A key string.
+ * @param value
+ * An object to be accumulated under the key.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is
+ *
* Use with caution.
*
- * @return An Entry Set
* @see Map#entrySet()
+ *
+ * @return An Entry Set
*/
protected Set
+ *
* If either of the numbers are Double or Float instances, then they are checked to have
* a finite value. If either value is not finite (NaN or ±infinity), then this
* function will always return false. If both numbers are finite, they are first checked
@@ -1999,10 +2142,10 @@ static boolean isNumberSimilar(Number l, Number r) {
// if the classes are the same and implement Comparable
// then use the built in compare first.
- if (l.getClass().equals(r.getClass()) && l instanceof Comparable) {
- @SuppressWarnings({"rawtypes", "unchecked"})
- int compareTo = ((Comparable) l).compareTo(r);
- return compareTo == 0;
+ if(l.getClass().equals(r.getClass()) && l instanceof Comparable) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ int compareTo = ((Comparable)l).compareTo(r);
+ return compareTo==0;
}
// BigDecimal should be able to handle all of our number types that we support through
@@ -2044,7 +2187,7 @@ protected static boolean isDecimalNotation(final String val) {
* @param val value to convert
* @return Number representation of the value.
* @throws NumberFormatException thrown if the value is not a valid number. A public
- * caller should catch this and wrap it in a {@link JSONException} if applicable.
+ * caller should catch this and wrap it in a {@link JSONException} if applicable.
*/
protected static Number stringToNumber(final String val) throws NumberFormatException {
char initial = val.charAt(0);
@@ -2056,7 +2199,7 @@ protected static Number stringToNumber(final String val) throws NumberFormatExce
// keep that by forcing a decimal.
try {
BigDecimal bd = new BigDecimal(val);
- if (initial == '-' && BigDecimal.ZERO.compareTo(bd) == 0) {
+ if(initial == '-' && BigDecimal.ZERO.compareTo(bd)==0) {
return Double.valueOf(-0.0);
}
return bd;
@@ -2064,26 +2207,26 @@ protected static Number stringToNumber(final String val) throws NumberFormatExce
// this is to support "Hex Floats" like this: 0x1.0P-1074
try {
Double d = Double.valueOf(val);
- if (d.isNaN() || d.isInfinite()) {
- throw new NumberFormatException("val [" + val + "] is not a valid number.");
+ if(d.isNaN() || d.isInfinite()) {
+ throw new NumberFormatException("val ["+val+"] is not a valid number.");
}
return d;
} catch (NumberFormatException ignore) {
- throw new NumberFormatException("val [" + val + "] is not a valid number.");
+ throw new NumberFormatException("val ["+val+"] is not a valid number.");
}
}
}
// block items like 00 01 etc. Java number parsers treat these as Octal.
- if (initial == '0' && val.length() > 1) {
+ if(initial == '0' && val.length() > 1) {
char at1 = val.charAt(1);
- if (at1 >= '0' && at1 <= '9') {
- throw new NumberFormatException("val [" + val + "] is not a valid number.");
+ if(at1 >= '0' && at1 <= '9') {
+ throw new NumberFormatException("val ["+val+"] is not a valid number.");
}
} else if (initial == '-' && val.length() > 2) {
char at1 = val.charAt(1);
char at2 = val.charAt(2);
- if (at1 == '0' && at2 >= '0' && at2 <= '9') {
- throw new NumberFormatException("val [" + val + "] is not a valid number.");
+ if(at1 == '0' && at2 >= '0' && at2 <= '9') {
+ throw new NumberFormatException("val ["+val+"] is not a valid number.");
}
}
// integer representation.
@@ -2095,24 +2238,26 @@ protected static Number stringToNumber(final String val) throws NumberFormatExce
// only what they need. i.e. Less runtime overhead if the value is
// long lived.
BigInteger bi = new BigInteger(val);
- if (bi.bitLength() <= 31) {
+ if(bi.bitLength() <= 31){
return Integer.valueOf(bi.intValue());
}
- if (bi.bitLength() <= 63) {
+ if(bi.bitLength() <= 63){
return Long.valueOf(bi.longValue());
}
return bi;
}
- throw new NumberFormatException("val [" + val + "] is not a valid number.");
+ throw new NumberFormatException("val ["+val+"] is not a valid number.");
}
/**
* Try to convert a string into a number, boolean, or null. If the string
* can't be converted, return the string.
*
- * @param string A String. can not be null.
+ * @param string
+ * A String. can not be null.
* @return A simple JSON value.
- * @throws NullPointerException Thrown if the string is null.
+ * @throws NullPointerException
+ * Thrown if the string is null.
*/
// Changes to this method must be copied to the corresponding method in
// the XML class to keep full support for Android
@@ -2150,8 +2295,10 @@ public static Object stringToValue(String string) {
/**
* Throw an exception if the object is a NaN or infinite number.
*
- * @param o The object to test.
- * @throws JSONException If o is a non-finite number.
+ * @param o
+ * The object to test.
+ * @throws JSONException
+ * If o is a non-finite number.
*/
public static void testValidity(Object o) throws JSONException {
if (o instanceof Number && !numberIsFinite((Number) o)) {
@@ -2163,10 +2310,12 @@ public static void testValidity(Object o) throws JSONException {
* 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.
+ * @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.
+ * @throws JSONException
+ * If any of the values are non-finite numbers.
*/
public JSONArray toJSONArray(JSONArray names) throws JSONException {
if (names == null || names.isEmpty()) {
@@ -2188,9 +2337,9 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
*
*
* @return a printable, displayable, portable, transmittable representation
- * of the object, beginning with
* Warning: This method assumes that the data structure is acyclical.
*
- * @param value The value to be serialized.
+ * @param value
+ * The value to be serialized.
* @return a printable, displayable, transmittable representation of the
- * object, beginning with
* Warning: This method assumes that the data structure is acyclical.
*
- *
* @param writer the writer object
* @return The writer.
* @throws JSONException if a called function has an error
@@ -2344,7 +2497,7 @@ static final Writer writeValue(Writer writer, Object value,
} else if (value instanceof Number) {
// not all Numbers may match actual JSON Numbers. i.e. fractions or Imaginary
final String numberAsString = numberToString((Number) value);
- if (NUMBER_PATTERN.matcher(numberAsString).matches()) {
+ if(NUMBER_PATTERN.matcher(numberAsString).matches()) {
writer.write(numberAsString);
} else {
// The Number value is not a valid JSON number.
@@ -2354,7 +2507,7 @@ static final Writer writeValue(Writer writer, Object value,
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof Enum>) {
- writer.write(quote(((Enum>) value).name()));
+ writer.write(quote(((Enum>)value).name()));
} else if (value instanceof JSONObject) {
((JSONObject) value).write(writer, indentFactor, indent);
} else if (value instanceof JSONArray) {
@@ -2396,12 +2549,15 @@ static final void indent(Writer writer, int indent) throws IOException {
* Warning: This method assumes that the data structure is acyclical.
*
*
- * @param writer Writes the serialized JSON
- * @param indentFactor The number of spaces to add to each level of indentation.
- * @param indent The indentation of the top level.
+ * @param writer
+ * Writes the serialized JSON
+ * @param indentFactor
+ * The number of spaces to add to each level of indentation.
+ * @param indent
+ * The indentation of the top level.
* @return The writer.
* @throws JSONException if a called function has an error or a write error
- * occurs
+ * occurs
*/
public Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
@@ -2411,21 +2567,21 @@ public Writer write(Writer writer, int indentFactor, int indent)
writer.write('{');
if (length == 1) {
- final EntrytoString
methods strictly conform to
@@ -115,16 +115,16 @@ protected final Object clone() {
/**
* A Null object is equal to the null value and to itself.
*
- * @param object An object to test for nullness.
+ * @param object
+ * An object to test for nullness.
* @return true if the object parameter is the JSONObject.NULL object or
- * null.
+ * null.
*/
@Override
@SuppressWarnings("lgtm[java/unchecked-cast-in-equals]")
public boolean equals(Object object) {
return object == null || object == this;
}
-
/**
* A Null object is equal to the null value and to itself.
*
@@ -147,8 +147,8 @@ public String toString() {
}
/**
- * Regular Expression Pattern that matches JSON Numbers. This is primarily used for
- * output to guarantee that we are always writing valid JSON.
+ * Regular Expression Pattern that matches JSON Numbers. This is primarily used for
+ * output to guarantee that we are always writing valid JSON.
*/
static final Pattern NUMBER_PATTERN = Pattern.compile("-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?");
@@ -183,10 +183,12 @@ public JSONObject() {
* strings is used to identify the keys that should be copied. Missing keys
* are ignored.
*
- * @param jo A JSONObject.
- * @param names An array of strings.
+ * @param jo
+ * A JSONObject.
+ * @param names
+ * An array of strings.
*/
- public JSONObject(JSONObject jo, String... names) {
+ public JSONObject(JSONObject jo, String ... names) {
this(names.length);
for (int i = 0; i < names.length; i += 1) {
try {
@@ -199,9 +201,11 @@ public JSONObject(JSONObject jo, String... names) {
/**
* Construct a JSONObject from a JSONTokener.
*
- * @param x A JSONTokener object containing the source string.
- * @throws JSONException If there is a syntax error in the source string or a
- * duplicated key.
+ * @param x
+ * A JSONTokener object containing the source string.
+ * @throws JSONException
+ * If there is a syntax error in the source string or a
+ * duplicated key.
*/
public JSONObject(JSONTokener x) throws JSONException {
this();
@@ -211,7 +215,7 @@ public JSONObject(JSONTokener x) throws JSONException {
if (x.nextClean() != '{') {
throw x.syntaxError("A JSONObject text must begin with '{'");
}
- for (; ; ) {
+ for (;;) {
c = x.nextClean();
switch (c) {
case 0:
@@ -240,7 +244,7 @@ public JSONObject(JSONTokener x) throws JSONException {
}
// Only add value if non-null
Object value = x.nextValue();
- if (value != null) {
+ if (value!=null) {
this.put(key, value);
}
}
@@ -266,19 +270,21 @@ public JSONObject(JSONTokener x) throws JSONException {
/**
* Construct a JSONObject from a Map.
*
- * @param m A map object that can be used to initialize the contents of
- * the JSONObject.
- * @throws JSONException If a value in the map is non-finite number.
- * @throws NullPointerException If a key in the map is null
- * @throws JSONException If there exists a cyclic dependency in the object provided.
+ * @param m
+ * A map object that can be used to initialize the contents of
+ * the JSONObject.
+ * @throws JSONException
+ * If a value in the map is non-finite number.
+ * @throws NullPointerException
+ * If a key in the map is null
*/
- public JSONObject(Map, ?> m) throws JSONException {
+ public JSONObject(Map, ?> m) {
if (m == null) {
this.map = new HashMap{
(left
- * brace) and ending with }
- * (right brace).
- * @throws JSONException If there is a syntax error in the source string or a
- * duplicated key.
+ * @param source
+ * A string beginning with {
(left
+ * brace) and ending with }
+ * (right brace).
+ * @exception JSONException
+ * If there is a syntax error in the source string or a
+ * duplicated key.
*/
public JSONObject(String source) throws JSONException {
this(new JSONTokener(source));
@@ -393,9 +404,12 @@ public JSONObject(String source) throws JSONException {
/**
* Construct a JSONObject from a ResourceBundle.
*
- * @param baseName The ResourceBundle base name.
- * @param locale The Locale to load the ResourceBundle for.
- * @throws JSONException If any JSONExceptions are detected.
+ * @param baseName
+ * The ResourceBundle base name.
+ * @param locale
+ * The Locale to load the ResourceBundle for.
+ * @throws JSONException
+ * If any JSONExceptions are detected.
*/
public JSONObject(String baseName, Locale locale) throws JSONException {
this();
@@ -437,7 +451,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException {
*
* @param initialCapacity initial capacity of the internal map.
*/
- protected JSONObject(int initialCapacity) {
+ protected JSONObject(int initialCapacity){
this.map = new HashMapnull
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject accumulate(String key, Object value) throws JSONException {
testValidity(value);
@@ -479,12 +497,16 @@ public JSONObject accumulate(String key, Object value) throws JSONException {
* 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.
+ * @param key
+ * A key string.
+ * @param value
+ * An object to be accumulated under the key.
* @return this.
- * @throws JSONException If the value is non-finite number or if the current value associated with
- * the key is not a JSONArray.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number or if the current value associated with
+ * the key is not a JSONArray.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject append(String key, Object value) throws JSONException {
testValidity(value);
@@ -503,7 +525,8 @@ public JSONObject append(String key, Object value) throws JSONException {
* Produce a string from a double. The string "null" will be returned if the
* number is not finite.
*
- * @param d A double.
+ * @param d
+ * A double.
* @return A String.
*/
public static String doubleToString(double d) {
@@ -529,9 +552,11 @@ public static String doubleToString(double d) {
/**
* Get the value object associated with a key.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return The object associated with the key.
- * @throws JSONException if the key is not found.
+ * @throws JSONException
+ * if the key is not found.
*/
public Object get(String key) throws JSONException {
if (key == null) {
@@ -547,16 +572,20 @@ public Object get(String key) throws JSONException {
/**
* Get the enum value associated with a key.
*
- * @param null
or if there is no
* value.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return true if there is no value associated with the key or if the value
- * is the JSONObject.NULL object.
+ * is the JSONObject.NULL object.
*/
public boolean isNull(String key) {
return JSONObject.NULL.equals(this.opt(key));
@@ -866,8 +923,9 @@ public boolean isNull(String key) {
* Get an enumeration of the keys of the JSONObject. Modifying this key Set will also
* modify the JSONObject. Use with caution.
*
- * @return An iterator of the keys.
* @see Set#iterator()
+ *
+ * @return An iterator of the keys.
*/
public Iteratorclazz
+ * if the value is not found or cannot be assigned to clazz
*/
public true
, then {@link Double} and {@link Float} values will be converted exactly.
- * When false
, they will be converted to {@link String} values before converting to {@link BigDecimal}.
+ * @param exact When true
, then {@link Double} and {@link Float} values will be converted exactly.
+ * When false
, they will be converted to {@link String} values before converting to {@link BigDecimal}.
* @return BigDecimal conversion of the original value, or the defaultValue if unable
- * to convert.
+ * to convert.
*/
static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue, boolean exact) {
if (NULL.equals(val)) {
return defaultValue;
}
- if (val instanceof BigDecimal) {
+ if (val instanceof BigDecimal){
return (BigDecimal) val;
}
- if (val instanceof BigInteger) {
+ if (val instanceof BigInteger){
return new BigDecimal((BigInteger) val);
}
- if (val instanceof Double || val instanceof Float) {
- if (!numberIsFinite((Number) val)) {
+ if (val instanceof Double || val instanceof Float){
+ if (!numberIsFinite((Number)val)) {
return defaultValue;
}
if (exact) {
- return new BigDecimal(((Number) val).doubleValue());
- } else {
+ return new BigDecimal(((Number)val).doubleValue());
+ }else {
// use the string constructor so that we maintain "nice" values for doubles and floats
// the double constructor will translate doubles to "exact" values instead of the likely
// intended representation
@@ -1114,7 +1189,7 @@ static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue, boolea
}
}
if (val instanceof Long || val instanceof Integer
- || val instanceof Short || val instanceof Byte) {
+ || val instanceof Short || val instanceof Byte){
return new BigDecimal(((Number) val).longValue());
}
// don't check if it's a string in case of unchecked Number subclasses
@@ -1130,8 +1205,10 @@ static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue, boolea
* there is no such key or if its value is not a number. If the value is a
* string, an attempt will be made to evaluate it as a number.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An object which is the value.
*/
public BigInteger optBigInteger(String key, BigInteger defaultValue) {
@@ -1140,29 +1217,29 @@ public BigInteger optBigInteger(String key, BigInteger defaultValue) {
}
/**
- * @param val value to convert
+ * @param val value to convert
* @param defaultValue default value to return is the conversion doesn't work or is null.
* @return BigInteger conversion of the original value, or the defaultValue if unable
- * to convert.
+ * to convert.
*/
static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) {
if (NULL.equals(val)) {
return defaultValue;
}
- if (val instanceof BigInteger) {
+ if (val instanceof BigInteger){
return (BigInteger) val;
}
- if (val instanceof BigDecimal) {
+ if (val instanceof BigDecimal){
return ((BigDecimal) val).toBigInteger();
}
- if (val instanceof Double || val instanceof Float) {
- if (!numberIsFinite((Number) val)) {
+ if (val instanceof Double || val instanceof Float){
+ if (!numberIsFinite((Number)val)) {
return defaultValue;
}
return new BigDecimal(((Number) val).doubleValue()).toBigInteger();
}
if (val instanceof Long || val instanceof Integer
- || val instanceof Short || val instanceof Byte) {
+ || val instanceof Short || val instanceof Byte){
return BigInteger.valueOf(((Number) val).longValue());
}
// don't check if it's a string in case of unchecked Number subclasses
@@ -1173,7 +1250,7 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) {
// this conversion to BigDecimal then to BigInteger is to maintain
// that type cast support that may truncate the decimal.
final String valStr = val.toString();
- if (isDecimalNotation(valStr)) {
+ if(isDecimalNotation(valStr)) {
return new BigDecimal(valStr).toBigInteger();
}
return new BigInteger(valStr);
@@ -1187,7 +1264,8 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) {
* key or if its value is not a number. If the value is a string, an attempt
* will be made to evaluate it as a number.
*
- * @param key A string which is the key.
+ * @param key
+ * A string which is the key.
* @return An object which is the value.
*/
public double optDouble(String key) {
@@ -1199,8 +1277,10 @@ public double optDouble(String key) {
* there is no such key or if its value is not a number. If the value is a
* string, an attempt will be made to evaluate it as a number.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An object which is the value.
*/
public double optDouble(String key, double defaultValue) {
@@ -1220,7 +1300,8 @@ public double optDouble(String key, double defaultValue) {
* if there is no value for the index, or if the value is not a number and
* cannot be converted to a number.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return The value.
*/
public float optFloat(String key) {
@@ -1232,8 +1313,10 @@ public float optFloat(String key) {
* 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 key A key string.
- * @param defaultValue The default value.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default value.
* @return The value.
*/
public float optFloat(String key, float defaultValue) {
@@ -1253,7 +1336,8 @@ public float optFloat(String key, float defaultValue) {
* such key or if the value is not a number. If the value is a string, an
* attempt will be made to evaluate it as a number.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return An object which is the value.
*/
public int optInt(String key) {
@@ -1265,8 +1349,10 @@ public int optInt(String key) {
* is no such key or if the value is not a number. If the value is a string,
* an attempt will be made to evaluate it as a number.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An object which is the value.
*/
public int optInt(String key, int defaultValue) {
@@ -1281,7 +1367,8 @@ public int optInt(String key, int defaultValue) {
* Get an optional JSONArray associated with a key. It returns null if there
* is no such key, or if its value is not a JSONArray.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return A JSONArray which is the value.
*/
public JSONArray optJSONArray(String key) {
@@ -1293,19 +1380,20 @@ public JSONArray optJSONArray(String key) {
* Get an optional JSONObject associated with a key. It returns null if
* there is no such key, or if its value is not a JSONObject.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return A JSONObject which is the value.
*/
- public JSONObject optJSONObject(String key) {
- return this.optJSONObject(key, null);
- }
+ public JSONObject optJSONObject(String key) { return this.optJSONObject(key, null); }
/**
* Get an optional JSONObject associated with a key, or the default if there
* is no such key or if the value is not a JSONObject.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An JSONObject which is the value.
*/
public JSONObject optJSONObject(String key, JSONObject defaultValue) {
@@ -1318,7 +1406,8 @@ public JSONObject optJSONObject(String key, JSONObject defaultValue) {
* such key or if the value is not a number. If the value is a string, an
* attempt will be made to evaluate it as a number.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return An object which is the value.
*/
public long optLong(String key) {
@@ -1330,8 +1419,10 @@ public long optLong(String key) {
* is no such key or if the value is not a number. If the value is a string,
* an attempt will be made to evaluate it as a number.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An object which is the value.
*/
public long optLong(String key, long defaultValue) {
@@ -1349,7 +1440,8 @@ public long optLong(String key, long defaultValue) {
* an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method
* would be used in cases where type coercion of the number value is unwanted.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return An object which is the value.
*/
public Number optNumber(String key) {
@@ -1362,8 +1454,10 @@ public Number optNumber(String key) {
* an attempt will be made to evaluate it as a number. This method
* would be used in cases where type coercion of the number value is unwanted.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return An object which is the value.
*/
public Number optNumber(String key, Number defaultValue) {
@@ -1371,7 +1465,7 @@ public Number optNumber(String key, Number defaultValue) {
if (NULL.equals(val)) {
return defaultValue;
}
- if (val instanceof Number) {
+ if (val instanceof Number){
return (Number) val;
}
@@ -1387,7 +1481,8 @@ public Number optNumber(String key, Number defaultValue) {
* if there is no such key. If the value is not a string and is not null,
* then it is converted to a string.
*
- * @param key A key string.
+ * @param key
+ * A key string.
* @return A string which is the value.
*/
public String optString(String key) {
@@ -1398,8 +1493,10 @@ public String optString(String key) {
* Get an optional string associated with a key. It returns the defaultValue
* if there is no such key.
*
- * @param key A key string.
- * @param defaultValue The default.
+ * @param key
+ * A key string.
+ * @param defaultValue
+ * The default.
* @return A string which is the value.
*/
public String optString(String key, String defaultValue) {
@@ -1411,8 +1508,10 @@ public String optString(String key, String defaultValue) {
* Populates the internal map of the JSONObject with the bean properties. The
* bean can not be recursive.
*
- * @param bean the bean
* @see JSONObject#JSONObject(Object)
+ *
+ * @param bean
+ * the bean
*/
private void populateMap(Object bean) {
@@ -1503,11 +1602,15 @@ private static String getKeyNameFromMethod(Method method) {
* Searches the class hierarchy to see if the method or it's super
* implementations and interfaces has the annotation.
*
- * @param type of the annotation
- * @param m method to check
- * @param annotationClass annotation to look for
+ * @param
+ * type of the annotation
+ *
+ * @param m
+ * method to check
+ * @param annotationClass
+ * annotation to look for
* @return the {@link Annotation} if the annotation exists on the current method
- * or one of its super class definitions
+ * or one of its super class definitions
*/
private static A getAnnotation(final Method m, final Class annotationClass) {
// if we have invalid data the result is null
@@ -1553,8 +1656,10 @@ private static A getAnnotation(final Method m, final Clas
* implementations and interfaces has the annotation. Returns the depth of the
* annotation in the hierarchy.
*
- * @param m method to check
- * @param annotationClass annotation to look for
+ * @param m
+ * method to check
+ * @param annotationClass
+ * annotation to look for
* @return Depth of the annotation or -1 if the annotation is not on the method.
*/
private static int getAnnotationDepth(final Method m, final Class extends Annotation> annotationClass) {
@@ -1608,11 +1713,15 @@ private static int getAnnotationDepth(final Method m, final Class extends Anno
/**
* Put a key/boolean pair in the JSONObject.
*
- * @param key A key string.
- * @param value A boolean which is the value.
+ * @param key
+ * A key string.
+ * @param value
+ * A boolean which is the value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, boolean value) throws JSONException {
return this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
@@ -1622,11 +1731,15 @@ public JSONObject put(String key, boolean value) throws JSONException {
* 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.
+ * @param key
+ * A key string.
+ * @param value
+ * A Collection value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, Collection> value) throws JSONException {
return this.put(key, new JSONArray(value));
@@ -1635,11 +1748,15 @@ public JSONObject put(String key, Collection> value) throws JSONException {
/**
* Put a key/double pair in the JSONObject.
*
- * @param key A key string.
- * @param value A double which is the value.
+ * @param key
+ * A key string.
+ * @param value
+ * A double which is the value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, double value) throws JSONException {
return this.put(key, Double.valueOf(value));
@@ -1648,11 +1765,15 @@ public JSONObject put(String key, double value) throws JSONException {
/**
* Put a key/float pair in the JSONObject.
*
- * @param key A key string.
- * @param value A float which is the value.
+ * @param key
+ * A key string.
+ * @param value
+ * A float which is the value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, float value) throws JSONException {
return this.put(key, Float.valueOf(value));
@@ -1661,11 +1782,15 @@ public JSONObject put(String key, float value) throws JSONException {
/**
* Put a key/int pair in the JSONObject.
*
- * @param key A key string.
- * @param value An int which is the value.
+ * @param key
+ * A key string.
+ * @param value
+ * An int which is the value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, int value) throws JSONException {
return this.put(key, Integer.valueOf(value));
@@ -1674,11 +1799,15 @@ public JSONObject put(String key, int value) throws JSONException {
/**
* Put a key/long pair in the JSONObject.
*
- * @param key A key string.
- * @param value A long which is the value.
+ * @param key
+ * A key string.
+ * @param value
+ * A long which is the value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, long value) throws JSONException {
return this.put(key, Long.valueOf(value));
@@ -1688,11 +1817,15 @@ public JSONObject put(String key, long value) throws JSONException {
* Put a key/value pair in the JSONObject, where the value will be a
* JSONObject which is produced from a Map.
*
- * @param key A key string.
- * @param value A Map value.
+ * @param key
+ * A key string.
+ * @param value
+ * A Map value.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, Map, ?> value) throws JSONException {
return this.put(key, new JSONObject(value));
@@ -1702,13 +1835,17 @@ public JSONObject put(String key, Map, ?> value) throws JSONException {
* Put a key/value pair in the JSONObject. If the value is null
, then the
* key will be removed from the JSONObject if it is present.
*
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
- * String, or the JSONObject.NULL object.
+ * @param key
+ * A key string.
+ * @param value
+ * An object which is the value. It should be of one of these
+ * types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
+ * String, or the JSONObject.NULL object.
* @return this.
- * @throws JSONException If the value is non-finite number.
- * @throws NullPointerException If the key is null
.
+ * @throws JSONException
+ * If the value is non-finite number.
+ * @throws NullPointerException
+ * If the key is null
.
*/
public JSONObject put(String key, Object value) throws JSONException {
if (key == null) {
@@ -1728,10 +1865,13 @@ public JSONObject put(String key, Object value) throws JSONException {
* are both non-null, and only if there is not already a member with that
* name.
*
- * @param key key to insert into
- * @param value value to insert
+ * @param key
+ * key to insert into
+ * @param value
+ * value to insert
* @return this.
- * @throws JSONException if the key is a duplicate
+ * @throws JSONException
+ * if the key is a duplicate
*/
public JSONObject putOnce(String key, Object value) throws JSONException {
if (key != null && value != null) {
@@ -1747,12 +1887,15 @@ public JSONObject putOnce(String key, Object value) throws JSONException {
* Put a key/value pair in the JSONObject, but only if the key and the value
* are both non-null.
*
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
- * String, or the JSONObject.NULL object.
+ * @param key
+ * A key string.
+ * @param value
+ * An object which is the value. It should be of one of these
+ * types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
+ * String, or the JSONObject.NULL object.
* @return this.
- * @throws JSONException If the value is a non-finite number.
+ * @throws JSONException
+ * If the value is a non-finite number.
*/
public JSONObject putOpt(String key, Object value) throws JSONException {
if (key != null && value != null) {
@@ -1783,7 +1926,6 @@ public JSONObject putOpt(String key, Object value) throws JSONException {
public Object query(String jsonPointer) {
return query(new JSONPointer(jsonPointer));
}
-
/**
* Uses a user initialized JSONPointer and tries to
* match it to an item within this JSONObject. For example, given a
@@ -1842,7 +1984,8 @@ public Object optQuery(JSONPointer jsonPointer) {
* string cannot contain a control character or an unescaped quote or
* backslash.
*
- * @param string A String
+ * @param string
+ * A String
* @return A String correctly formatted for insertion in a JSON text.
*/
public static String quote(String string) {
@@ -1919,9 +2062,10 @@ public static Writer quote(String string, Writer w) throws IOException {
/**
* Remove a name and its value, if present.
*
- * @param key The name to be removed.
+ * @param key
+ * The name to be removed.
* @return The value that was associated with the name, or null if there was
- * no value.
+ * no value.
*/
public Object remove(String key) {
return this.map.remove(key);
@@ -1940,32 +2084,31 @@ public boolean similar(Object other) {
if (!(other instanceof JSONObject)) {
return false;
}
- if (!this.keySet().equals(((JSONObject) other).keySet())) {
+ if (!this.keySet().equals(((JSONObject)other).keySet())) {
return false;
}
- for (final Entry{
(left
- * brace) and ending with }
(right
- * brace).
+ * of the object, beginning with {
(left
+ * brace) and ending with }
(right
+ * brace).
*/
@Override
public String toString() {
@@ -2218,12 +2367,14 @@ public String toString() {
* Warning: This method assumes that the data structure is acyclical.
*
*
- * @param indentFactor The number of spaces to add to each level of indentation.
+ * @param indentFactor
+ * The number of spaces to add to each level of indentation.
* @return a printable, displayable, portable, transmittable representation
- * of the object, beginning with {
(left
- * brace) and ending with }
(right
- * brace).
- * @throws JSONException If the object contains an invalid number.
+ * of the object, beginning with {
(left
+ * brace) and ending with }
(right
+ * brace).
+ * @throws JSONException
+ * If the object contains an invalid number.
*/
public String toString(int indentFactor) throws JSONException {
StringWriter w = new StringWriter();
@@ -2247,12 +2398,14 @@ public String toString(int indentFactor) throws JSONException {
* {
(left
- * brace) and ending with }
(right
- * brace).
- * @throws JSONException If the value is or contains an invalid number.
+ * object, beginning with {
(left
+ * brace) and ending with }
(right
+ * brace).
+ * @throws JSONException
+ * If the value is or contains an invalid number.
*/
public static String valueToString(Object value) throws JSONException {
// moves the implementation to JSONWriter as:
@@ -2270,7 +2423,8 @@ public static String valueToString(Object value) throws JSONException {
* one of the java packages, turn it into a string. And if it doesn't, try
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
*
- * @param object The object to wrap
+ * @param object
+ * The object to wrap
* @return The wrapped value
*/
public static Object wrap(Object object) {
@@ -2320,7 +2474,6 @@ public static Object wrap(Object object) {
*