|
1 | 1 | package io.ipgeolocation.api; |
2 | 2 |
|
3 | | -import java.util.Map; |
| 3 | +import java.util.Objects; |
| 4 | +import org.json.JSONObject; |
4 | 5 |
|
5 | 6 | public class UserAgentOperatingSystem { |
6 | | - private final String name; |
7 | | - private final String type; |
8 | | - private final String version; |
9 | | - private final String versionMajor; |
10 | | - |
11 | | - public UserAgentOperatingSystem(Map<String, Object> json) { |
12 | | - this.name = (String) json.get("name"); |
13 | | - this.type = (String) json.get("type"); |
14 | | - this.version = (String) json.get("version"); |
15 | | - this.versionMajor = (String) json.get("versionMajor"); |
16 | | - } |
| 7 | + private final String name; |
| 8 | + private final String type; |
| 9 | + private final String version; |
| 10 | + private final String versionMajor; |
| 11 | + private final JSONObject json; |
17 | 12 |
|
18 | | - public String getName() { |
19 | | - return name; |
| 13 | + UserAgentOperatingSystem(JSONObject json) { |
| 14 | + if (Objects.isNull(json)) { |
| 15 | + throw new IllegalArgumentException("'json' must not be null"); |
20 | 16 | } |
21 | 17 |
|
22 | | - public String getType() { |
23 | | - return type; |
| 18 | + if (json.isEmpty()) { |
| 19 | + throw new IllegalArgumentException("'json' must not be empty"); |
24 | 20 | } |
25 | 21 |
|
26 | | - public String getVersion() { |
27 | | - return version; |
28 | | - } |
| 22 | + this.name = json.getString("name"); |
| 23 | + this.type = json.getString("type"); |
| 24 | + this.version = json.getString("version"); |
| 25 | + this.versionMajor = json.getString("versionMajor"); |
| 26 | + this.json = json; |
| 27 | + } |
29 | 28 |
|
30 | | - public String getVersionMajor() { |
31 | | - return versionMajor; |
32 | | - } |
| 29 | + public String getName() { |
| 30 | + return name; |
| 31 | + } |
| 32 | + |
| 33 | + public String getType() { |
| 34 | + return type; |
| 35 | + } |
| 36 | + |
| 37 | + public String getVersion() { |
| 38 | + return version; |
| 39 | + } |
| 40 | + |
| 41 | + public String getVersionMajor() { |
| 42 | + return versionMajor; |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public String toString() { |
| 47 | + return json.toString(2); |
| 48 | + } |
33 | 49 | } |
0 commit comments