-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTimezoneGeo.java
executable file
·166 lines (149 loc) · 3.88 KB
/
TimezoneGeo.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package io.ipgeolocation.api;
import java.math.BigDecimal;
import java.util.Objects;
import org.json.JSONObject;
/**
* The TimezoneGeo class represents geographic information associated with a timezone, including details such as country,
* state/province, city, latitude, and longitude.
*
* <p>The TimezoneGeo class provides methods to access the information about the {@code TimezoneGeo} object. For example,
* the {@link #getCity()} method returns the city name.
*
*/
public class TimezoneGeo {
private final String countryCode2;
private final String countryCode3;
private final String countryName;
private final String stateProvince;
private final String district;
private final String city;
private final String locality;
private final String location;
private final String zipCode;
private final BigDecimal latitude;
private final BigDecimal longitude;
private final JSONObject json;
/**
* Constructs a TimezoneGeo object based on the provided JSON data.
*
* @param json the JSON object containing geographic data
* @throws IllegalArgumentException if the provided JSON object is null or empty
*/
TimezoneGeo(JSONObject json) {
if (Objects.isNull(json)) {
throw new IllegalArgumentException("'json' must not be null");
}
if (json.isEmpty()) {
throw new IllegalArgumentException("'json' must not be empty");
}
this.countryCode2 = json.optString("country_code2");
this.countryCode3 = json.optString("country_code3");
this.countryName = json.optString("country_name", json.optString("country"));
this.stateProvince = json.optString("state_prov", json.optString("state"));
this.district = json.optString("district");
this.city = json.getString("city");
this.locality = json.optString("locality");
this.location = json.optString("location");
this.zipCode = json.optString("zipcode");
this.latitude = json.getBigDecimal("latitude");
this.longitude = json.getBigDecimal("longitude");
this.json = json;
}
/**
* Returns the two-letter country code.
*
* @return The two-letter country code as String.
*/
public String getCountryCode2() {
return countryCode2;
}
/**
* Returns the three-letter country code.
*
* @return The three-letter country code as String.
*/
public String getCountryCode3() {
return countryCode3;
}
/**
* Returns the name of the country.
*
* @return The name of the country as String.
*/
public String getCountryName() {
return countryName;
}
/**
* Returns the state or province.
*
* @return The state or province or region as String.
*/
public String getStateProvince() {
return stateProvince;
}
/**
* Returns the district.
*
* @return The district.
*/
public String getDistrict() {
return district;
}
/**
* Returns the city.
*
* @return The city.
*/
public String getCity() {
return city;
}
/**
* Returns the locality.
*
* @return The locality.
*/
public String getLocality() {
return locality;
}
/**
* Returns the specific location.
*
* @return The specific location.
*/
public String getLocation() {
return location;
}
/**
* Returns the postal code.
*
* @return The postal code as String.
*/
public String getZipCode() {
return zipCode;
}
/**
* Returns the latitude coordinate.
*
* @return The latitude coordinate as BigDecimal.
*/
public BigDecimal getLatitude() {
return latitude;
}
/**
* Returns the longitude coordinate.
*
* @return The longitude coordinate as BigDecimal.
*/
public BigDecimal getLongitude() {
return longitude;
}
/**
* Returns a string representation of the TimezoneGeo object, in JSON format.
*
* @return A JSON string representing the geographic data.
*/
@Override
public String toString() {
return json.toString(2);
}
}