kopia lustrzana https://github.com/JOSM/MapWithAI
Convert conflation keys to just be KEY
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
cc6aa7e600
commit
41105000c0
|
@ -20,7 +20,7 @@ import org.openstreetmap.josm.tools.Geometry;
|
|||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
public class ConnectedCommand extends AbstractConflationCommand {
|
||||
public static final String CONN_KEY = "conn";
|
||||
public static final String KEY = "conn";
|
||||
|
||||
public ConnectedCommand(DataSet data) {
|
||||
super(data);
|
||||
|
@ -55,7 +55,7 @@ public class ConnectedCommand extends AbstractConflationCommand {
|
|||
|
||||
private static List<Command> connectedCommand(DataSet dataSet, Node node) {
|
||||
final List<Command> commands = new ArrayList<>();
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(CONN_KEY));
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(KEY));
|
||||
for (int i = 0; i < primitiveConnections.length / 3; i++) {
|
||||
if (primitiveConnections[i] instanceof Way && primitiveConnections[i + 1] instanceof Node
|
||||
&& primitiveConnections[i + 2] instanceof Node) {
|
||||
|
@ -69,7 +69,7 @@ public class ConnectedCommand extends AbstractConflationCommand {
|
|||
primitiveConnections[i + 1].getClass(), i + 2, primitiveConnections[i + 2].getClass());
|
||||
}
|
||||
}
|
||||
commands.add(new ChangePropertyCommand(node, CONN_KEY, null));
|
||||
commands.add(new ChangePropertyCommand(node, KEY, null));
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class ConnectedCommand extends AbstractConflationCommand {
|
|||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return CONN_KEY;
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,17 +21,17 @@ import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
|||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
public class DuplicateCommand extends AbstractConflationCommand {
|
||||
public static final String DUPE_KEY = "dupe";
|
||||
public static final String KEY = "dupe";
|
||||
|
||||
public DuplicateCommand(DataSet data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
private static List<Command> duplicateNode(DataSet dataSet, Node node) {
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(DUPE_KEY));
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(KEY));
|
||||
if (primitiveConnections.length != 1) {
|
||||
Logging.error("{0}: {3} connection connected to more than one node? ({3}={1})", MapWithAIPlugin.NAME,
|
||||
node.get(DUPE_KEY), DUPE_KEY);
|
||||
node.get(KEY), KEY);
|
||||
}
|
||||
|
||||
final List<Command> commands = new ArrayList<>();
|
||||
|
@ -40,13 +40,13 @@ public class DuplicateCommand extends AbstractConflationCommand {
|
|||
final Command tCommand = replaceNode(node, replaceNode);
|
||||
if (tCommand != null) {
|
||||
commands.add(tCommand);
|
||||
if (replaceNode.hasKey(DUPE_KEY)) {
|
||||
final String key = replaceNode.get(DUPE_KEY);
|
||||
commands.add(new ChangePropertyCommand(replaceNode, DUPE_KEY, key));
|
||||
if (replaceNode.hasKey(KEY)) {
|
||||
final String key = replaceNode.get(KEY);
|
||||
commands.add(new ChangePropertyCommand(replaceNode, KEY, key));
|
||||
} else {
|
||||
replaceNode.put(DUPE_KEY, "empty_value"); // This is needed to actually have a command.
|
||||
commands.add(new ChangePropertyCommand(replaceNode, DUPE_KEY, null));
|
||||
replaceNode.remove(DUPE_KEY);
|
||||
replaceNode.put(KEY, "empty_value"); // This is needed to actually have a command.
|
||||
commands.add(new ChangePropertyCommand(replaceNode, KEY, null));
|
||||
replaceNode.remove(KEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,14 +81,14 @@ public class DuplicateCommand extends AbstractConflationCommand {
|
|||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return DUPE_KEY;
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command getRealCommand() {
|
||||
final List<Command> commands = new ArrayList<>();
|
||||
for (Node tNode : possiblyAffectedPrimitives.stream().filter(Node.class::isInstance).map(Node.class::cast)
|
||||
.distinct().filter(node -> node.hasKey(DUPE_KEY)).collect(Collectors.toList())) {
|
||||
.distinct().filter(node -> node.hasKey(KEY)).collect(Collectors.toList())) {
|
||||
List<Command> tCommands = duplicateNode(getAffectedDataSet(), tNode);
|
||||
// We have to execute the command to avoid duplicating the command later. Undo
|
||||
// occurs later, so that the state doesn't actually change.
|
||||
|
|
|
@ -69,7 +69,7 @@ public class MapWithAIMoveActionTest {
|
|||
@Test
|
||||
public void testConflationDupeKeyRemoval() {
|
||||
mapWithAIData.unlock();
|
||||
way1.lastNode().put(DuplicateCommand.DUPE_KEY, "n" + Long.toString(way2.lastNode().getUniqueId()));
|
||||
way1.lastNode().put(DuplicateCommand.KEY, "n" + Long.toString(way2.lastNode().getUniqueId()));
|
||||
mapWithAIData.lock();
|
||||
mapWithAIData.addSelected(way1);
|
||||
final DataSet ds = osmLayer.getDataSet();
|
||||
|
@ -77,33 +77,33 @@ public class MapWithAIMoveActionTest {
|
|||
moveAction.actionPerformed(null);
|
||||
assertTrue(((Way) ds.getPrimitiveById(way1)).lastNode().equals(((Way) ds.getPrimitiveById(way2)).lastNode()),
|
||||
"The duplicate node should have been replaced");
|
||||
assertFalse(((Way) ds.getPrimitiveById(way2)).lastNode().hasKey(DuplicateCommand.DUPE_KEY),
|
||||
assertFalse(((Way) ds.getPrimitiveById(way2)).lastNode().hasKey(DuplicateCommand.KEY),
|
||||
"The dupe key should no longer exist");
|
||||
assertFalse(((Way) ds.getPrimitiveById(way1)).lastNode().hasKey(DuplicateCommand.DUPE_KEY),
|
||||
assertFalse(((Way) ds.getPrimitiveById(way1)).lastNode().hasKey(DuplicateCommand.KEY),
|
||||
"The dupe key should no longer exist");
|
||||
|
||||
UndoRedoHandler.getInstance().undo();
|
||||
assertFalse(way2.lastNode().hasKey(DuplicateCommand.DUPE_KEY), "The dupe key should no longer exist");
|
||||
assertTrue(way1.lastNode().hasKey(DuplicateCommand.DUPE_KEY), "The dupe key should no longer exist");
|
||||
assertFalse(way2.lastNode().hasKey(DuplicateCommand.KEY), "The dupe key should no longer exist");
|
||||
assertTrue(way1.lastNode().hasKey(DuplicateCommand.KEY), "The dupe key should no longer exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConflationConnKeyRemoval() {
|
||||
mapWithAIData.unlock();
|
||||
way1.lastNode().put(ConnectedCommand.CONN_KEY, "w" + Long.toString(way2.getUniqueId()) + ",n"
|
||||
way1.lastNode().put(ConnectedCommand.KEY, "w" + Long.toString(way2.getUniqueId()) + ",n"
|
||||
+ Long.toString(way2.lastNode().getUniqueId()) + ",n" + Long.toString(way2.firstNode().getUniqueId()));
|
||||
mapWithAIData.lock();
|
||||
mapWithAIData.addSelected(way1);
|
||||
|
||||
moveAction.actionPerformed(null);
|
||||
assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
|
||||
assertFalse(way2.firstNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
|
||||
assertFalse(way2.getNode(1).hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
|
||||
assertFalse(way2.lastNode().hasKey(ConnectedCommand.KEY), "The conn key should have been removed");
|
||||
assertFalse(way2.firstNode().hasKey(ConnectedCommand.KEY), "The conn key should have been removed");
|
||||
assertFalse(way2.getNode(1).hasKey(ConnectedCommand.KEY), "The conn key should have been removed");
|
||||
assertTrue(way1.isDeleted(), "way1 should be deleted when added");
|
||||
|
||||
UndoRedoHandler.getInstance().undo();
|
||||
assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key shouldn't exist");
|
||||
assertTrue(way1.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should exist");
|
||||
assertFalse(way2.lastNode().hasKey(ConnectedCommand.KEY), "The conn key shouldn't exist");
|
||||
assertTrue(way1.lastNode().hasKey(ConnectedCommand.KEY), "The conn key should exist");
|
||||
assertFalse(way1.lastNode().isDeleted(), "way1 should no longer be deleted");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,13 +82,13 @@ public class CreateConnectionsCommandTest {
|
|||
createConnections.undoCommand();
|
||||
assertFalse(dataSet.isModified(), "DataSet shouldn't be modified yet");
|
||||
|
||||
node3.put(ConnectedCommand.CONN_KEY,
|
||||
node3.put(ConnectedCommand.KEY,
|
||||
"w" + way.getUniqueId() + ",n" + node1.getUniqueId() + ",n" + node2.getUniqueId());
|
||||
createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(node3));
|
||||
createConnections.executeCommand();
|
||||
assertTrue(dataSet.isModified(), "DataSet should be modified");
|
||||
assertEquals(3, way.getNodesCount(), "The way should have three nodes");
|
||||
assertFalse(node3.hasKey(ConnectedCommand.CONN_KEY), "There should be no conn key");
|
||||
assertFalse(node3.hasKey(ConnectedCommand.KEY), "There should be no conn key");
|
||||
createConnections.fillModifiedData(modified, deleted, added);
|
||||
assertEquals(3, modified.size(),
|
||||
"There should be three modifications (the connecting way, the node, and the node again for key removal)");
|
||||
|
@ -97,22 +97,22 @@ public class CreateConnectionsCommandTest {
|
|||
createConnections.undoCommand();
|
||||
assertFalse(dataSet.isModified(), "DataSet is no longer modified");
|
||||
assertEquals(2, way.getNodesCount(), "The way should have two nodes again");
|
||||
assertTrue(node3.hasKey(ConnectedCommand.CONN_KEY), "The conn key should exist again");
|
||||
assertTrue(node3.hasKey(ConnectedCommand.KEY), "The conn key should exist again");
|
||||
|
||||
dupe.put(DuplicateCommand.DUPE_KEY, "n" + node1.getUniqueId());
|
||||
dupe.put(DuplicateCommand.KEY, "n" + node1.getUniqueId());
|
||||
createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(dupe));
|
||||
createConnections.executeCommand();
|
||||
assertTrue(dataSet.isModified(), "The DataSet should be modified");
|
||||
assertEquals(2, way.getNodesCount(), "The way should have two nodes");
|
||||
assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY), "There should no longer be a dupe key");
|
||||
assertFalse(node1.hasKey(DuplicateCommand.KEY), "There should no longer be a dupe key");
|
||||
modified.clear();
|
||||
createConnections.fillModifiedData(modified, deleted, added);
|
||||
assertEquals(2, modified.size(), "We removed a node and modified a way");
|
||||
assertTrue(deleted.isEmpty(), "Nothing was truly deleted (the dupe node doesn't count)");
|
||||
assertTrue(added.isEmpty(), "Nothing was added");
|
||||
createConnections.undoCommand();
|
||||
assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY), "The original node should not have the dupe key");
|
||||
assertTrue(dupe.hasKey(DuplicateCommand.DUPE_KEY), "The dupe node should have the dupe key");
|
||||
assertFalse(node1.hasKey(DuplicateCommand.KEY), "The original node should not have the dupe key");
|
||||
assertTrue(dupe.hasKey(DuplicateCommand.KEY), "The dupe node should have the dupe key");
|
||||
assertFalse(dataSet.isModified(), "The DataSet is no longer modified");
|
||||
assertEquals(2, way.getNodesCount(), "The way still has two nodes");
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class CreateConnectionsCommandTest {
|
|||
public void testGetMissingPrimitives() {
|
||||
final Node node1 = new Node(new LatLon(39.0674124, -108.5592645));
|
||||
final DataSet dataSet = new DataSet(node1);
|
||||
node1.put(DuplicateCommand.DUPE_KEY, "n6146500887");
|
||||
node1.put(DuplicateCommand.KEY, "n6146500887");
|
||||
Command replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1));
|
||||
|
||||
replaceNodeCommand.executeCommand();
|
||||
|
@ -191,7 +191,7 @@ public class CreateConnectionsCommandTest {
|
|||
"We don't roll back downloaded data");
|
||||
|
||||
node1.setCoor(new LatLon(39.067399, -108.5608433));
|
||||
node1.put(DuplicateCommand.DUPE_KEY, "n6151680832");
|
||||
node1.put(DuplicateCommand.KEY, "n6151680832");
|
||||
final OsmDataLayer layer = new OsmDataLayer(dataSet, "temp layer", null);
|
||||
MainApplication.getLayerManager().addLayer(layer);
|
||||
|
||||
|
|
|
@ -230,8 +230,8 @@ public class MapWithAIAddComandTest {
|
|||
String connectedValue = "w" + Long.toString(original.getUniqueId()) + ",n"
|
||||
+ Long.toString(original.firstNode().getUniqueId()) + ",n"
|
||||
+ Long.toString(original.lastNode().getUniqueId());
|
||||
way1.firstNode().put(ConnectedCommand.CONN_KEY, connectedValue);
|
||||
way2.firstNode().put(ConnectedCommand.CONN_KEY, connectedValue);
|
||||
way1.firstNode().put(ConnectedCommand.KEY, connectedValue);
|
||||
way2.firstNode().put(ConnectedCommand.KEY, connectedValue);
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
DataSet osmData = new DataSet();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// License: GPL. For details, see LICENSE file.
|
||||
package org.openstreetmap.josm.plugins.mapwithai.data.validation.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -37,17 +38,22 @@ public class ConnectingNodeInformationTestTest {
|
|||
test.startTest(null);
|
||||
test.visit(ds.allPrimitives());
|
||||
assertTrue(test.getErrors().isEmpty());
|
||||
way.firstNode().put(DuplicateCommand.DUPE_KEY, "n123");
|
||||
way.firstNode().put(DuplicateCommand.KEY, "n123");
|
||||
test.visit(ds.allPrimitives());
|
||||
assertEquals(1, test.getErrors().size());
|
||||
assertEquals(way.firstNode(), test.getErrors().get(0).getPrimitives().iterator().next());
|
||||
test.getErrors().get(0).getFix().executeCommand();
|
||||
assertFalse(way.firstNode().hasKey(DuplicateCommand.KEY));
|
||||
test.clear();
|
||||
|
||||
way.firstNode().put(DuplicateCommand.DUPE_KEY, null);
|
||||
way.put(ConnectedCommand.CONN_KEY, "w1,w2,n123");
|
||||
way.firstNode().put(DuplicateCommand.KEY, null);
|
||||
way.put(ConnectedCommand.KEY, "w1,w2,n123");
|
||||
test.visit(ds.allPrimitives());
|
||||
assertEquals(1, test.getErrors().size());
|
||||
assertEquals(way, test.getErrors().get(0).getPrimitives().iterator().next());
|
||||
test.getErrors().get(0).getFix().executeCommand();
|
||||
assertFalse(way.hasKey(ConnectedCommand.KEY));
|
||||
assertTrue(way.hasKeys());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue