Fix get provider from string
This commit is contained in:
parent
90287298c8
commit
e3662fd078
2 changed files with 23 additions and 22 deletions
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package eu.m724.wtapi.provider.exception;
|
||||
|
||||
public class NoSuchProviderException extends RuntimeException {
|
||||
public NoSuchProviderException(String provider) {
|
||||
super("No such provider: " + provider);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue