Fix get provider from string

This commit is contained in:
Minecon724 2025-05-24 12:16:08 +02:00
commit e3662fd078
Signed by untrusted user who does not match committer: m724
GPG key ID: A02E6E67AB961189
2 changed files with 23 additions and 22 deletions

View file

@ -1,5 +1,6 @@
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.twilight.impl.approximate.ApproximateTwilightTimeProvider;
@ -19,12 +20,12 @@ public class Providers {
* @throws NoSuchProviderException If invalid provider name
*/
public static ThunderProvider getThunderProvider(String name, String apiKey) {
switch (name.toLowerCase()) {
case "blitzortung" -> new BlitzortungProvider();
}
throw new NoSuchProviderException(name);
}
return switch (name.toLowerCase()) {
case "blitzortung", "lightningmaps" -> new BlitzortungProvider();
default -> throw new NoSuchProviderException(name);
};
}
/**
* Gets a weather provider by name.<br>
@ -36,12 +37,12 @@ public class Providers {
* @throws NoSuchProviderException If invalid provider name
*/
public static WeatherProvider getWeatherProvider(String name, String apiKey) {
switch (name.toLowerCase()) {
case "openmeteo" -> new OpenMeteoProvider();
}
throw new NoSuchProviderException(name);
}
return switch (name.toLowerCase()) {
case "openmeteo", "open-meteo" -> new OpenMeteoProvider();
default -> throw new NoSuchProviderException(name);
};
}
/**
* Gets a twilight time provider by name.<br>
@ -53,16 +54,9 @@ public class Providers {
* @throws NoSuchProviderException If invalid provider name
*/
public static TwilightTimeProvider getTwilightTimeProvider(String name, String apiKey) {
switch (name.toLowerCase()) {
return switch (name.toLowerCase()) {
case "approximate" -> new ApproximateTwilightTimeProvider();
}
throw new NoSuchProviderException(name);
}
public static class NoSuchProviderException extends RuntimeException {
public NoSuchProviderException(String provider) {
super(provider);
}
default -> throw new NoSuchProviderException(name);
};
}
}

View file

@ -0,0 +1,7 @@
package eu.m724.wtapi.provider.exception;
public class NoSuchProviderException extends RuntimeException {
public NoSuchProviderException(String provider) {
super("No such provider: " + provider);
}
}