-
Notifications
You must be signed in to change notification settings - Fork 0
/
EppoValue.java
113 lines (87 loc) · 2.5 KB
/
EppoValue.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package cloud.eppo.android.dto;
import com.google.gson.JsonElement;
import java.util.List;
public class EppoValue {
private String value;
private EppoValueType type = EppoValueType.Null;
private List<String> array;
private JsonElement json;
public EppoValue() {}
public EppoValue(String value, EppoValueType type) {
this.value = value;
this.type = type;
}
public EppoValue(List<String> array) {
this.array = array;
this.type = EppoValueType.ArrayOfStrings;
}
public EppoValue(EppoValueType type) {
this.type = type;
}
public EppoValue(JsonElement json) {
this.json = json;
this.value = json.toString();
this.type = EppoValueType.JSON;
}
public static EppoValue valueOf(String value) {
return new EppoValue(value, EppoValueType.String);
}
public static EppoValue valueOf(double value) {
return new EppoValue(Double.toString(value), EppoValueType.Number);
}
public static EppoValue valueOf(boolean value) {
return new EppoValue(Boolean.toString(value), EppoValueType.Boolean);
}
public static EppoValue valueOf(List<String> value) {
return new EppoValue(value);
}
public static EppoValue valueOf(JsonElement json) {
return new EppoValue(json);
}
public static EppoValue valueOf() {
return new EppoValue(EppoValueType.Null);
}
public double doubleValue() {
return Double.parseDouble(value);
}
public String stringValue() {
return value;
}
public boolean boolValue() {
return Boolean.valueOf(value);
}
public List<String> arrayValue() {
return array;
}
public JsonElement jsonValue() {
return this.json;
}
public boolean isNumeric() {
try {
Double.parseDouble(value);
return true;
} catch (Exception e) {
return false;
}
}
public boolean isArray() {
return type == EppoValueType.ArrayOfStrings;
}
public boolean isBool() {
return type == EppoValueType.Boolean;
}
public boolean isNull() {
return type == EppoValueType.Null;
}
public boolean isJSON() {
return type == EppoValueType.JSON;
}
@Override
public String toString() {
return "EppoValue{" +
"value='" + value + '\'' +
", type=" + type +
", array=" + array +
'}';
}
}