|
| 1 | +package io.ipgeolocation.api; |
| 2 | + |
| 3 | +import org.json.JSONObject; |
| 4 | + |
| 5 | +import java.math.BigDecimal; |
| 6 | +import java.util.Objects; |
| 7 | + |
| 8 | +public class Astronomy { |
| 9 | + private final String date; |
| 10 | + private final String currentTime; |
| 11 | + private final String sunrise; |
| 12 | + private final String sunset; |
| 13 | + private final String sunStatus; |
| 14 | + private final String solarNoon; |
| 15 | + private final String dayLength; |
| 16 | + private final BigDecimal sunAltitude; |
| 17 | + private final BigDecimal sunDistance; |
| 18 | + private final BigDecimal sunAzimuth; |
| 19 | + private final String moonrise; |
| 20 | + private final String moonset; |
| 21 | + private final String moonStatus; |
| 22 | + private final BigDecimal moonAltitude; |
| 23 | + private final BigDecimal moonDistance; |
| 24 | + private final BigDecimal moonAzimuth; |
| 25 | + private final BigDecimal moonParallacticAngle; |
| 26 | + private AstronomyLocation location; |
| 27 | + private final JSONObject json; |
| 28 | + |
| 29 | + Astronomy(JSONObject json) { |
| 30 | + if (Objects.isNull(json)) { |
| 31 | + throw new IllegalArgumentException("'json' must not be null"); |
| 32 | + } |
| 33 | + |
| 34 | + if (json.isEmpty()) { |
| 35 | + throw new IllegalArgumentException("'json' must not be empty"); |
| 36 | + } |
| 37 | + |
| 38 | + this.date = json.getString("date"); |
| 39 | + this.currentTime = json.getString("current_time"); |
| 40 | + this.sunrise = json.getString("sunrise"); |
| 41 | + this.sunset = json.getString("sunset"); |
| 42 | + this.sunStatus = json.getString("sun_status"); |
| 43 | + this.solarNoon = json.getString("solar_noon"); |
| 44 | + this.dayLength = json.getString("day_length"); |
| 45 | + this.sunAltitude = json.getBigDecimal("sun_altitude"); |
| 46 | + this.sunDistance = json.getBigDecimal("sun_distance"); |
| 47 | + this.sunAzimuth = json.getBigDecimal("sun_azimuth"); |
| 48 | + this.moonrise = json.getString("moonrise"); |
| 49 | + this.moonset = json.getString("moonset"); |
| 50 | + this.moonStatus = json.getString("moon_status"); |
| 51 | + this.moonAltitude = json.getBigDecimal("moon_altitude"); |
| 52 | + this.moonDistance = json.getBigDecimal("moon_distance"); |
| 53 | + this.moonAzimuth = json.getBigDecimal("moon_azimuth"); |
| 54 | + this.moonParallacticAngle = json.getBigDecimal("moon_parallactic_angle"); |
| 55 | + |
| 56 | + if (json.has("location")) { |
| 57 | + this.location = new AstronomyLocation(json.getJSONObject("location")); |
| 58 | + } |
| 59 | + this.json = json; |
| 60 | + } |
| 61 | + |
| 62 | + public String getDate() { |
| 63 | + return date; |
| 64 | + } |
| 65 | + |
| 66 | + public String getCurrentTime() { |
| 67 | + return currentTime; |
| 68 | + } |
| 69 | + |
| 70 | + public String getSunrise() { |
| 71 | + return sunrise; |
| 72 | + } |
| 73 | + |
| 74 | + public String getSunset() { |
| 75 | + return sunset; |
| 76 | + } |
| 77 | + |
| 78 | + public String getSunStatus() { |
| 79 | + return sunStatus; |
| 80 | + } |
| 81 | + |
| 82 | + public String getSolarNoon() { |
| 83 | + return solarNoon; |
| 84 | + } |
| 85 | + |
| 86 | + public String getDayLength() { |
| 87 | + return dayLength; |
| 88 | + } |
| 89 | + |
| 90 | + public BigDecimal getSunAltitude() { |
| 91 | + return sunAltitude; |
| 92 | + } |
| 93 | + |
| 94 | + public BigDecimal getSunDistance() { |
| 95 | + return sunDistance; |
| 96 | + } |
| 97 | + |
| 98 | + public BigDecimal getSunAzimuth() { |
| 99 | + return sunAzimuth; |
| 100 | + } |
| 101 | + |
| 102 | + public String getMoonrise() { |
| 103 | + return moonrise; |
| 104 | + } |
| 105 | + |
| 106 | + public String getMoonset() { |
| 107 | + return moonset; |
| 108 | + } |
| 109 | + |
| 110 | + public String getMoonStatus() { |
| 111 | + return moonStatus; |
| 112 | + } |
| 113 | + |
| 114 | + public BigDecimal getMoonAltitude() { |
| 115 | + return moonAltitude; |
| 116 | + } |
| 117 | + |
| 118 | + public BigDecimal getMoonDistance() { |
| 119 | + return moonDistance; |
| 120 | + } |
| 121 | + |
| 122 | + public BigDecimal getMoonAzimuth() { |
| 123 | + return moonAzimuth; |
| 124 | + } |
| 125 | + |
| 126 | + public BigDecimal getMoonParallacticAngle() { |
| 127 | + return moonParallacticAngle; |
| 128 | + } |
| 129 | + |
| 130 | + public AstronomyLocation getLocation() { |
| 131 | + return location; |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public String toString() { |
| 136 | + return json.toString(2); |
| 137 | + } |
| 138 | +} |
0 commit comments