fix: check placeBindings for null instead of checking each destructured value

This commit is contained in:
Rsedp8 2025-05-24 17:35:45 +02:00
parent 50c7c49bdb
commit d6d8155cee

View file

@ -531,40 +531,38 @@ ${"wd:" + place.wikiDataEntityId}"""
) )
if (placeBindings != null) { if (placeBindings != null) {
for ((item1, label, location, clas) in placeBindings) { for ((item1, label, location, clas) in placeBindings) {
if (item1 != null && label != null && clas != null) { val input = location.value
val input = location.value val pattern = Pattern.compile(
val pattern = Pattern.compile( "Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)"
"Point\\(([-+]?[0-9]*\\.?[0-9]+) ([-+]?[0-9]*\\.?[0-9]+)\\)" )
) val matcher = pattern.matcher(input)
val matcher = pattern.matcher(input)
if (matcher.find()) { if (matcher.find()) {
val longStr = matcher.group(1) val longStr = matcher.group(1)
val latStr = matcher.group(2) val latStr = matcher.group(2)
val itemUrl = item1.value val itemUrl = item1.value
val itemName = label.value.replace("&", "&") val itemName = label.value.replace("&", "&")
val itemLatitude = latStr val itemLatitude = latStr
val itemLongitude = longStr val itemLongitude = longStr
val itemClass = clas.value val itemClass = clas.value
val formattedItemName = val formattedItemName =
if (!itemClass.isEmpty()) if (!itemClass.isEmpty())
"$itemName ($itemClass)" "$itemName ($itemClass)"
else else
itemName itemName
val kmlEntry = (""" val kmlEntry = ("""
<Placemark> <Placemark>
<name>$formattedItemName</name> <name>$formattedItemName</name>
<description>$itemUrl</description> <description>$itemUrl</description>
<Point> <Point>
<coordinates>$itemLongitude,$itemLatitude</coordinates> <coordinates>$itemLongitude,$itemLatitude</coordinates>
</Point> </Point>
</Placemark>""") </Placemark>""")
kmlString = kmlString + kmlEntry kmlString = kmlString + kmlEntry
} else { } else {
Timber.e("No match found") Timber.e("No match found")
}
} }
} }
} }