Skip to content

Commit

Permalink
Use jakarta.json instead of java.json
Browse files Browse the repository at this point in the history
This also fixes various lint issues

Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Aug 22, 2023
1 parent 03ea278 commit 71c807e
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/main/java/org/wikipedia/io/SophoxDownloadReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand All @@ -20,10 +21,11 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonValue;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;
import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.DataSource;
Expand Down Expand Up @@ -174,7 +176,7 @@ static String date(String humanDuration, LocalDateTime from) {

private static SearchResult searchName(String area) throws IOException {
return NameFinder.queryNominatim(area).stream().filter(
x -> !OsmPrimitiveType.NODE.equals(x.getOsmId().getType())).iterator().next();
x -> OsmPrimitiveType.NODE != x.getOsmId().getType()).iterator().next();
}

static String geocodeArea(String area) throws IOException {
Expand Down Expand Up @@ -257,22 +259,26 @@ static List<PrimitiveId> getPrimitiveIds(InputStream source) throws UnsupportedE
Pattern uriPattern = Pattern.compile("^https://www\\.openstreetmap\\.org/(node|way|relation)/(\\d+)");
List<PrimitiveId> ids = new ArrayList<>();

JsonArray results = Json.createReader(new InputStreamReader(source, StandardCharsets.UTF_8))
.readObject()
.getJsonObject("results")
.getJsonArray("bindings");

for (JsonObject row : results.getValuesAs(JsonObject.class)) {
for (JsonValue column : row.values()) {
JsonObject columnObj = (JsonObject) column;
if (columnObj.getString("type").equals("uri")) {
Matcher matcher = uriPattern.matcher(columnObj.getString("value"));
if (matcher.matches()) {
ids.add(new SimplePrimitiveId(Long.parseLong(matcher.group(2)),
OsmPrimitiveType.from(matcher.group(1))));
try (InputStreamReader inputStreamReader = new InputStreamReader(source, StandardCharsets.UTF_8);
JsonReader reader = Json.createReader(inputStreamReader)) {
JsonArray results = reader.readObject()
.getJsonObject("results")
.getJsonArray("bindings");

for (JsonObject row : results.getValuesAs(JsonObject.class)) {
for (JsonValue column : row.values()) {
JsonObject columnObj = (JsonObject) column;
if ("uri".equals(columnObj.getString("type"))) {
Matcher matcher = uriPattern.matcher(columnObj.getString("value"));
if (matcher.matches()) {
ids.add(new SimplePrimitiveId(Long.parseLong(matcher.group(2)),
OsmPrimitiveType.from(matcher.group(1))));
}
}
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return ids;
Expand Down

0 comments on commit 71c807e

Please sign in to comment.