Fix sonar warnings (#181)

This commit is contained in:
Michael Barry
2022-04-23 05:58:49 -04:00
committed by GitHub
parent e876314e2b
commit 644ea4b4cf
5 changed files with 11 additions and 13 deletions

View File

@@ -105,7 +105,7 @@ public class Generate {
} }
private static <T> T loadAndParseYaml(String url, PlanetilerConfig config, Class<T> clazz) throws IOException { private static <T> T loadAndParseYaml(String url, PlanetilerConfig config, Class<T> clazz) throws IOException {
LOGGER.info("reading " + url); LOGGER.info("reading {}", url);
try (var stream = Downloader.openStream(url, config)) { try (var stream = Downloader.openStream(url, config)) {
// Jackson yaml parsing does not handle anchors and references, so first parse the input // Jackson yaml parsing does not handle anchors and references, so first parse the input
// using SnakeYAML, then parse SnakeYAML's output using Jackson to get it into our records. // using SnakeYAML, then parse SnakeYAML's output using Jackson to get it into our records.
@@ -150,7 +150,7 @@ public class Generate {
String mappingPath = Path.of(layerFile).resolveSibling(datasource.mapping_file).normalize().toString(); String mappingPath = Path.of(layerFile).resolveSibling(datasource.mapping_file).normalize().toString();
imposm3MappingFiles.add(base + mappingPath); imposm3MappingFiles.add(base + mappingPath);
} else { } else {
LOGGER.warn("Unknown datasource type: " + datasource.type); LOGGER.warn("Unknown datasource type: {}", datasource.type);
} }
} }
} }
@@ -675,7 +675,7 @@ public class Generate {
return Stream.of(markdown.strip().split("[\r\n][\r\n]+")) return Stream.of(markdown.strip().split("[\r\n][\r\n]+"))
.map(p -> parser.parse(p.strip())) .map(p -> parser.parse(p.strip()))
.map(node -> escapeJavadoc(renderer.render(node))) .map(node -> escapeJavadoc(renderer.render(node)))
.map(p -> p.replaceAll("(^<p>|</p>$)", "").strip()) .map(p -> p.replaceAll("((^<p>)|(</p>$))", "").strip())
.collect(joining(LINE_SEPARATOR + "<p>" + LINE_SEPARATOR)); .collect(joining(LINE_SEPARATOR + "<p>" + LINE_SEPARATOR));
} }

View File

@@ -82,7 +82,7 @@ public class MountainPeak implements
* label density by only taking the top 5 most important mountain peaks within each 100x100px * label density by only taking the top 5 most important mountain peaks within each 100x100px
* square. * square.
*/ */
private static final Logger LOGGER = LoggerFactory.getLogger(TransportationName.class); private static final Logger LOGGER = LoggerFactory.getLogger(MountainPeak.class);
private final Translations translations; private final Translations translations;
private final Stats stats; private final Stats stats;

View File

@@ -235,7 +235,7 @@ public class Place implements
rank = country.rank; rank = country.rank;
} }
rank = Math.min(6, Math.max(1, rank)); rank = Math.max(1, Math.min(6, rank));
features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE) features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
.putAttrs(names) .putAttrs(names)

View File

@@ -106,7 +106,7 @@ public class WaterName implements
// TODO pull lake centerline computation into planetiler? // TODO pull lake centerline computation into planetiler?
long osmId = Math.abs(feature.getLong("OSM_ID")); long osmId = Math.abs(feature.getLong("OSM_ID"));
if (osmId == 0L) { if (osmId == 0L) {
LOGGER.warn("Bad lake centerline. Tags: " + feature.tags()); LOGGER.warn("Bad lake centerline. Tags: {}", feature.tags());
} else { } else {
try { try {
// multiple threads call this concurrently // multiple threads call this concurrently
@@ -179,7 +179,7 @@ public class WaterName implements
if (centerlineGeometry != null) { if (centerlineGeometry != null) {
// prefer lake centerline if it exists // prefer lake centerline if it exists
feature = features.geometry(LAYER_NAME, centerlineGeometry) feature = features.geometry(LAYER_NAME, centerlineGeometry)
.setMinPixelSizeBelowZoom(13, 6 * element.name().length()); .setMinPixelSizeBelowZoom(13, 6d * element.name().length());
} else { } else {
// otherwise just use a label point inside the lake // otherwise just use a label point inside the lake
feature = features.pointOnSurface(LAYER_NAME); feature = features.pointOnSurface(LAYER_NAME);

View File

@@ -54,28 +54,26 @@ import java.util.stream.Stream;
* <a href="https://github.com/openmaptiles/openmaptiles-tools/blob/master/sql/zzz_language.sql">openmaptiles-tools</a>. * <a href="https://github.com/openmaptiles/openmaptiles-tools/blob/master/sql/zzz_language.sql">openmaptiles-tools</a>.
*/ */
public class LanguageUtils { public class LanguageUtils {
// See https://github.com/onthegomap/planetiler/issues/86
// Name tags that should be eligible for finding a latin name. // Name tags that should be eligible for finding a latin name.
// See https://wiki.openstreetmap.org/wiki/Multilingual_names // See https://wiki.openstreetmap.org/wiki/Multilingual_names
private static final Predicate<String> VALID_NAME_TAGS = private static final Predicate<String> VALID_NAME_TAGS =
Pattern Pattern
.compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|[0-9]{3}))?$", Pattern.CASE_INSENSITIVE) .compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|[0-9]{3}))?$", Pattern.CASE_INSENSITIVE)
.asMatchPredicate(); .asMatchPredicate();
// See https://github.com/onthegomap/planetiler/issues/86
// Match strings that only contain latin characters. // Match strings that only contain latin characters.
private static final Predicate<String> ONLY_LATIN = Pattern private static final Predicate<String> ONLY_LATIN = Pattern
.compile("^[\\P{IsLetter}[\\p{IsLetter}&&\\p{IsLatin}]]+$") .compile("^[\\P{IsLetter}[\\p{IsLetter}&&\\p{IsLatin}]]+$")
.asMatchPredicate(); .asMatchPredicate();
// Match only latin letters // Match only latin letters
private static final Pattern LATIN_LETTER = Pattern.compile("[\\p{IsLetter}&&\\p{IsLatin}]+"); private static final Pattern LATIN_LETTER = Pattern.compile("[\\p{IsLetter}&&\\p{IsLatin}]+");
private static final Pattern EMPTY_PARENS = Pattern.compile("(\\([ -.]*\\)|\\[[ -.]*])"); private static final Pattern EMPTY_PARENS = Pattern.compile("(\\([ -.]*\\)|\\[[ -.]*])");
private static final Pattern LEADING_TRAILING_JUNK = Pattern.compile("(^\\s*([./-]\\s*)*|(\\s+[./-])*\\s*$)"); private static final Pattern LEADING_TRAILING_JUNK = Pattern.compile("((^[\\s./-]*)|([\\s./-]*$))");
private static final Pattern WHITESPACE = Pattern.compile("\\s+"); private static final Pattern WHITESPACE = Pattern.compile("\\s+");
private static final Set<String> EN_DE_NAME_KEYS = Set.of("name:en", "name:de"); private static final Set<String> EN_DE_NAME_KEYS = Set.of("name:en", "name:de");
private LanguageUtils() {}
private static void putIfNotEmpty(Map<String, Object> dest, String key, Object value) { private static void putIfNotEmpty(Map<String, Object> dest, String key, Object value) {
if (value != null && !value.equals("")) { if (value != null && !value.equals("")) {
dest.put(key, value); dest.put(key, value);