From 838816c0333bd2f5ae3932c9f28a9796bb00cb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Mon, 18 Nov 2024 13:55:12 +0100 Subject: [PATCH] SAT solving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫl L'hopital --- .../binding/airparif/internal/AirParifIconProvider.java | 3 +-- .../openhab/binding/airparif/internal/api/AirParifDto.java | 4 ++-- .../binding/airparif/internal/api/PollenAlertLevel.java | 6 ++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/AirParifIconProvider.java b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/AirParifIconProvider.java index d464e0eb9f4..d893d010df8 100755 --- a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/AirParifIconProvider.java +++ b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/AirParifIconProvider.java @@ -101,8 +101,7 @@ public class AirParifIconProvider implements IconProvider { if (POLLEN_ICONS.contains(category) && state != null) { try { int ordinal = Integer.valueOf(state); - PollenAlertLevel alertLevel = PollenAlertLevel.AS_SET.stream() - .filter(pal -> pal.riskLevel == ordinal).findFirst().orElse(PollenAlertLevel.UNKNOWN); + PollenAlertLevel alertLevel = PollenAlertLevel.valueOf(ordinal); result = result.replaceAll(NEUTRAL_COLOR, alertLevel.color); } catch (NumberFormatException ignore) { } diff --git a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/AirParifDto.java b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/AirParifDto.java index 24c6e9a728a..a68ff1a1604 100644 --- a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/AirParifDto.java +++ b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/AirParifDto.java @@ -124,11 +124,11 @@ public class AirParifDto { } private Set getValidities() { - Set local; + final Set local; if (validities != null) { local = validities; } else { - local = new TreeSet<>(); + local = new TreeSet(); getData().ifPresent(pollens -> { Matcher matcher = PATTERN.matcher(pollens.periode); while (matcher.find()) { diff --git a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/PollenAlertLevel.java b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/PollenAlertLevel.java index 59b2d821ba3..82fe12ae565 100644 --- a/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/PollenAlertLevel.java +++ b/bundles/org.openhab.binding.airparif/src/main/java/org/openhab/binding/airparif/internal/api/PollenAlertLevel.java @@ -13,6 +13,7 @@ package org.openhab.binding.airparif.internal.api; import java.util.EnumSet; +import java.util.Objects; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -42,4 +43,9 @@ public enum PollenAlertLevel { this.riskLevel = riskLevel; this.color = color; } + + public static PollenAlertLevel valueOf(int ordinal) { + return Objects + .requireNonNull(AS_SET.stream().filter(pal -> pal.riskLevel == ordinal).findFirst().orElse(UNKNOWN)); + } }