X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Futils%2FLOGJSONObject.java;h=0f95523406bef9a7ec62a22d5754c2339510fef1;hb=381d4ebc5e83d5fd5b62fff7e5a6fa6d582149d9;hp=bc1f44939bd67925fd00da04f56e6f116cbb41e7;hpb=632e4aaf606ca99ddc5a5cba11deb5e2ee2a90c5;p=dmaap%2Fdatarouter.git
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
index bc1f4493..0f955234 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
@@ -57,22 +57,22 @@ import org.json.JSONTokener;
* returns a value if one can be found, and throws an exception if one cannot be
* found. An opt
method returns a default value instead of throwing
* an exception, and so is useful for obtaining optional values.
- *
- * The generic get()
and opt()
methods return an
+ *
+ *
The generic get()
and opt()
methods return an
* object, which you can cast or query for type. There are also typed
* get
and opt
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.
- *
- * The put
methods add or replace values in an object. For example,
+ *
+ *
The put
methods add or replace values in an object. For example,
*
*
* myString = new JSONObject().put("JSON", "Hello, World!").toString(); *- *
- * produces the string {"JSON": "Hello, World"}
.
- *
- * The texts produced by the toString
methods strictly conform to
+ *
+ *
* produces the string {"JSON": "Hello, World"}
.
+ *
+ *
The texts produced by the toString
methods strictly conform to
* the JSON syntax rules. The constructors are more forgiving in the texts they
* will accept:
*
- * The general contract of {@code hashCode} is: + * + *
* The general contract of {@code hashCode} is: *
- * As much as is reasonably practical, the hashCode method defined by + * + *
* As much as is reasonably practical, the hashCode method defined by
* 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
@@ -234,56 +235,56 @@ public class LOGJSONObject {
/**
* Construct a JSONObject from a JSONTokener.
*
- * @param x A JSONTokener object containing the source string.
+ * @param tokener A JSONTokener object containing the source string.
* @throws JSONException If there is a syntax error in the source string
* or a duplicated key.
*/
- public LOGJSONObject(JSONTokener x) {
+ public LOGJSONObject(JSONTokener tokener) {
this();
- char c;
+ char chr;
String key;
- if (x.nextClean() != '{') {
- throw x.syntaxError("A JSONObject text must begin with '{'");
+ if (tokener.nextClean() != '{') {
+ throw tokener.syntaxError("A JSONObject text must begin with '{'");
}
for (; ; ) {
- c = x.nextClean();
- switch (c) {
+ chr = tokener.nextClean();
+ switch (chr) {
case 0:
- throw x.syntaxError("A JSONObject text must end with '}'");
+ throw tokener.syntaxError("A JSONObject text must end with '}'");
case '}':
return;
default:
- x.back();
- key = x.nextValue().toString();
+ tokener.back();
+ key = tokener.nextValue().toString();
}
-// The key is followed by ':'. We will also tolerate '=' or '=>'.
+ // The key is followed by ':'. We will also tolerate '=' or '=>'.
- c = x.nextClean();
- if (c == '=') {
- if (x.next() != '>') {
- x.back();
+ chr = tokener.nextClean();
+ if (chr == '=') {
+ if (tokener.next() != '>') {
+ tokener.back();
}
- } else if (c != ':') {
- throw x.syntaxError("Expected a ':' after a key");
+ } else if (chr != ':') {
+ throw tokener.syntaxError("Expected a ':' after a key");
}
- this.putOnce(key, x.nextValue());
+ this.putOnce(key, tokener.nextValue());
-// Pairs are separated by ','. We will also tolerate ';'.
+ // Pairs are separated by ','. We will also tolerate ';'.
- switch (x.nextClean()) {
+ switch (tokener.nextClean()) {
case ';':
case ',':
- if (x.nextClean() == '}') {
+ if (tokener.nextClean() == '}') {
return;
}
- x.back();
+ tokener.back();
break;
case '}':
return;
default:
- throw x.syntaxError("Expected a ',' or '}'");
+ throw tokener.syntaxError("Expected a ',' or '}'");
}
}
}
@@ -293,17 +294,17 @@ public class LOGJSONObject {
*
* @param map A map object that can be used to initialize the contents of
* the JSONObject.
- * @throws JSONException
+ * @throws JSONException json exception
*/
public LOGJSONObject(Map
- * The key is formed by removing the * The key is formed by removing the
- * For example, if an object has a method named * For example, if an object has a method named
- * If only one value is accumulated that is not a JSONArray, then the
+ *
+ * * 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.
*
@@ -388,8 +389,8 @@ public class LOGJSONObject {
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
- throw new JSONException(JSON_OBJECT_CONST + key +
- "] is not a JSONArray.");
+ throw new JSONException(JSON_OBJECT_CONST + key
+ + "] is not a JSONArray.");
}
return this;
}
@@ -398,17 +399,17 @@ public class LOGJSONObject {
* Produce a string from a double. The string "null" will be returned if
* the number is not finite.
*
- * @param d A double.
+ * @param dub A double.
* @return A String.
*/
- 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)) {
return "null";
}
-// Shave off trailing zeros and decimal point, if possible.
+ // Shave off trailing zeros and decimal point, if possible.
- String string = Double.toString(d);
+ String string = Double.toString(dub);
if (string.indexOf('.') > 0 && string.indexOf('e') < 0
&& string.indexOf('E') < 0) {
while (string.endsWith("0")) {
@@ -434,8 +435,8 @@ public class LOGJSONObject {
}
Object object = this.opt(key);
if (object == null) {
- throw new JSONException(JSON_OBJECT_CONST + quote(key) +
- "] not found.");
+ throw new JSONException(JSON_OBJECT_CONST + quote(key)
+ + "] not found.");
}
return object;
}
@@ -449,17 +450,17 @@ public class LOGJSONObject {
*/
public boolean getBoolean(String key) {
Object object = this.get(key);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- "false".equalsIgnoreCase((String) object))) {
+ if (object.equals(Boolean.FALSE)
+ || (object instanceof String
+ && "false".equalsIgnoreCase((String) object))) {
return false;
- } 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))) {
return true;
}
- throw new JSONException(JSON_OBJECT_CONST + quote(key) +
- "] is not a Boolean.");
+ throw new JSONException(JSON_OBJECT_CONST + quote(key)
+ + "] is not a Boolean.");
}
/**
@@ -515,8 +516,8 @@ public class LOGJSONObject {
if (object instanceof JSONArray) {
return (JSONArray) object;
}
- throw new JSONException(JSON_OBJECT_CONST + quote(key) +
- "] is not a JSONArray.");
+ throw new JSONException(JSON_OBJECT_CONST + quote(key)
+ + "] is not a JSONArray.");
}
/**
@@ -532,8 +533,8 @@ public class LOGJSONObject {
if (object instanceof LOGJSONObject) {
return (LOGJSONObject) object;
}
- throw new JSONException(JSON_OBJECT_CONST + quote(key) +
- "] is not a JSONObject.");
+ throw new JSONException(JSON_OBJECT_CONST + quote(key)
+ + "] is not a JSONObject.");
}
/**
@@ -568,10 +569,10 @@ public class LOGJSONObject {
}
Iterator
- * Warning: This method assumes that the data structure is acyclical.
+ *
+ * * Warning: This method assumes that the data structure is acyclical.
*
* @return a printable, displayable, portable, transmittable
* representation of the object, beginning
@@ -1150,8 +1155,8 @@ public class LOGJSONObject {
/**
* Make a prettyprinted JSON text of this JSONObject.
- *
- * Warning: This method assumes that the data structure is acyclical.
+ *
+ * * Warning: This method assumes that the data structure is acyclical.
*
* @param indentFactor The number of spaces to add to each level of
* indentation.
@@ -1162,9 +1167,9 @@ public class LOGJSONObject {
* @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();
}
}
@@ -1180,8 +1185,7 @@ public class LOGJSONObject {
* from it and its toJSONString method will be called. Otherwise, the
* value's toString method will be called, and the result will be quoted.
*
- *
- * Warning: This method assumes that the data structure is acyclical.
+ * * Warning: This method assumes that the data structure is acyclical.
*
* @param value The value to be serialized.
* @return a printable, displayable, transmittable
@@ -1244,13 +1248,13 @@ public class LOGJSONObject {
if (object == null) {
return NULL;
}
- 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) {
return object;
}
@@ -1268,9 +1272,9 @@ public class LOGJSONObject {
? objectPackage.getName()
: "";
if (
- objectPackageName.startsWith("java.") ||
- objectPackageName.startsWith("javax.") ||
- object.getClass().getClassLoader() == null
+ objectPackageName.startsWith("java.")
+ || objectPackageName.startsWith("javax.")
+ || object.getClass().getClassLoader() == null
) {
return object.toString();
}
@@ -1300,13 +1304,13 @@ public class LOGJSONObject {
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
- Object o;
+ Object obj;
try {
- o = ((JSONString) value).toJSONString();
+ obj = ((JSONString) value).toJSONString();
} catch (Exception e) {
throw new JSONException(e);
}
- writer.write(o != null ? o.toString() : quote(value.toString()));
+ writer.write(obj != null ? obj.toString() : quote(value.toString()));
} else {
quote(value.toString(), writer);
}
@@ -1322,14 +1326,13 @@ public class LOGJSONObject {
/**
* Write the contents of the JSONObject as JSON text to a writer. For
* compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
+ *
+ * * Warning: This method assumes that the data structure is acyclical.
*
* @return The writer.
- * @throws JSONException
+ * @throws JSONException JSON exception
*/
- Writer write(Writer writer, int indentFactor, int indent)
- {
+ Writer write(Writer writer, int indentFactor, int indent) {
try {
boolean commanate = false;
final int length = this.length();
@@ -1347,7 +1350,6 @@ public class LOGJSONObject {
} else if (length != 0) {
final int newindent = indent + indentFactor;
while (keys.hasNext()) {
- Object key = keys.next();
if (commanate) {
writer.write(',');
}
@@ -1355,6 +1357,7 @@ public class LOGJSONObject {
writer.write('\n');
}
indent(writer, newindent);
+ Object key = keys.next();
writer.write(quote(key.toString()));
writer.write(':');
if (indentFactor > 0) {
"get"
or "is"
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.
- * "get"
or "is"
prefix.
+ *
+ * "get"
or "is"
prefix.
* If the second remaining character is not upper case, then the first
* character is converted to lower case.
- * "getName"
, and
+ *
+ * "getName"
, and
* if the result of calling object.getName()
is "Larry Fine"
,
* then the JSONObject will contain "name": "Larry Fine"
.
*
@@ -339,8 +340,8 @@ public class LOGJSONObject {
* 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.
- *