Skip to content

Commit 7cbbc47

Browse files
Merge pull request #17 from IPGeolocation/proposedv1.0.16
Proposedv1.0.16
2 parents 4a4f949 + 1e7fff7 commit 7cbbc47

22 files changed

+2844
-67
lines changed

README.md

Lines changed: 386 additions & 65 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>org.json</groupId>
4848
<artifactId>json</artifactId>
49-
<version>20230618</version>
49+
<version>20240205</version>
5050
</dependency>
5151
</dependencies>
5252

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
package io.ipgeolocation.api;
2+
3+
import org.json.JSONObject;
4+
5+
import java.math.BigDecimal;
6+
import java.util.Objects;
7+
8+
/**
9+
* The Astronomy class represents astronomical data for a specific date and location, including information
10+
* about sunrise, sunset, moonrise, moonset, sun and moon positions, and other related details.
11+
*
12+
* <p>The Astronomy class provides methods to access the information stored in the {@code Astronomy} object,
13+
* For Example, you can get the sunrise time by calling {@link Astronomy#getSunrise()}.
14+
*/
15+
public class Astronomy {
16+
private final String date;
17+
private final String currentTime;
18+
private final String sunrise;
19+
private final String sunset;
20+
private final String sunStatus;
21+
private final String solarNoon;
22+
private final String dayLength;
23+
private final BigDecimal sunAltitude;
24+
private final BigDecimal sunDistance;
25+
private final BigDecimal sunAzimuth;
26+
private final String moonrise;
27+
private final String moonset;
28+
private final String moonStatus;
29+
private final BigDecimal moonAltitude;
30+
private final BigDecimal moonDistance;
31+
private final BigDecimal moonAzimuth;
32+
private final BigDecimal moonParallacticAngle;
33+
private AstronomyLocation location;
34+
private final JSONObject json;
35+
36+
/**
37+
* Constructs an Astronomy object based on the provided JSON data.
38+
*
39+
* @param json the JSON object containing astronomical data
40+
* @throws IllegalArgumentException if the provided JSON object is null or empty
41+
*/
42+
Astronomy(JSONObject json) {
43+
if (Objects.isNull(json)) {
44+
throw new IllegalArgumentException("'json' must not be null");
45+
}
46+
47+
if (json.isEmpty()) {
48+
throw new IllegalArgumentException("'json' must not be empty");
49+
}
50+
51+
this.date = json.getString("date");
52+
this.currentTime = json.getString("current_time");
53+
this.sunrise = json.getString("sunrise");
54+
this.sunset = json.getString("sunset");
55+
this.sunStatus = json.getString("sun_status");
56+
this.solarNoon = json.getString("solar_noon");
57+
this.dayLength = json.getString("day_length");
58+
this.sunAltitude = json.getBigDecimal("sun_altitude");
59+
this.sunDistance = json.getBigDecimal("sun_distance");
60+
this.sunAzimuth = json.getBigDecimal("sun_azimuth");
61+
this.moonrise = json.getString("moonrise");
62+
this.moonset = json.getString("moonset");
63+
this.moonStatus = json.getString("moon_status");
64+
this.moonAltitude = json.getBigDecimal("moon_altitude");
65+
this.moonDistance = json.getBigDecimal("moon_distance");
66+
this.moonAzimuth = json.getBigDecimal("moon_azimuth");
67+
this.moonParallacticAngle = json.getBigDecimal("moon_parallactic_angle");
68+
69+
if (json.has("location")) {
70+
this.location = new AstronomyLocation(json.getJSONObject("location"));
71+
}
72+
this.json = json;
73+
}
74+
75+
/**
76+
* Returns the date for which astronomical data is provided.
77+
*
78+
* @return The date as String.
79+
*/
80+
public String getDate() {
81+
return date;
82+
}
83+
84+
/**
85+
* Returns the current time at the location in the format "HH:mm:ss".
86+
*
87+
* @return The current time as String.
88+
*/
89+
public String getCurrentTime() {
90+
return currentTime;
91+
}
92+
93+
/**
94+
* Returns the time of sunrise in the format "HH:mm".
95+
*
96+
* @return The time of sunrise as String.
97+
*/
98+
public String getSunrise() {
99+
return sunrise;
100+
}
101+
102+
/**
103+
* Returns the time of sunset in the format "HH:mm".
104+
*
105+
* @return The time of sunset as String.
106+
*/
107+
public String getSunset() {
108+
return sunset;
109+
}
110+
111+
/**
112+
* Returns the status of sunrise and sunset as "-", if these values are not available.
113+
*
114+
* @return The status of the sun.
115+
*/
116+
public String getSunStatus() {
117+
return sunStatus;
118+
}
119+
120+
/**
121+
* Returns the time of solar noon in the format "HH:mm".
122+
*
123+
* @return The time of solar noon as String.
124+
*/
125+
public String getSolarNoon() {
126+
return solarNoon;
127+
}
128+
129+
/**
130+
* Returns the duration of daylight in the format "HH:mm".
131+
*
132+
* @return The duration of daylight.
133+
*/
134+
public String getDayLength() {
135+
return dayLength;
136+
}
137+
138+
/**
139+
* Returns the altitude of the sun.
140+
*
141+
* @return The altitude of the sun in degrees.
142+
*/
143+
public BigDecimal getSunAltitude() {
144+
return sunAltitude;
145+
}
146+
147+
/**
148+
* Returns the distance to the sun.
149+
*
150+
* @return The distance to the sun in km.
151+
*/
152+
public BigDecimal getSunDistance() {
153+
return sunDistance;
154+
}
155+
156+
/**
157+
* Returns the azimuth of the sun.
158+
*
159+
* @return The azimuth of the sun in degrees.
160+
*/
161+
public BigDecimal getSunAzimuth() {
162+
return sunAzimuth;
163+
}
164+
165+
/**
166+
* Returns the time of moonrise in the format "HH:mm".
167+
*
168+
* @return The time of moonrise.
169+
*/
170+
public String getMoonrise() {
171+
return moonrise;
172+
}
173+
174+
/**
175+
* Returns the time of moonset in the format "HH:mm".
176+
*
177+
* @return The time of moonset.
178+
*/
179+
public String getMoonset() {
180+
return moonset;
181+
}
182+
183+
/**
184+
* Returns the status of moon rise and moon set as "-", if these values are not available.
185+
*
186+
* @return The status of the moon.
187+
*/
188+
public String getMoonStatus() {
189+
return moonStatus;
190+
}
191+
192+
/**
193+
* Returns the altitude of the moon.
194+
*
195+
* @return The altitude of the moon in degrees.
196+
*/
197+
public BigDecimal getMoonAltitude() {
198+
return moonAltitude;
199+
}
200+
201+
/**
202+
* Returns the distance to the moon.
203+
*
204+
* @return The distance to the moon in km.
205+
*/
206+
public BigDecimal getMoonDistance() {
207+
return moonDistance;
208+
}
209+
210+
/**
211+
* Returns the azimuth of the moon.
212+
*
213+
* @return The azimuth of the moon in degrees.
214+
*/
215+
public BigDecimal getMoonAzimuth() {
216+
return moonAzimuth;
217+
}
218+
219+
/**
220+
* Returns the parallactic angle of the moon.
221+
*
222+
* @return The parallactic angle of the moon in degrees.
223+
*/
224+
public BigDecimal getMoonParallacticAngle() {
225+
return moonParallacticAngle;
226+
}
227+
228+
/**
229+
* Returns the location associated with the astronomical data.
230+
*
231+
* @return The {@code AstronomyLocation} object.
232+
*/
233+
public AstronomyLocation getLocation() {
234+
return location;
235+
}
236+
237+
/**
238+
* Returns a string representation of the Astronomy object, in JSON format.
239+
*
240+
* @return A JSON string representing the astronomical data.
241+
*/
242+
@Override
243+
public String toString() {
244+
return json.toString(2);
245+
}
246+
}

0 commit comments

Comments
 (0)