|
1 | 1 | package io.ipgeolocation.api; |
2 | 2 |
|
3 | 3 | import java.math.BigDecimal; |
4 | | -import java.util.Map; |
| 4 | +import java.util.Objects; |
| 5 | +import org.json.JSONObject; |
5 | 6 |
|
6 | 7 | public class GeolocationTimezone { |
7 | | - private final String name; |
8 | | - private final Integer offset; |
9 | | - private final String currentTime; |
10 | | - private final BigDecimal currentTimeUnix; |
11 | | - private final Boolean isDST; |
12 | | - private final Integer dstSavings; |
13 | | - |
14 | | - GeolocationTimezone(Map<String, Object> json) { |
15 | | - this.name = (String) json.get("name"); |
16 | | - this.offset = (Integer) json.get("offset"); |
17 | | - this.currentTime = (String) json.get("current_time"); |
18 | | - this.currentTimeUnix = (BigDecimal) json.get("current_time_unix"); |
19 | | - this.isDST = (Boolean) json.get("is_dst"); |
20 | | - this.dstSavings = (Integer) json.get("dst_savings"); |
| 8 | + private final String name; |
| 9 | + private final int offset; |
| 10 | + private final String currentTime; |
| 11 | + private final BigDecimal currentTimeUnix; |
| 12 | + private final boolean dst; |
| 13 | + private final int dstSavings; |
| 14 | + private final JSONObject json; |
| 15 | + |
| 16 | + GeolocationTimezone(JSONObject json) { |
| 17 | + if (Objects.isNull(json)) { |
| 18 | + throw new IllegalArgumentException("'json' must not be null"); |
21 | 19 | } |
22 | 20 |
|
23 | | - public String getName() { |
24 | | - return name; |
25 | | - } |
26 | | - |
27 | | - public Integer getOffset() { |
28 | | - return offset; |
29 | | - } |
30 | | - |
31 | | - public String getCurrentTime() { |
32 | | - return currentTime; |
33 | | - } |
34 | | - |
35 | | - public BigDecimal getCurrentTimeUnix() { |
36 | | - return currentTimeUnix; |
37 | | - } |
38 | | - |
39 | | - public Boolean isDST() { |
40 | | - return isDST; |
41 | | - } |
42 | | - |
43 | | - public Integer getDSTSavings() { |
44 | | - return dstSavings; |
| 21 | + if (json.isEmpty()) { |
| 22 | + throw new IllegalArgumentException("'json' must not be empty"); |
45 | 23 | } |
46 | 24 |
|
| 25 | + this.name = json.getString("name"); |
| 26 | + this.offset = json.getInt("offset"); |
| 27 | + this.currentTime = json.getString("current_time"); |
| 28 | + this.currentTimeUnix = json.getBigDecimal("current_time_unix"); |
| 29 | + this.dst = json.getBoolean("is_dst"); |
| 30 | + this.dstSavings = json.getInt("dst_savings"); |
| 31 | + this.json = json; |
| 32 | + } |
| 33 | + |
| 34 | + public String getName() { |
| 35 | + return name; |
| 36 | + } |
| 37 | + |
| 38 | + public int getOffset() { |
| 39 | + return offset; |
| 40 | + } |
| 41 | + |
| 42 | + public String getCurrentTime() { |
| 43 | + return currentTime; |
| 44 | + } |
| 45 | + |
| 46 | + public BigDecimal getCurrentTimeUnix() { |
| 47 | + return currentTimeUnix; |
| 48 | + } |
| 49 | + |
| 50 | + public boolean isDst() { |
| 51 | + return dst; |
| 52 | + } |
| 53 | + |
| 54 | + public int getDstSavings() { |
| 55 | + return dstSavings; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public String toString() { |
| 60 | + return json.toString(2); |
| 61 | + } |
47 | 62 | } |
0 commit comments