Skip to content

Commit 886abdc

Browse files
committed
Pass a JSONObject instead of a Map in the constructor. Save 'json' to return as String.
1 parent fdc390e commit 886abdc

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed
Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
package io.ipgeolocation.api;
22

3-
import java.util.Map;
3+
import java.util.Objects;
4+
import org.json.JSONObject;
45

56
public class UserAgentDevice {
6-
private final String name;
7-
private final String type;
8-
private final String brand;
9-
private final String cpu;
10-
11-
public UserAgentDevice(Map<String, Object> json) {
12-
this.name = (String) json.get("name");
13-
this.type = (String) json.get("type");
14-
this.brand = (String) json.get("brand");
15-
this.cpu = (String) json.get("CPU");
16-
}
7+
private final String name;
8+
private final String type;
9+
private final String brand;
10+
private final String cpu;
11+
private final JSONObject json;
1712

18-
public String getName() {
19-
return name;
13+
UserAgentDevice(JSONObject json) {
14+
if (Objects.isNull(json)) {
15+
throw new IllegalArgumentException("'json' must not be null");
2016
}
2117

22-
public String getType() {
23-
return type;
18+
if (json.isEmpty()) {
19+
throw new IllegalArgumentException("'json' must not be empty");
2420
}
2521

26-
public String getBrand() {
27-
return brand;
28-
}
22+
this.name = json.getString("name");
23+
this.type = json.getString("type");
24+
this.brand = json.getString("brand");
25+
this.cpu = json.getString("cpu");
26+
this.json = json;
27+
}
2928

30-
public String getCpu() {
31-
return cpu;
32-
}
29+
public String getName() {
30+
return name;
31+
}
32+
33+
public String getType() {
34+
return type;
35+
}
36+
37+
public String getBrand() {
38+
return brand;
39+
}
40+
41+
public String getCpu() {
42+
return cpu;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return json.toString(2);
48+
}
3349
}

0 commit comments

Comments
 (0)