fix: Map key comparison, preventing NPE

This commit is contained in:
Piotr Dec 2024-07-19 01:11:03 +02:00
parent 1667579c15
commit 03fad8ff96
Signed by: stawros
GPG key ID: F89F27AD8F881A91
2 changed files with 4 additions and 2 deletions

View file

@ -30,7 +30,7 @@ public class TemperaturesServiceImpl implements TemperaturesService {
Thread.currentThread().interrupt();
}
}
return averages.get().get(city);
return averages.get().getOrDefault(city.toLowerCase(), List.of());
}
@EventListener(FileProcessedEvent.class)

View file

@ -79,7 +79,9 @@ public class FileLoadingService {
.map(line -> {
try {
var parts = line.split(";");
return new DataRow(parts[0], Integer.parseInt(parts[1].split("-")[0]), Double.parseDouble(parts[2]));
return new DataRow(parts[0].toLowerCase(),
Integer.parseInt(parts[1].split("-")[0]),
Double.parseDouble(parts[2]));
} catch (Exception e) {
throw new FileProcessingException("Error in line %s".formatted(line), e);
}