Reviewed By: mbouaziz Differential Revision: D7859180 fbshipit-source-id: e3ff89bmaster
parent
c1aac1e089
commit
f2fa8cf0e0
@ -0,0 +1,17 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package libraries.marauder.analytics.utils.json;
|
||||
|
||||
public class JsonArray implements JsonType {
|
||||
|
||||
public StringBuilder array = new StringBuilder("[");
|
||||
|
||||
|
||||
public void addStringEntry(String value) {
|
||||
if (array.length() != 1) {
|
||||
array.append(",");
|
||||
}
|
||||
JsonUtils.serialize(array, value);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package libraries.marauder.analytics.utils.json;
|
||||
|
||||
public class JsonMap implements JsonType {
|
||||
|
||||
public StringBuilder map = new StringBuilder("{");
|
||||
|
||||
public void addEntry(String key, JsonType value) {
|
||||
if (!JsonUtils.isValidInputType(value)) {
|
||||
//throw new IllegalStateException("illegal input type " + value);
|
||||
}
|
||||
|
||||
addKeyToMap(key);
|
||||
map.append(value.toString());
|
||||
}
|
||||
|
||||
public void addEntry(String key, String value) {
|
||||
addKeyToMap(key);
|
||||
JsonUtils.serialize(map, value);
|
||||
}
|
||||
|
||||
public void addEntry(String key, long value) {
|
||||
addKeyToMap(key);
|
||||
JsonUtils.serialize(map, value);
|
||||
}
|
||||
|
||||
public void addEntry(String key, double value) {
|
||||
addKeyToMap(key);
|
||||
JsonUtils.serialize(map, value);
|
||||
}
|
||||
|
||||
public void addEntry(String key, boolean value) {
|
||||
addKeyToMap(key);
|
||||
JsonUtils.serialize(map, value);
|
||||
}
|
||||
|
||||
public void addEntry(String key, Object value) {
|
||||
addKeyToMap(key);
|
||||
JsonUtils.serialize(map, value);
|
||||
}
|
||||
|
||||
|
||||
private void addKeyToMap(String key) {
|
||||
if (map.length() != 1) {
|
||||
map.append(",");
|
||||
}
|
||||
|
||||
JsonUtils.serialize(map, key);
|
||||
map.append(":");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package libraries.marauder.analytics.utils.json;
|
||||
|
||||
public class JsonString implements JsonType {
|
||||
|
||||
public String array;
|
||||
|
||||
public JsonString(String input) {
|
||||
array = JsonUtils.serialize(input).toString();
|
||||
}
|
||||
|
||||
public JsonString(long input) {
|
||||
array = JsonUtils.serialize(input);
|
||||
}
|
||||
|
||||
public JsonString(double input) {
|
||||
array = JsonUtils.serialize(input);
|
||||
}
|
||||
|
||||
public JsonString(boolean input) {
|
||||
array = JsonUtils.serialize(input);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package libraries.marauder.analytics.utils.json;
|
||||
|
||||
public interface JsonType {
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package libraries.marauder.analytics.utils.json;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
private static void escape(StringBuilder builder, String input) {
|
||||
for (Character c : input.toCharArray()) {
|
||||
if (Character.getType(c) == Character.CONTROL) {
|
||||
builder.append(String.format("\\u%04x", (int)c));
|
||||
} else if (c == '\\' || c== '\"') {
|
||||
builder.append('\\').append(c);
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static StringBuilder serialize(String input) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
serialize(stringBuilder, input);
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
public static String serialize(long input) {
|
||||
return String.valueOf(input);
|
||||
}
|
||||
|
||||
public static String serialize(boolean input) {
|
||||
return String.valueOf(input);
|
||||
}
|
||||
|
||||
public static String serialize(double input) {
|
||||
return String.valueOf(input);
|
||||
}
|
||||
|
||||
public static String serialize(Object input) {
|
||||
if (input instanceof Integer
|
||||
|| input instanceof Float
|
||||
|| input instanceof Long
|
||||
|| input instanceof Double
|
||||
|| input instanceof Boolean
|
||||
|| input instanceof Byte
|
||||
|| input instanceof Short) {
|
||||
return "";//String.valueOf(input);
|
||||
} else {
|
||||
return "";// serialize(String.valueOf(input)).toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void serialize(StringBuilder out, String input) {
|
||||
if (input == null) {
|
||||
out.append("null");
|
||||
} else {
|
||||
out.append("\"");
|
||||
escape(out, input);
|
||||
out.append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
public static void serialize(StringBuilder out, long input) {
|
||||
out.append(serialize(input));
|
||||
}
|
||||
|
||||
public static void serialize(StringBuilder out, boolean input) {
|
||||
out.append(serialize(input));
|
||||
}
|
||||
|
||||
public static void serialize(StringBuilder out, double input) {
|
||||
out.append(serialize(input));
|
||||
}
|
||||
|
||||
public static void serialize(StringBuilder out, Object input) {
|
||||
out.append(serialize(input));
|
||||
}
|
||||
|
||||
public static boolean isValidInputType(Object value) {
|
||||
if (value instanceof JsonString ||
|
||||
value instanceof JsonArray ||
|
||||
value instanceof JsonMap) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1 +1,15 @@
|
||||
codetoanalyze/java/performance/ArrayCost.java, boolean ArrayCost.isPowOfTwo_FP(int), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/ArrayCost.java, void ArrayCost.ArrayCost_FP(int,int[]), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonArray.java, void JsonArray.addStringEntry(String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,JsonType), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,Object), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,boolean), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,double), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addEntry(String,long), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonMap.java, void JsonMap.addKeyToMap(String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonString.java, JsonString.<init>(String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonUtils.java, StringBuilder JsonUtils.serialize(String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonUtils.java, void JsonUtils.escape(StringBuilder,String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
codetoanalyze/java/performance/JsonUtils.java, void JsonUtils.escape(StringBuilder,String), 1, BUFFER_OVERRUN_U5, ERROR, [Unknown value from: char[] String.toCharArray(),Assignment,ArrayAccess: Offset: [-oo, +oo] Size: [0, +oo]]
|
||||
codetoanalyze/java/performance/JsonUtils.java, void JsonUtils.serialize(StringBuilder,String), 0, INFINITE_EXECUTION_TIME_CALL, ERROR, []
|
||||
|
Loading…
Reference in new issue