FIXUP: Ensure that we don't try to merge deleted ways

This fixes #81.

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-22 13:50:19 -06:00
rodzic b3ddb241db
commit b07707cc22
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 45 dodań i 3 usunięć

Wyświetl plik

@ -63,10 +63,14 @@ public class MergeDuplicateWays extends Command {
public MergeDuplicateWays(DataSet data, List<Way> ways) {
super(data);
this.ways = ways;
this.ways = ways.stream().filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
this.commands = new ArrayList<>();
}
private static boolean nonDeletedWay(Way way) {
return !way.isDeleted() && way.getNodes().stream().noneMatch(OsmPrimitive::isDeleted);
}
@Override
public boolean executeCommand() {
if (commands.isEmpty() || (command == null)) {
@ -125,7 +129,7 @@ public class MergeDuplicateWays extends Command {
for (int i = 0; i < ways.size(); i++) {
final Way way1 = ways.get(i);
final Collection<Way> nearbyWays = dataSet.searchWays(way1.getBBox()).parallelStream()
.filter(way -> !way.isDeleted()).collect(Collectors.toList());
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
nearbyWays.remove(way1);
for (final Way way2 : nearbyWays) {
final Command command = checkForDuplicateWays(way1, way2);
@ -150,7 +154,8 @@ public class MergeDuplicateWays extends Command {
* @param commands A list of commands to add to
*/
public static void checkForDuplicateWays(Way way, List<Command> commands) {
final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox());
final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
nearbyWays.remove(way);
for (final Way way2 : nearbyWays) {
if (!way2.isDeleted()) {

Wyświetl plik

@ -1,6 +1,7 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.commands;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -315,4 +316,40 @@ public class MergeDuplicateWaysTest {
assertSame(matchPair.a.b, MergeDuplicateWays.nodeInCompressed(testNode, testSet),
"If a node has a pairing, then the paired node should be returned");
}
/**
* Non-regression test for <a
* href=https://gitlab.com/gokaart/JOSM_MapWithAI/-/issues/81>#81</a>.
*/
@Test
public void testDeletedNode() {
Way way1 = TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE));
Way way2 = TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE));
DataSet ds = new DataSet();
List<Way> ways = Arrays.asList(way1, way2);
for (Way way : ways) {
way.getNodes().forEach(ds::addPrimitive);
ds.addPrimitive(way);
}
way2.firstNode().setDeleted(true);
assertDoesNotThrow(() -> new MergeDuplicateWays(ds, ways).executeCommand());
}
/**
* Non-regression test for <a
* href=https://gitlab.com/gokaart/JOSM_MapWithAI/-/issues/81>#81</a>.
*/
@Test
public void testDeletedWay() {
Way way1 = TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE));
Way way2 = TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE));
DataSet ds = new DataSet();
List<Way> ways = Arrays.asList(way1, way2);
for (Way way : ways) {
way.getNodes().forEach(ds::addPrimitive);
ds.addPrimitive(way);
}
way2.setDeleted(true);
assertDoesNotThrow(() -> new MergeDuplicateWays(ds, ways).executeCommand());
}
}