From 17d554850c54fbb42dd70cfcedb71845139dcedc Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Fri, 6 Dec 2019 07:39:11 -0700 Subject: [PATCH] Start using new features from JOSM (up to r15486, November 2019) * Use function in JOSM (bboxIsFunctionallyEqual, added in r15486) * Keep attributes as tags (added in r15470) * Add @Override in MapWithAILayer (added in r15371) Signed-off-by: Taylor Smock --- .../mapwithai/backend/MapWithAIDataUtils.java | 23 +++++-------------- .../mapwithai/backend/MapWithAILayer.java | 2 +- .../mapwithai/backend/OsmReaderCustom.java | 12 +++------- .../frontend/MapWithAIDownloadReader.java | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java index 2f4455f..072f673 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java @@ -9,7 +9,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.TreeSet; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.locks.Lock; @@ -92,8 +91,8 @@ public final class MapWithAIDataUtils { */ public static void removeMapWithAIPaintStyles() { new ArrayList<>(MapPaintStyles.getStyles().getStyleSources()).parallelStream() - .filter(source -> paintStyleResourceUrl.equals(source.url)) - .forEach(style -> SwingUtilities.invokeLater(() -> MapPaintStyles.removeStyle(style))); + .filter(source -> paintStyleResourceUrl.equals(source.url)) + .forEach(style -> SwingUtilities.invokeLater(() -> MapPaintStyles.removeStyle(style))); } /** @@ -319,28 +318,18 @@ public final class MapWithAIDataUtils { } while (aDRSize != alreadyDownloadedReduced.size()); for (final BBox bbox : wantToDownload) { for (final BBox downloaded : alreadyDownloaded) { - if (bboxesAreFunctionallyEqual(bbox, downloaded, null)) { - Logging.debug("YEP"); + if (downloaded.bboxIsFunctionallyEqual(downloaded, null)) { + Logging.debug("{0}: It looks like we already downloaded {1}", MapWithAIPlugin.NAME, + bbox.toStringCSV(",")); } } } return wantToDownload.parallelStream() .filter(bbox1 -> alreadyDownloadedReduced.parallelStream() - .noneMatch(bbox2 -> bboxesAreFunctionallyEqual(bbox1, bbox2, 0.000_02))) + .noneMatch(bbox2 -> bbox2.bboxIsFunctionallyEqual(bbox1, 0.000_02))) .collect(Collectors.toList()); } - // TODO replace with {@link BBox.bboxesAreFunctionallyEqual} when version bumped - // to >r15483 - private static boolean bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, Double maxDifference) { - final double diff = Optional.ofNullable(maxDifference).orElse(LatLon.MAX_SERVER_PRECISION); - return ((bbox1 != null) && (bbox2 != null) - && (Math.abs(bbox1.getBottomRightLat() - bbox2.getBottomRightLat()) < diff) - && (Math.abs(bbox1.getBottomRightLon() - bbox2.getBottomRightLon()) < diff) - && (Math.abs(bbox1.getTopLeftLat() - bbox2.getTopLeftLat()) < diff) - && (Math.abs(bbox1.getTopLeftLon() - bbox2.getTopLeftLon()) < diff)); - } - private static boolean bboxesShareSide(BBox bbox1, BBox bbox2) { final List bbox1Lons = Arrays.asList(bbox1.getTopLeftLon(), bbox1.getBottomRightLon()); final List bbox1Lats = Arrays.asList(bbox1.getTopLeftLat(), bbox1.getBottomRightLat()); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java index 803ca97..edd0d37 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAILayer.java @@ -56,7 +56,7 @@ public class MapWithAILayer extends OsmDataLayer implements ActiveLayerChangeLis MainApplication.getLayerManager().addActiveLayerChangeListener(this); } - // @Override TODO remove comment on 2020-01-01 + @Override public String getChangesetSourceTag() { return MapWithAIDataUtils.getAddedObjects() > 0 ? String.join("; ", MapWithAIDataUtils.getAddedObjectsSource()) : null; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java index 8e8002f..123382c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/OsmReaderCustom.java @@ -14,7 +14,6 @@ import org.openstreetmap.josm.io.OsmReader; import org.openstreetmap.josm.tools.Logging; /** - * TODO remove this class in January 2019 (if required patch is pulled) * Parser for the Osm API (XML output). Read from an input stream and construct a dataset out of it. * * For each xml element, there is a dedicated method. @@ -25,16 +24,11 @@ public class OsmReaderCustom extends OsmReader { boolean temporaryConvertUknownToTags; protected OsmReaderCustom(boolean convertUnknownToTags) { // Restricts visibility - super(); - // TODO when we update to r15470 this.convertUnknownToTags - temporaryConvertUknownToTags = convertUnknownToTags; - } - - // TODO remove with update to r15470 - protected boolean isConvertUknownToTags() { - return temporaryConvertUknownToTags; + super(convertUnknownToTags); } + // check every so often to see if I can keep original negative ids + // See https://josm.openstreetmap.de/ticket/18258 (TODO) @Override protected OsmPrimitive buildPrimitive(PrimitiveData pd) { final Long serverId = pd.getUniqueId(); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java index 2deafb4..28559fc 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/frontend/MapWithAIDownloadReader.java @@ -59,7 +59,7 @@ public class MapWithAIDownloadReader implements DownloadSource urlInformation) { + private static String getUrl(Map urlInformation) { StringBuilder sb = new StringBuilder(); if (urlInformation.containsKey("url")) { sb.append(urlInformation.get("url"));