Fix some errorprone issues

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-08-05 08:03:40 -06:00
rodzic 690e99503c
commit e8e3985460
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
4 zmienionych plików z 29 dodań i 22 usunięć

Wyświetl plik

@ -25,7 +25,7 @@ import org.openstreetmap.josm.tools.Destroyable;
public final class DownloadListener implements DataSourceListener, Destroyable {
final WeakReference<DataSet> ds;
private double BBOX_SIMILARITY_DEGREES = 0.001;
private static final double BBOX_SIMILARITY_DEGREES = 0.001;
private static final Collection<DownloadListener> LISTENERS = new HashSet<>();
public DownloadListener(DataSet dataSet) {

Wyświetl plik

@ -37,7 +37,7 @@ import org.openstreetmap.josm.tools.Utils;
*/
public class ESRISourceReader implements Closeable {
private final MapWithAIInfo source;
private List<CachedFile> cachedFiles = new ArrayList<>();
private final List<CachedFile> cachedFiles = new ArrayList<>();
private boolean fastFail;
private final List<MapWithAICategory> ignoreConflationCategories;
private static final String JSON_QUERY_PARAM = "?f=json";

Wyświetl plik

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
@ -64,17 +65,21 @@ public class MapPaintUtils {
private final Color color;
SafeColors(Color color) {
this.color = color;
this.color = new Color(color.getRGB());
}
/**
* Get the safe color
*/
public Color getColor() {
return this.color;
return new Color(this.color.getRGB());
}
}
private MapPaintUtils() {
// This is a utils class. Don't allow constructing.
}
/**
* Add a paintstyle from the jar
*/
@ -149,8 +154,8 @@ public class MapPaintUtils {
.distinct().collect(Collectors.toList());
StyleSource styleSource = getMapWithAIPaintStyle();
/* TODO Depends upon JOSM-19547 */
if (Version.getInstance().getVersion() < 20_000
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION || styleSource == null) {
if ((Version.getInstance().getVersion() < 20_000
&& Version.getInstance().getVersion() == Version.JOSM_UNKNOWN_VERSION) || styleSource == null) {
return;
}
if (!styleSource.isLoaded()) {
@ -183,7 +188,8 @@ public class MapPaintUtils {
} catch (ZipException e) {
// Assume that it is a standard file, not a zip file.
OutputStream out = new FileOutputStream(file.getName() + ".tmp");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
writeData(out, bufferedReader, group, sources);
bufferedReader.close();
out.close();
@ -216,7 +222,8 @@ public class MapPaintUtils {
continue;
}
out.putNextEntry(new ZipEntry(MAPWITHAI_MAPCSS_ZIP_NAME));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.getInputStream(current)));
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(file.getInputStream(current), StandardCharsets.UTF_8));
writeData(out, bufferedReader, group, sources);
bufferedReader.close();
out.closeEntry();
@ -230,21 +237,21 @@ public class MapPaintUtils {
throws IOException {
String line = bufferedReader.readLine();
while (!line.contains("End Settings for the paint style")) {
out.write(line.getBytes());
out.write(System.lineSeparator().getBytes());
out.write(line.getBytes(StandardCharsets.UTF_8));
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
line = bufferedReader.readLine();
}
/* Finish writing the comment */
while (!line.endsWith("*/")) {
out.write(line.getBytes());
out.write(System.lineSeparator().getBytes());
out.write(line.getBytes(StandardCharsets.UTF_8));
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
line = bufferedReader.readLine();
}
out.write(line.getBytes());
out.write(System.lineSeparator().getBytes());
out.write(line.getBytes(StandardCharsets.UTF_8));
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
for (String source : sources) {
out.write(System.lineSeparator().getBytes());
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
String simpleSource = source.replaceAll("[() /\\${}:]", "_");
StringBuilder sb = new StringBuilder("setting::").append(simpleSource).append("{").append("type:color;")
.append("default:").append(simpleSource).append(ColorHelper.color2html(getRandomColor(source)))
@ -253,17 +260,17 @@ public class MapPaintUtils {
sb.append("group:\"").append(group).append("\";");
}
sb.append("}");
out.write(sb.toString().getBytes());
out.write(System.lineSeparator().getBytes());
out.write(sb.toString().getBytes(StandardCharsets.UTF_8));
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
sb = new StringBuilder(
"*[/^(source|mapwithai:source)$/][any(tag(\"source\"), tag(\"mapwithai:source\"))=\"")
.append(source).append("\"]{set_color_programatic:setting(\"").append(simpleSource)
.append("\");}");
out.write(sb.toString().getBytes());
out.write(sb.toString().getBytes(StandardCharsets.UTF_8));
}
while ((line = bufferedReader.readLine()) != null) {
out.write(line.getBytes());
out.write(System.lineSeparator().getBytes());
out.write(line.getBytes(StandardCharsets.UTF_8));
out.write(System.lineSeparator().getBytes(StandardCharsets.UTF_8));
}
}
@ -275,7 +282,7 @@ public class MapPaintUtils {
SafeColors[] colors = Stream.of(SafeColors.values()).filter(c -> SafeColors.AI_MAGENTA != c)
.toArray(SafeColors[]::new);
CRC32 crc = new CRC32();
crc.update(sourceName.getBytes());
crc.update(sourceName.getBytes(StandardCharsets.UTF_8));
double bucket = crc.getValue() / CRC_DIVIDE_TO_TEN_K_MAX;
double bucket_size = 10_000 / colors.length;

Wyświetl plik

@ -251,7 +251,7 @@ public class MapWithAITestRules extends JOSMTestRules {
@Override
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
if (wireMock != null && !request.getUrl().endsWith("/capabilities")
&& (!response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip"))) {
&& !response.getHeaders().getContentTypeHeader().mimeTypePart().contains("application/zip")) {
String origBody = response.getBodyAsString();
String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", wireMock.baseUrl() + "/");
return Response.Builder.like(response).but().body(newBody).build();