FIXUP: Avoid source tag conflicts

* Merging addresses and buildings will now merge sources _in
  alphabetical_ order.

This fixes #96.

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2020-10-07 08:05:21 -06:00
rodzic 10e3ad76a7
commit 8e71690ed1
2 zmienionych plików z 34 dodań i 2 usunięć

Wyświetl plik

@ -8,8 +8,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openstreetmap.josm.command.ChangePropertyCommand;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.data.osm.DataSet;
@ -31,6 +34,7 @@ import org.openstreetmap.josm.tools.Geometry;
*/
public class MergeAddressBuildings extends AbstractConflationCommand {
public static final String KEY = "building";
public static final String SOURCE = "source";
public MergeAddressBuildings(DataSet data) {
super(data);
@ -85,16 +89,27 @@ public class MergeAddressBuildings extends AbstractConflationCommand {
if (nodesWithAddresses.size() == 1
&& nodesWithAddresses.parallelStream().allMatch(n -> n.getParentWays().isEmpty())) {
String currentKey = null;
Node node = nodesWithAddresses.get(0);
List<String> sources = new ArrayList<>();
try {
// Remove the key to avoid the popup from utilsplugin2
currentKey = object.get(KEY);
sources.add(object.get(SOURCE));
object.remove(KEY);
GuiHelper.runInEDTAndWait(() -> commandList
.add(ReplaceGeometryUtils.buildUpgradeNodeCommand(nodesWithAddresses.get(0), object)));
object.remove(SOURCE);
GuiHelper.runInEDTAndWait(
() -> commandList.add(ReplaceGeometryUtils.buildUpgradeNodeCommand(node, object)));
} finally {
if (currentKey != null) {
object.put(KEY, currentKey);
}
sources.add(node.get(SOURCE));
sources.removeIf(Objects::isNull);
sources = sources.stream().flatMap(source -> Stream.of(source.split(";", 0))).distinct()
.filter(Objects::nonNull).sorted().collect(Collectors.toList());
if (!sources.isEmpty()) {
commandList.add(new ChangePropertyCommand(object, SOURCE, String.join(";", sources)));
}
}
}
return commandList;

Wyświetl plik

@ -8,7 +8,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openstreetmap.josm.command.ChangePropertyCommand;
import org.openstreetmap.josm.command.Command;
@ -92,12 +94,27 @@ public class MergeBuildingAddress extends AbstractConflationCommand {
.filter(prim -> checkInside(node, prim)).collect(Collectors.toList());
final List<Command> commandList = new ArrayList<>();
List<String> sources = new ArrayList<>();
OsmPrimitive object = null;
sources.add(node.get(MergeAddressBuildings.SOURCE));
if (possibleDuplicates.size() == 1) {
commandList.add(new ChangePropertyCommand(possibleDuplicates, node.getKeys()));
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
object = possibleDuplicates.get(0);
} else if (buildings.size() == 1 && getAddressPoints(buildings.get(0)).size() == 1) {
commandList.add(new ChangePropertyCommand(buildings, node.getKeys()));
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
object = buildings.get(0);
}
if (object != null) {
sources.add(object.get(MergeAddressBuildings.SOURCE));
}
sources.removeIf(Objects::isNull);
sources = sources.stream().flatMap(source -> Stream.of(source.split(";", 0))).distinct()
.filter(Objects::nonNull).sorted().collect(Collectors.toList());
if (!sources.isEmpty() && object != null) {
commandList.add(new ChangePropertyCommand(object, MergeAddressBuildings.SOURCE, String.join(";", sources)));
}
return commandList;