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 toString 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(); } else { this.map = new HashMap(m.size()); for (final Entry e : m.entrySet()) { - if (e.getKey() == null) { + if(e.getKey() == null) { throw new NullPointerException("Null key."); } final Object value = e.getValue(); @@ -344,8 +350,9 @@ public JSONObject(Map m) throws JSONException { * *

* - * @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 { (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 HashMap(initialCapacity); } @@ -447,16 +461,20 @@ protected JSONObject(int initialCapacity) { * 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. - *

+ * * 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 null. + * @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 Enum Type - * @param clazz The type of enum to retrieve. - * @param key A key string. + * @param + * Enum Type + * @param clazz + * The type of enum to retrieve. + * @param key + * A key string. * @return The enum value associated with the key - * @throws JSONException if the key is not found or if the value cannot be converted - * to an enum. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an enum. */ public > E getEnum(Class clazz, String key) throws JSONException { E val = optEnum(clazz, key); - if (val == null) { + if(val==null) { // JSONException should really take a throwable argument. // If it did, I would re-implement this with the Enum.valueOf // method and place any thrown exception in the JSONException @@ -568,10 +597,12 @@ public > E getEnum(Class clazz, String key) throws JSONExce /** * Get the boolean value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The truth. - * @throws JSONException if the value is not a Boolean or the String "true" or - * "false". + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". */ public boolean getBoolean(String key) throws JSONException { Object object = this.get(key); @@ -590,10 +621,12 @@ public boolean getBoolean(String key) throws JSONException { /** * Get the BigInteger value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value cannot - * be converted to BigInteger. + * @throws JSONException + * if the key is not found or if the value cannot + * be converted to BigInteger. */ public BigInteger getBigInteger(String key) throws JSONException { Object object = this.get(key); @@ -610,10 +643,12 @@ public BigInteger getBigInteger(String key) throws JSONException { * be used. See notes on the constructor for conversion issues that may * arise. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value - * cannot be converted to BigDecimal. + * @throws JSONException + * if the key is not found or if the value + * cannot be converted to BigDecimal. */ public BigDecimal getBigDecimal(String key) throws JSONException { Object object = this.get(key); @@ -627,15 +662,17 @@ public BigDecimal getBigDecimal(String key) throws JSONException { /** * Get the double value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value is not a Number - * object and cannot be converted to a number. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. */ public double getDouble(String key) throws JSONException { final Object object = this.get(key); - if (object instanceof Number) { - return ((Number) object).doubleValue(); + if(object instanceof Number) { + return ((Number)object).doubleValue(); } try { return Double.parseDouble(object.toString()); @@ -647,15 +684,17 @@ public double getDouble(String key) throws JSONException { /** * Get the float value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value is not a Number - * object and cannot be converted to a number. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. */ public float getFloat(String key) throws JSONException { final Object object = this.get(key); - if (object instanceof Number) { - return ((Number) object).floatValue(); + if(object instanceof Number) { + return ((Number)object).floatValue(); } try { return Float.parseFloat(object.toString()); @@ -667,16 +706,18 @@ public float getFloat(String key) throws JSONException { /** * Get the Number value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The numeric value. - * @throws JSONException if the key is not found or if the value is not a Number - * object and cannot be converted to a number. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. */ public Number getNumber(String key) throws JSONException { Object object = this.get(key); try { if (object instanceof Number) { - return (Number) object; + return (Number)object; } return stringToNumber(object.toString()); } catch (Exception e) { @@ -687,15 +728,17 @@ public Number getNumber(String key) throws JSONException { /** * Get the int value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The integer value. - * @throws JSONException if the key is not found or if the value cannot be converted - * to an integer. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. */ public int getInt(String key) throws JSONException { final Object object = this.get(key); - if (object instanceof Number) { - return ((Number) object).intValue(); + if(object instanceof Number) { + return ((Number)object).intValue(); } try { return Integer.parseInt(object.toString()); @@ -707,9 +750,11 @@ public int getInt(String key) throws JSONException { /** * Get the JSONArray value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A JSONArray which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONArray. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. */ public JSONArray getJSONArray(String key) throws JSONException { Object object = this.get(key); @@ -722,9 +767,11 @@ public JSONArray getJSONArray(String key) throws JSONException { /** * Get the JSONObject value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A JSONObject which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONObject. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. */ public JSONObject getJSONObject(String key) throws JSONException { Object object = this.get(key); @@ -737,15 +784,17 @@ public JSONObject getJSONObject(String key) throws JSONException { /** * Get the long value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return The long value. - * @throws JSONException if the key is not found or if the value cannot be converted - * to a long. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. */ public long getLong(String key) throws JSONException { final Object object = this.get(key); - if (object instanceof Number) { - return ((Number) object).longValue(); + if(object instanceof Number) { + return ((Number)object).longValue(); } try { return Long.parseLong(object.toString()); @@ -757,7 +806,8 @@ public long getLong(String key) throws JSONException { /** * Get an array of field names from a JSONObject. * - * @param jo JSON object + * @param jo + * JSON object * @return An array of field names, or null if there are no names. */ public static String[] getNames(JSONObject jo) { @@ -770,7 +820,8 @@ public static String[] getNames(JSONObject jo) { /** * Get an array of public field names from an Object. * - * @param object object to read + * @param object + * object to read * @return An array of field names, or null if there are no names. */ public static String[] getNames(Object object) { @@ -793,9 +844,11 @@ public static String[] getNames(Object object) { /** * Get the string associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return A string which is the value. - * @throws JSONException if there is no string value for the key. + * @throws JSONException + * if there is no string value for the key. */ public String getString(String key) throws JSONException { Object object = this.get(key); @@ -808,7 +861,8 @@ public String getString(String key) throws JSONException { /** * Determine if the JSONObject contains a specific key. * - * @param key A key string. + * @param key + * A key string. * @return true if the key exists in the JSONObject. */ public boolean has(String key) { @@ -823,10 +877,12 @@ public boolean has(String key) { * prior to this call with an appropriate type that can handle the maximum expected * value. * - * @param key A key string. + * @param key + * A key string. * @return this. - * @throws JSONException If there is already a property with this name that is not an - * Integer, Long, Double, or Float. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. */ public JSONObject increment(String key) throws JSONException { Object value = this.opt(key); @@ -837,13 +893,13 @@ public JSONObject increment(String key) throws JSONException { } else if (value instanceof Long) { this.put(key, ((Long) value).longValue() + 1L); } else if (value instanceof BigInteger) { - this.put(key, ((BigInteger) value).add(BigInteger.ONE)); + this.put(key, ((BigInteger)value).add(BigInteger.ONE)); } else if (value instanceof Float) { this.put(key, ((Float) value).floatValue() + 1.0f); } else if (value instanceof Double) { this.put(key, ((Double) value).doubleValue() + 1.0d); } else if (value instanceof BigDecimal) { - this.put(key, ((BigDecimal) value).add(BigDecimal.ONE)); + this.put(key, ((BigDecimal)value).add(BigDecimal.ONE)); } else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } @@ -854,9 +910,10 @@ public JSONObject increment(String key) throws JSONException { * Determine if the value associated with the key is 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 Iterator keys() { return this.keySet().iterator(); @@ -877,8 +935,9 @@ public Iterator keys() { * Get a set of keys of the JSONObject. Modifying this key Set will also modify the * JSONObject. Use with caution. * - * @return A keySet. * @see Map#keySet() + * + * @return A keySet. */ public Set keySet() { return this.map.keySet(); @@ -889,11 +948,12 @@ public Set keySet() { * match what is returned by the JSONObject get* and opt* functions. Modifying * the returned EntrySet or the Entry objects contained therein will modify the * backing JSONObject. This does not return a clone or a read-only view. - *

+ * * Use with caution. * - * @return An Entry Set * @see Map#entrySet() + * + * @return An Entry Set */ protected Set> entrySet() { return this.map.entrySet(); @@ -930,10 +990,10 @@ public boolean isEmpty() { * JSONObject. * * @return A JSONArray containing the key strings, or null if the JSONObject - * is empty. + * is empty. */ public JSONArray names() { - if (this.map.isEmpty()) { + if(this.map.isEmpty()) { return null; } return new JSONArray(this.map.keySet()); @@ -942,9 +1002,11 @@ public JSONArray names() { /** * Produce a string from a Number. * - * @param number A Number + * @param number + * A Number * @return A String. - * @throws JSONException If n is a non-finite number. + * @throws JSONException + * If n is a non-finite number. */ public static String numberToString(Number number) throws JSONException { if (number == null) { @@ -970,7 +1032,8 @@ public static String numberToString(Number number) throws JSONException { /** * Get an optional value associated with a key. * - * @param key A key string. + * @param key + * A key string. * @return An object which is the value, or null if there is no value. */ public Object opt(String key) { @@ -980,9 +1043,12 @@ public Object opt(String key) { /** * Get the enum value associated with a key. * - * @param Enum Type - * @param clazz The type of enum to retrieve. - * @param key A key string. + * @param + * Enum Type + * @param clazz + * The type of enum to retrieve. + * @param key + * A key string. * @return The enum value associated with the key or null if not found */ public > E optEnum(Class clazz, String key) { @@ -992,12 +1058,16 @@ public > E optEnum(Class clazz, String key) { /** * Get the enum value associated with a key. * - * @param Enum Type - * @param clazz The type of enum to retrieve. - * @param key A key string. - * @param defaultValue The default in case the value is not found + * @param + * Enum Type + * @param clazz + * The type of enum to retrieve. + * @param key + * A key string. + * @param defaultValue + * The default in case the value is not found * @return The enum value associated with the key or defaultValue - * if the value is not found or cannot be assigned to clazz + * if the value is not found or cannot be assigned to clazz */ public > E optEnum(Class clazz, String key, E defaultValue) { try { @@ -1023,7 +1093,8 @@ public > E optEnum(Class clazz, String key, E defaultValue) * Get an optional boolean associated with a key. It returns false if there * is no such key, or if the value is not Boolean.TRUE or the String "true". * - * @param key A key string. + * @param key + * A key string. * @return The truth. */ public boolean optBoolean(String key) { @@ -1035,8 +1106,10 @@ public boolean optBoolean(String key) { * defaultValue if there is no such key, or if it is not a Boolean or the * String "true" or "false" (case insensitive). * - * @param key A key string. - * @param defaultValue The default. + * @param key + * A key string. + * @param defaultValue + * The default. * @return The truth. */ public boolean optBoolean(String key, boolean defaultValue) { @@ -1044,7 +1117,7 @@ public boolean optBoolean(String key, boolean defaultValue) { if (NULL.equals(val)) { return defaultValue; } - if (val instanceof Boolean) { + if (val instanceof Boolean){ return ((Boolean) val).booleanValue(); } try { @@ -1063,8 +1136,10 @@ public boolean optBoolean(String key, boolean defaultValue) { * constructor will be used. See notes on the constructor for conversion * issues that may arise. * - * @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 BigDecimal optBigDecimal(String key, BigDecimal defaultValue) { @@ -1073,40 +1148,40 @@ public BigDecimal optBigDecimal(String key, BigDecimal 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 BigDecimal conversion of the original value, or the defaultValue if unable - * to convert. + * to convert. */ static BigDecimal objectToBigDecimal(Object val, BigDecimal defaultValue) { return objectToBigDecimal(val, defaultValue, true); } /** - * @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. - * @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}. + * @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 annotationClass) { @@ -1608,11 +1713,15 @@ private static int getAnnotationDepth(final Method m, final Classnull. + * @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 entry : this.entrySet()) { + for (final Entry entry : this.entrySet()) { String name = entry.getKey(); Object valueThis = entry.getValue(); - Object valueOther = ((JSONObject) other).get(name); - if (valueThis == valueOther) { + Object valueOther = ((JSONObject)other).get(name); + if(valueThis == valueOther) { continue; } - if (valueThis == null) { + if(valueThis == null) { return false; } if (valueThis instanceof JSONObject) { - if (!((JSONObject) valueThis).similar(valueOther)) { + if (!((JSONObject)valueThis).similar(valueOther)) { return false; } } else if (valueThis instanceof JSONArray) { - if (!((JSONArray) valueThis).similar(valueOther)) { + if (!((JSONArray)valueThis).similar(valueOther)) { return false; } } else if (valueThis instanceof Number && valueOther instanceof Number) { - if (!isNumberSimilar((Number) valueThis, (Number) valueOther)) { + if (!isNumberSimilar((Number)valueThis, (Number)valueOther)) { return false; - } - ; + }; } else if (!valueThis.equals(valueOther)) { return false; } @@ -1978,7 +2121,7 @@ public boolean similar(Object other) { /** * Compares two numbers to see if they are similar. - *

+ * * 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 { (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 { *

* 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 { (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) { *

* 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 Entry entry = this.entrySet().iterator().next(); + final Entry entry = this.entrySet().iterator().next(); final String key = entry.getKey(); writer.write(quote(key)); writer.write(':'); if (indentFactor > 0) { writer.write(' '); } - try { + try{ writeValue(writer, entry.getValue(), indentFactor, indent); } catch (Exception e) { throw new JSONException("Unable to write JSONObject value for key: " + key, e); } } else if (length != 0) { final int newIndent = indent + indentFactor; - for (final Entry entry : this.entrySet()) { + for (final Entry entry : this.entrySet()) { if (needsComma) { writer.write(','); } @@ -2487,10 +2643,9 @@ public Map toMap() { /** * Create a new JSONException in a common format for incorrect conversions. - * - * @param key name of the key + * @param key name of the key * @param valueType the type of value being coerced to - * @param cause optional cause of the coercion failure + * @param cause optional cause of the coercion failure * @return JSONException that can be thrown. */ private static JSONException wrongValueFormatException( @@ -2504,10 +2659,9 @@ private static JSONException wrongValueFormatException( /** * Create a new JSONException in a common format for incorrect conversions. - * - * @param key name of the key + * @param key name of the key * @param valueType the type of value being coerced to - * @param cause optional cause of the coercion failure + * @param cause optional cause of the coercion failure * @return JSONException that can be thrown. */ private static JSONException wrongValueFormatException( @@ -2593,5 +2747,4 @@ private static JSONException cyclicDependencyFormatException(String key) { return new JSONException( "JSONObject[" + quote(key) + "] cannot be written because of a Cyclic Dependency"); } - -} +} \ No newline at end of file diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 1ae6074dc..cc146349f 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -58,24 +58,7 @@ of this software and associated documentation files (the "Software"), to deal import org.json.JSONPointerException; import org.json.JSONTokener; import org.json.XML; -import org.json.junit.data.BrokenToString; -import org.json.junit.data.ExceptionalBean; -import org.json.junit.data.Fraction; -import org.json.junit.data.GenericBean; -import org.json.junit.data.GenericBeanInt; -import org.json.junit.data.MyBean; -import org.json.junit.data.MyBeanCustomName; -import org.json.junit.data.MyBeanCustomNameSubClass; -import org.json.junit.data.MyBigNumberBean; -import org.json.junit.data.MyEnum; -import org.json.junit.data.MyEnumField; -import org.json.junit.data.MyJsonString; -import org.json.junit.data.MyNumber; -import org.json.junit.data.MyNumberContainer; -import org.json.junit.data.MyPublicClass; -import org.json.junit.data.Singleton; -import org.json.junit.data.SingletonEnum; -import org.json.junit.data.WeirdList; +import org.json.junit.data.*; import org.junit.Test; import com.jayway.jsonpath.Configuration;