* returns a value if one can be found, and throws an exception if one cannot be
* found. An <code>opt</code> method returns a default value instead of throwing
* an exception, and so is useful for obtaining optional values.
* returns a value if one can be found, and throws an exception if one cannot be
* found. An <code>opt</code> method returns a default value instead of throwing
* an exception, and so is useful for obtaining optional values.
* object, which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and type
* coercion for you. The opt methods differ from the get methods in that they do
* not throw. Instead, they return a specified value, such as null.
* object, which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and type
* coercion for you. The opt methods differ from the get methods in that they do
* not throw. Instead, they return a specified value, such as null.
- * <p>
- * produces the string <code>{"JSON": "Hello, World"}</code>.
- * <p>
- * The texts produced by the <code>toString</code> methods strictly conform to
+ *
+ * <p>* produces the string <code>{"JSON": "Hello, World"}</code>.
+ *
+ * <p>The texts produced by the <code>toString</code> methods strictly conform to
* Returns a hash code value for the object. This method is
* supported for the benefit of hash tables such as those provided by
* {@link HashMap}.
* Returns a hash code value for the object. This method is
* supported for the benefit of hash tables such as those provided by
* {@link HashMap}.
* <ul>
* <li>Whenever it is invoked on the same object more than once during
* an execution of a Java application, the {@code hashCode} method
* <ul>
* <li>Whenever it is invoked on the same object more than once during
* an execution of a Java application, the {@code hashCode} method
* programmer should be aware that producing distinct integer results
* for unequal objects may improve the performance of hash tables.
* </ul>
* programmer should be aware that producing distinct integer results
* for unequal objects may improve the performance of hash tables.
* </ul>
* class {@code Object} does return distinct integers for distinct
* objects. (This is typically implemented by converting the internal
* address of the object into an integer, but this implementation
* class {@code Object} does return distinct integers for distinct
* objects. (This is typically implemented by converting the internal
* address of the object into an integer, but this implementation
*/
public LOGJSONObject(Map<String, Object> map) {
this.map = new LinkedHashMap<>();
if (map != null) {
*/
public LOGJSONObject(Map<String, Object> map) {
this.map = new LinkedHashMap<>();
if (map != null) {
- Iterator<Map.Entry<String, Object>> i = map.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry<String, Object> e = i.next();
- Object value = e.getValue();
+ Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry<String, Object> entry = iterator.next();
+ Object value = entry.getValue();
* with <code>"get"</code> or <code>"is"</code> followed by an uppercase letter,
* the method is invoked, and a key and the value returned from the getter method
* are put into the new JSONObject.
* with <code>"get"</code> or <code>"is"</code> followed by an uppercase letter,
* the method is invoked, and a key and the value returned from the getter method
* are put into the new JSONObject.
* If the second remaining character is not upper case, then the first
* character is converted to lower case.
* If the second remaining character is not upper case, then the first
* character is converted to lower case.
* if the result of calling <code>object.getName()</code> is <code>"Larry Fine"</code>,
* then the JSONObject will contain <code>"name": "Larry Fine"</code>.
*
* if the result of calling <code>object.getName()</code> is <code>"Larry Fine"</code>,
* then the JSONObject will contain <code>"name": "Larry Fine"</code>.
*
* JSONArray is stored under the key to hold all of the accumulated values.
* If there is already a JSONArray, then the new value is appended to it.
* In contrast, the put method replaces the previous value.
* JSONArray is stored under the key to hold all of the accumulated values.
* If there is already a JSONArray, then the new value is appended to it.
* In contrast, the put method replaces the previous value.
* result will be the same as using put. But if multiple values are
* accumulated, then the result will be like append.
*
* result will be the same as using put. But if multiple values are
* accumulated, then the result will be like append.
*
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
- public static String doubleToString(double d) {
- if (Double.isInfinite(d) || Double.isNaN(d)) {
+ public static String doubleToString(double dub) {
+ if (Double.isInfinite(dub) || Double.isNaN(dub)) {
if (string.indexOf('.') > 0 && string.indexOf('e') < 0
&& string.indexOf('E') < 0) {
while (string.endsWith("0")) {
if (string.indexOf('.') > 0 && string.indexOf('e') < 0
&& string.indexOf('E') < 0) {
while (string.endsWith("0")) {
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- "false".equalsIgnoreCase((String) object))) {
+ if (object.equals(Boolean.FALSE)
+ || (object instanceof String
+ && "false".equalsIgnoreCase((String) object))) {
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- "true".equalsIgnoreCase((String) object))) {
+ } else if (object.equals(Boolean.TRUE)
+ || (object instanceof String
+ && "true".equalsIgnoreCase((String) object))) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
- if (key.length() > 0 &&
- Character.isUpperCase(key.charAt(0)) &&
- method.getParameterTypes().length == 0) {
+ if (key.length() > 0
+ && Character.isUpperCase(key.charAt(0))
+ && method.getParameterTypes().length == 0) {
* @throws JSONException if the key is a duplicate
*/
public LOGJSONObject putOnce(String key, Object value) {
* @throws JSONException if the key is a duplicate
*/
public LOGJSONObject putOnce(String key, Object value) {
- * right places. A backslash will be inserted within </, producing <\/,
- * allowing JSON text to be delivered in HTML. In JSON text, a string
+ * right places. In JSON text, a string
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
- || (c >= '\u2000' && c < '\u2100')) {
- w.write("\\u");
- hhhh = Integer.toHexString(c);
- w.write("0000", 0, 4 - hhhh.length());
- w.write(hhhh);
+ if (char2 < ' ' || (char2 >= '\u0080' && char2 < '\u00a0')
+ || (char2 >= '\u2000' && char2 < '\u2100')) {
+ writer.write("\\u");
+ hhhh = Integer.toHexString(char2);
+ writer.write("0000", 0, 4 - hhhh.length());
+ writer.write(hhhh);
- char b = string.charAt(0);
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
+ char chr = string.charAt(0);
+ if ((chr >= '0' && chr <= '9') || chr == '.' || chr == '-' || chr == '+') {
- public static void testValidity(Object o) {
- if (o != null) {
- if (o instanceof Double) {
- if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
+ public static void testValidity(Object obj) {
+ if (obj != null) {
+ if (obj instanceof Double) {
+ if (((Double) obj).isInfinite() || ((Double) obj).isNaN()) {
* Make a JSON text of this JSONObject. For compactness, no whitespace
* is added. If this would not result in a syntactically correct JSON text,
* then null will be returned instead.
* Make a JSON text of this JSONObject. For compactness, no whitespace
* is added. If this would not result in a syntactically correct JSON text,
* then null will be returned instead.
*
* @return a printable, displayable, portable, transmittable
* representation of the object, beginning
*
* @return a printable, displayable, portable, transmittable
* representation of the object, beginning
* @throws JSONException If the object contains an invalid number.
*/
public String toString(int indentFactor) {
* @throws JSONException If the object contains an invalid number.
*/
public String toString(int indentFactor) {
- StringWriter w = new StringWriter();
- synchronized (w.getBuffer()) {
- return this.write(w, indentFactor, 0).toString();
+ StringWriter writer = new StringWriter();
+ synchronized (writer.getBuffer()) {
+ return this.write(writer, indentFactor, 0).toString();
* from it and its toJSONString method will be called. Otherwise, the
* value's toString method will be called, and the result will be quoted.
*
* from it and its toJSONString method will be called. Otherwise, the
* value's toString method will be called, and the result will be quoted.
*
*
* @param value The value to be serialized.
* @return a printable, displayable, transmittable
*
* @param value The value to be serialized.
* @return a printable, displayable, transmittable
- if (object instanceof LOGJSONObject || object instanceof JSONArray ||
- NULL.equals(object) || object instanceof JSONString ||
- object instanceof Byte || object instanceof Character ||
- object instanceof Short || object instanceof Integer ||
- object instanceof Long || object instanceof Boolean ||
- object instanceof Float || object instanceof Double ||
- object instanceof String) {
+ if (object instanceof LOGJSONObject || object instanceof JSONArray
+ || NULL.equals(object) || object instanceof JSONString
+ || object instanceof Byte || object instanceof Character
+ || object instanceof Short || object instanceof Integer
+ || object instanceof Long || object instanceof Boolean
+ || object instanceof Float || object instanceof Double
+ || object instanceof String) {
- objectPackageName.startsWith("java.") ||
- objectPackageName.startsWith("javax.") ||
- object.getClass().getClassLoader() == null
+ objectPackageName.startsWith("java.")
+ || objectPackageName.startsWith("javax.")
+ || object.getClass().getClassLoader() == null
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
/**
* Write the contents of the JSONObject as JSON text to a writer. For
* compactness, no whitespace is added.
/**
* Write the contents of the JSONObject as JSON text to a writer. For
* compactness, no whitespace is added.