Solving nullable

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2024-11-18 14:01:36 +01:00
parent 838816c033
commit ec0bb2f463

View File

@ -115,7 +115,6 @@ public class AirParifDto {
private static ZoneId DEFAULT_ZONE = ZoneId.of("Europe/Paris"); private static ZoneId DEFAULT_ZONE = ZoneId.of("Europe/Paris");
public List<Pollens> data = List.of(); public List<Pollens> data = List.of();
private @Nullable Set<ZonedDateTime> validities;
private @Nullable ZonedDateTime beginValidity; private @Nullable ZonedDateTime beginValidity;
private @Nullable ZonedDateTime endValidity; private @Nullable ZonedDateTime endValidity;
@ -124,21 +123,15 @@ public class AirParifDto {
} }
private Set<ZonedDateTime> getValidities() { private Set<ZonedDateTime> getValidities() {
final Set<ZonedDateTime> local; Set<ZonedDateTime> validities = new TreeSet<>();
if (validities != null) {
local = validities;
} else {
local = new TreeSet<ZonedDateTime>();
getData().ifPresent(pollens -> { getData().ifPresent(pollens -> {
Matcher matcher = PATTERN.matcher(pollens.periode); Matcher matcher = PATTERN.matcher(pollens.periode);
while (matcher.find()) { while (matcher.find()) {
local.add(LocalDate.parse(matcher.group(), FORMATTER).atStartOfDay(DEFAULT_ZONE)); validities.add(LocalDate.parse(matcher.group(), FORMATTER).atStartOfDay(DEFAULT_ZONE));
} }
}); });
validities = local;
}
return local; return validities;
} }
public Optional<ZonedDateTime> getBeginValidity() { public Optional<ZonedDateTime> getBeginValidity() {