From 7d6e0e107708c3a08689f8fbb2372fbdc4173c79 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Fri, 21 Jun 2024 16:54:54 +0200 Subject: [PATCH] reorg --- .classpath | 17 +++++++++++ .project | 11 +++++++ .../eu/m724/wtapi/provider/Providers.java | 29 +++++++++++++++++++ .../exception/NoSuchProviderException.java | 10 +++++++ .../thunder/ThunderProvider.java | 2 +- .../impl/blitzortung/BlitzortungProvider.java | 4 +-- .../BlitzortungWebsocketClient.java | 2 +- .../thunder/impl/blitzortung/TimedStrike.java | 2 +- .../{ => weather}/WeatherProvider.java | 2 +- .../openweathermap/OWMResponseConverter.java | 2 +- .../OpenWeatherMapProvider.java | 4 +-- .../m724/wtapi/thunder/BlitzortungTest.java | 3 +- .../wtapi/thunder/MockThunderProvider.java | 3 +- .../wtapi/thunder/ThunderProviderTest.java | 1 + .../wtapi/weather/MockWeatherProvider.java | 2 +- .../wtapi/weather/OpenWeatherMapTest.java | 4 +-- .../eu/m724/wtapi/weather/ProviderTest.java | 2 +- 17 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 src/main/java/eu/m724/wtapi/provider/Providers.java create mode 100644 src/main/java/eu/m724/wtapi/provider/exception/NoSuchProviderException.java rename src/main/java/eu/m724/wtapi/{ => provider}/thunder/ThunderProvider.java (95%) rename src/main/java/eu/m724/wtapi/{ => provider}/thunder/impl/blitzortung/BlitzortungProvider.java (95%) rename src/main/java/eu/m724/wtapi/{ => provider}/thunder/impl/blitzortung/BlitzortungWebsocketClient.java (97%) rename src/main/java/eu/m724/wtapi/{ => provider}/thunder/impl/blitzortung/TimedStrike.java (85%) rename src/main/java/eu/m724/wtapi/provider/{ => weather}/WeatherProvider.java (97%) rename src/main/java/eu/m724/wtapi/provider/{ => weather}/impl/openweathermap/OWMResponseConverter.java (99%) rename src/main/java/eu/m724/wtapi/provider/{ => weather}/impl/openweathermap/OpenWeatherMapProvider.java (96%) diff --git a/.classpath b/.classpath index 7a9a105..df66b20 100644 --- a/.classpath +++ b/.classpath @@ -36,5 +36,22 @@ + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index 5f80782..89171fe 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1718972143313 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/src/main/java/eu/m724/wtapi/provider/Providers.java b/src/main/java/eu/m724/wtapi/provider/Providers.java new file mode 100644 index 0000000..4e98afc --- /dev/null +++ b/src/main/java/eu/m724/wtapi/provider/Providers.java @@ -0,0 +1,29 @@ +package eu.m724.wtapi.provider; + +import eu.m724.wtapi.provider.exception.NoSuchProviderException; +import eu.m724.wtapi.provider.thunder.ThunderProvider; +import eu.m724.wtapi.provider.thunder.impl.blitzortung.BlitzortungProvider; +import eu.m724.wtapi.provider.weather.WeatherProvider; +import eu.m724.wtapi.provider.weather.impl.openweathermap.OpenWeatherMapProvider; + +public class Providers { + + public static ThunderProvider getThunderProvider(String name, String apiKey) throws NoSuchProviderException { + switch (name.toLowerCase()) { + case "blitzortung": + return new BlitzortungProvider(); + } + + throw new NoSuchProviderException(); + } + + public static WeatherProvider getWeatherProvider(String name, String apiKey) throws NoSuchProviderException { + switch (name.toLowerCase()) { + case "openweathermap": + return new OpenWeatherMapProvider(apiKey); + } + + throw new NoSuchProviderException(); + } + +} diff --git a/src/main/java/eu/m724/wtapi/provider/exception/NoSuchProviderException.java b/src/main/java/eu/m724/wtapi/provider/exception/NoSuchProviderException.java new file mode 100644 index 0000000..621a4cb --- /dev/null +++ b/src/main/java/eu/m724/wtapi/provider/exception/NoSuchProviderException.java @@ -0,0 +1,10 @@ +package eu.m724.wtapi.provider.exception; + +/** + * thrown when there's no known provider with that name + */ +public class NoSuchProviderException extends Exception { + + private static final long serialVersionUID = -2740598348303023762L; + +} diff --git a/src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java b/src/main/java/eu/m724/wtapi/provider/thunder/ThunderProvider.java similarity index 95% rename from src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java rename to src/main/java/eu/m724/wtapi/provider/thunder/ThunderProvider.java index 18f986c..ba209c5 100644 --- a/src/main/java/eu/m724/wtapi/thunder/ThunderProvider.java +++ b/src/main/java/eu/m724/wtapi/provider/thunder/ThunderProvider.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.thunder; +package eu.m724.wtapi.provider.thunder; import java.util.function.Consumer; diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungProvider.java similarity index 95% rename from src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java rename to src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungProvider.java index f3679e1..466996a 100644 --- a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungProvider.java +++ b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungProvider.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.thunder.impl.blitzortung; +package eu.m724.wtapi.provider.thunder.impl.blitzortung; import java.util.ArrayList; import java.util.concurrent.CopyOnWriteArrayList; @@ -6,7 +6,7 @@ import java.util.function.Consumer; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.provider.exception.ProviderException; -import eu.m724.wtapi.thunder.ThunderProvider; +import eu.m724.wtapi.provider.thunder.ThunderProvider; public class BlitzortungProvider extends ThunderProvider { BlitzortungWebsocketClient websocketClient = new BlitzortungWebsocketClient(this); diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungWebsocketClient.java similarity index 97% rename from src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java rename to src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungWebsocketClient.java index 9b39322..bdb7bef 100644 --- a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/BlitzortungWebsocketClient.java +++ b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/BlitzortungWebsocketClient.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.thunder.impl.blitzortung; +package eu.m724.wtapi.provider.thunder.impl.blitzortung; import java.net.URI; import java.util.ArrayList; diff --git a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/TimedStrike.java similarity index 85% rename from src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java rename to src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/TimedStrike.java index faa245f..00580ff 100644 --- a/src/main/java/eu/m724/wtapi/thunder/impl/blitzortung/TimedStrike.java +++ b/src/main/java/eu/m724/wtapi/provider/thunder/impl/blitzortung/TimedStrike.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.thunder.impl.blitzortung; +package eu.m724.wtapi.provider.thunder.impl.blitzortung; import eu.m724.wtapi.object.Coordinates; diff --git a/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java b/src/main/java/eu/m724/wtapi/provider/weather/WeatherProvider.java similarity index 97% rename from src/main/java/eu/m724/wtapi/provider/WeatherProvider.java rename to src/main/java/eu/m724/wtapi/provider/weather/WeatherProvider.java index c837843..24b8eda 100644 --- a/src/main/java/eu/m724/wtapi/provider/WeatherProvider.java +++ b/src/main/java/eu/m724/wtapi/provider/weather/WeatherProvider.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.provider; +package eu.m724.wtapi.provider.weather; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OWMResponseConverter.java b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java similarity index 99% rename from src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OWMResponseConverter.java rename to src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java index 5426a7e..c1e57b9 100644 --- a/src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OWMResponseConverter.java +++ b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OWMResponseConverter.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.provider.impl.openweathermap; +package eu.m724.wtapi.provider.weather.impl.openweathermap; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; diff --git a/src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OpenWeatherMapProvider.java b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OpenWeatherMapProvider.java similarity index 96% rename from src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OpenWeatherMapProvider.java rename to src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OpenWeatherMapProvider.java index c78eedf..eabf18a 100644 --- a/src/main/java/eu/m724/wtapi/provider/impl/openweathermap/OpenWeatherMapProvider.java +++ b/src/main/java/eu/m724/wtapi/provider/weather/impl/openweathermap/OpenWeatherMapProvider.java @@ -1,4 +1,4 @@ -package eu.m724.wtapi.provider.impl.openweathermap; +package eu.m724.wtapi.provider.weather.impl.openweathermap; import java.net.ProxySelector; import java.net.URI; @@ -15,11 +15,11 @@ import com.google.gson.JsonParser; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Weather; -import eu.m724.wtapi.provider.WeatherProvider; import eu.m724.wtapi.provider.exception.AuthorizationException; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.QuotaExceededException; import eu.m724.wtapi.provider.exception.ServerProviderException; +import eu.m724.wtapi.provider.weather.WeatherProvider; public class OpenWeatherMapProvider extends WeatherProvider { private String apiKey; diff --git a/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java b/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java index e154aaa..1890941 100644 --- a/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java +++ b/src/test/java/eu/m724/wtapi/thunder/BlitzortungTest.java @@ -5,7 +5,8 @@ import java.util.ArrayList; import org.junit.Test; import eu.m724.wtapi.object.Coordinates; -import eu.m724.wtapi.thunder.impl.blitzortung.BlitzortungProvider; +import eu.m724.wtapi.provider.thunder.ThunderProvider; +import eu.m724.wtapi.provider.thunder.impl.blitzortung.BlitzortungProvider; public class BlitzortungTest { @Test diff --git a/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java b/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java index 5cdb950..8272982 100644 --- a/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java +++ b/src/test/java/eu/m724/wtapi/thunder/MockThunderProvider.java @@ -6,7 +6,8 @@ import java.util.function.Consumer; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.provider.exception.ProviderException; -import eu.m724.wtapi.thunder.impl.blitzortung.TimedStrike; +import eu.m724.wtapi.provider.thunder.ThunderProvider; +import eu.m724.wtapi.provider.thunder.impl.blitzortung.TimedStrike; public class MockThunderProvider extends ThunderProvider { ArrayList> strikeHandlers = new ArrayList<>(); diff --git a/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java b/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java index f1670ce..baf73bd 100644 --- a/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java +++ b/src/test/java/eu/m724/wtapi/thunder/ThunderProviderTest.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import org.junit.Test; import eu.m724.wtapi.object.Coordinates; +import eu.m724.wtapi.provider.thunder.ThunderProvider; public class ThunderProviderTest { @Test diff --git a/src/test/java/eu/m724/wtapi/weather/MockWeatherProvider.java b/src/test/java/eu/m724/wtapi/weather/MockWeatherProvider.java index a9bfa67..3e74bd0 100644 --- a/src/test/java/eu/m724/wtapi/weather/MockWeatherProvider.java +++ b/src/test/java/eu/m724/wtapi/weather/MockWeatherProvider.java @@ -3,10 +3,10 @@ package eu.m724.wtapi.weather; import java.util.concurrent.CompletableFuture; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Weather; -import eu.m724.wtapi.provider.WeatherProvider; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.QuotaExceededException; import eu.m724.wtapi.provider.exception.ServerProviderException; +import eu.m724.wtapi.provider.weather.WeatherProvider; public class MockWeatherProvider extends WeatherProvider { private boolean faulty; diff --git a/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java b/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java index 7682e88..506a4c2 100644 --- a/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java +++ b/src/test/java/eu/m724/wtapi/weather/OpenWeatherMapTest.java @@ -9,8 +9,8 @@ import org.junit.Test; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Weather; -import eu.m724.wtapi.provider.WeatherProvider; -import eu.m724.wtapi.provider.impl.openweathermap.OpenWeatherMapProvider; +import eu.m724.wtapi.provider.weather.WeatherProvider; +import eu.m724.wtapi.provider.weather.impl.openweathermap.OpenWeatherMapProvider; public class OpenWeatherMapTest { @Test diff --git a/src/test/java/eu/m724/wtapi/weather/ProviderTest.java b/src/test/java/eu/m724/wtapi/weather/ProviderTest.java index 912be8f..cee26a7 100644 --- a/src/test/java/eu/m724/wtapi/weather/ProviderTest.java +++ b/src/test/java/eu/m724/wtapi/weather/ProviderTest.java @@ -12,9 +12,9 @@ import org.junit.Test; import eu.m724.wtapi.object.Coordinates; import eu.m724.wtapi.object.Weather; -import eu.m724.wtapi.provider.WeatherProvider; import eu.m724.wtapi.provider.exception.ProviderException; import eu.m724.wtapi.provider.exception.QuotaExceededException; +import eu.m724.wtapi.provider.weather.WeatherProvider; public class ProviderTest { @Test