Compare commits

...

2 commits

Author SHA1 Message Date
28286df814
Add getTwilightTimeProvider to providers by name
And fix eclipse indentation
2024-09-24 18:40:35 +02:00
31d6873249
Actually, this name is better 2024-09-24 18:39:58 +02:00
3 changed files with 19 additions and 8 deletions

View file

@ -3,6 +3,8 @@ package eu.m724.wtapi.provider;
import eu.m724.wtapi.provider.exception.NoSuchProviderException; import eu.m724.wtapi.provider.exception.NoSuchProviderException;
import eu.m724.wtapi.provider.thunder.ThunderProvider; import eu.m724.wtapi.provider.thunder.ThunderProvider;
import eu.m724.wtapi.provider.thunder.impl.blitzortung.BlitzortungProvider; import eu.m724.wtapi.provider.thunder.impl.blitzortung.BlitzortungProvider;
import eu.m724.wtapi.provider.twilight.ApproximateTwilightTimeProvider;
import eu.m724.wtapi.provider.twilight.TwilightTimeProvider;
import eu.m724.wtapi.provider.weather.WeatherProvider; import eu.m724.wtapi.provider.weather.WeatherProvider;
import eu.m724.wtapi.provider.weather.impl.openweathermap.OpenWeatherMapProvider; import eu.m724.wtapi.provider.weather.impl.openweathermap.OpenWeatherMapProvider;
@ -10,8 +12,8 @@ public class Providers {
public static ThunderProvider getThunderProvider(String name, String apiKey) throws NoSuchProviderException { public static ThunderProvider getThunderProvider(String name, String apiKey) throws NoSuchProviderException {
switch (name.toLowerCase()) { switch (name.toLowerCase()) {
case "blitzortung": case "blitzortung":
return new BlitzortungProvider(); return new BlitzortungProvider();
} }
throw new NoSuchProviderException(); throw new NoSuchProviderException();
@ -19,8 +21,17 @@ public class Providers {
public static WeatherProvider getWeatherProvider(String name, String apiKey) throws NoSuchProviderException { public static WeatherProvider getWeatherProvider(String name, String apiKey) throws NoSuchProviderException {
switch (name.toLowerCase()) { switch (name.toLowerCase()) {
case "openweathermap": case "openweathermap":
return new OpenWeatherMapProvider(apiKey); return new OpenWeatherMapProvider(apiKey);
}
throw new NoSuchProviderException();
}
public static TwilightTimeProvider getTwilightTimeProvider(String name, String apiKey) throws NoSuchProviderException {
switch (name.toLowerCase()) {
case "approximate":
return new ApproximateTwilightTimeProvider();
} }
throw new NoSuchProviderException(); throw new NoSuchProviderException();

View file

@ -13,7 +13,7 @@ import static java.lang.Math.*;
* Usually off by a few minutes, except the Poles which, during polar days, are up to few hours inaccurate * Usually off by a few minutes, except the Poles which, during polar days, are up to few hours inaccurate
* Adapted from: <a href="https://gml.noaa.gov/grad/solcalc/solareqns.PDF">https://gml.noaa.gov/grad/solcalc/solareqns.PDF</a> * Adapted from: <a href="https://gml.noaa.gov/grad/solcalc/solareqns.PDF">https://gml.noaa.gov/grad/solcalc/solareqns.PDF</a>
*/ */
public class SimpleTwilightTimeProvider extends TwilightTimeProvider { public class ApproximateTwilightTimeProvider extends TwilightTimeProvider {
@Override @Override
public Twilight calculateTwilightTime(LocalDate date, Coordinates coordinates) { public Twilight calculateTwilightTime(LocalDate date, Coordinates coordinates) {
int dayOfYear = date.getDayOfYear() - 1; // -1 because we have to start from zero int dayOfYear = date.getDayOfYear() - 1; // -1 because we have to start from zero

View file

@ -2,13 +2,13 @@ package eu.m724.wtapi.twilight;
import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Coordinates;
import eu.m724.wtapi.object.Twilight; import eu.m724.wtapi.object.Twilight;
import eu.m724.wtapi.provider.twilight.SimpleTwilightTimeProvider; import eu.m724.wtapi.provider.twilight.ApproximateTwilightTimeProvider;
import eu.m724.wtapi.provider.twilight.TwilightTimeProvider; import eu.m724.wtapi.provider.twilight.TwilightTimeProvider;
import org.junit.Test; import org.junit.Test;
import java.time.LocalDate; import java.time.LocalDate;
public class SimpleTwilightTimeTest { public class ApproximateTwilightTimeTest {
/** /**
* Acceptable discrepancy in minutes * Acceptable discrepancy in minutes
*/ */
@ -16,7 +16,7 @@ public class SimpleTwilightTimeTest {
@Test @Test
public void approximateTest() { public void approximateTest() {
TwilightTimeProvider provider = new SimpleTwilightTimeProvider(); TwilightTimeProvider provider = new ApproximateTwilightTimeProvider();
testLocation(provider, 26, 6, 2023, 53.123394, 23.0864867, 122, 1139); testLocation(provider, 26, 6, 2023, 53.123394, 23.0864867, 122, 1139);
testLocation(provider, 13, 11, 2040, 45.432427, -122.3899276, 907, 1481); testLocation(provider, 13, 11, 2040, 45.432427, -122.3899276, 907, 1481);