42 lines
972 B
Java
42 lines
972 B
Java
package SuMoC.backend.meteo;
|
|
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* Simplified WMO weather codes, taken from https://gist.github.com/stellasphere/9490c195ed2b53c707087c8c2db4ec0c
|
|
*/
|
|
public enum WeatherCondition {
|
|
|
|
CLEAR(Set.of(0, 1)),
|
|
PARTLY_CLOUDY(Set.of(2)),
|
|
CLOUDY(Set.of(3)),
|
|
|
|
FOG(Set.of(45, 48)),
|
|
|
|
DRIZZLE(Set.of(51, 53, 55, 56, 57)),
|
|
RAIN(Set.of(61, 63, 65, 66, 67)),
|
|
|
|
SNOW(Set.of(71, 73, 75, 77, 85, 86)),
|
|
|
|
SHOWERS(Set.of(80, 81, 82)),
|
|
|
|
THUNDERSTORM(Set.of(95, 96, 99)),
|
|
|
|
UNKNOWN(Set.of());
|
|
|
|
private final Set<Integer> codes;
|
|
|
|
WeatherCondition(Set<Integer> codes) {
|
|
this.codes = codes;
|
|
}
|
|
|
|
public static WeatherCondition from(int code) throws Exception {
|
|
for (WeatherCondition condition : values()) {
|
|
if (condition.codes.contains(code)) {
|
|
return condition;
|
|
}
|
|
}
|
|
throw new UnknownWeatherCodeException("Encountered unknown weather code.");
|
|
}
|
|
}
|