-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSONNumber.java
67 lines (55 loc) · 1.19 KB
/
JSONNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package Yelp;
import java.math.BigDecimal;
import java.util.Map;
public class JSONNumber implements JSONValue {
private String value = "0";
/**
*
*/
public JSONNumber(double value) {
this.value = Double.toString(value);
}
/**
* @param value
*/
public JSONNumber(String value) {
this.value = value;
}
/**
* @param value
*/
public JSONNumber(long value) {
this.value = Long.toString(value);
}
/**
* @param value
*/
public JSONNumber(float value) {
this.value = Float.toString(value);
}
/**
* @param value
*/
public JSONNumber(BigDecimal value) {
this.value = value.toPlainString();
}
public JSONNumber(int value) {
this.value = Integer.toString(value);
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* (non-Javadoc)
* @see org.apache.commons.json.JSONValue#toJSON()
*/
public String toJSON() {
return value;
}
public void flattenTo(Map<String, String> map, String prefix) {
map.put(prefix, toJSON());
}
}