You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
7 years ago
|
// 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(":");
|
||
|
}
|
||
|
}
|