kopia lustrzana https://github.com/JOSM/MapWithAI
Add test for getting missing primitives
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
f1d2e064c6
commit
9db795435c
|
@ -9,7 +9,7 @@ sp_cleanup.add_missing_nls_tags=false
|
||||||
sp_cleanup.add_missing_override_annotations=true
|
sp_cleanup.add_missing_override_annotations=true
|
||||||
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
sp_cleanup.add_missing_override_annotations_interface_methods=true
|
||||||
sp_cleanup.add_serial_version_id=false
|
sp_cleanup.add_serial_version_id=false
|
||||||
sp_cleanup.always_use_blocks=false
|
sp_cleanup.always_use_blocks=true
|
||||||
sp_cleanup.always_use_parentheses_in_expressions=false
|
sp_cleanup.always_use_parentheses_in_expressions=false
|
||||||
sp_cleanup.always_use_this_for_non_static_field_access=false
|
sp_cleanup.always_use_this_for_non_static_field_access=false
|
||||||
sp_cleanup.always_use_this_for_non_static_method_access=false
|
sp_cleanup.always_use_this_for_non_static_method_access=false
|
||||||
|
@ -52,7 +52,7 @@ sp_cleanup.sort_members=false
|
||||||
sp_cleanup.sort_members_all=false
|
sp_cleanup.sort_members_all=false
|
||||||
sp_cleanup.use_anonymous_class_creation=false
|
sp_cleanup.use_anonymous_class_creation=false
|
||||||
sp_cleanup.use_blocks=true
|
sp_cleanup.use_blocks=true
|
||||||
sp_cleanup.use_blocks_only_for_return_and_throw=true
|
sp_cleanup.use_blocks_only_for_return_and_throw=false
|
||||||
sp_cleanup.use_lambda=true
|
sp_cleanup.use_lambda=true
|
||||||
sp_cleanup.use_parentheses_in_expressions=false
|
sp_cleanup.use_parentheses_in_expressions=false
|
||||||
sp_cleanup.use_this_for_non_static_field_access=false
|
sp_cleanup.use_this_for_non_static_field_access=false
|
||||||
|
|
|
@ -68,9 +68,9 @@ public class CreateConnectionsCommand extends Command {
|
||||||
* connecting to
|
* connecting to
|
||||||
* @param collection The primitives with connection information (currently only
|
* @param collection The primitives with connection information (currently only
|
||||||
* checks Nodes)
|
* checks Nodes)
|
||||||
* @return
|
* @return A {@link SequenceCommand} to create connections with
|
||||||
*/
|
*/
|
||||||
public SequenceCommand createConnections(DataSet dataSet, Collection<OsmPrimitive> collection) {
|
public static SequenceCommand createConnections(DataSet dataSet, Collection<OsmPrimitive> collection) {
|
||||||
final Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
final Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
||||||
final List<Command> changedKeyList = new ArrayList<>();
|
final List<Command> changedKeyList = new ArrayList<>();
|
||||||
for (final Node node : nodes) {
|
for (final Node node : nodes) {
|
||||||
|
@ -85,7 +85,7 @@ public class CreateConnectionsCommand extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!changedKeyList.isEmpty()) {
|
if (!changedKeyList.isEmpty()) {
|
||||||
return new SequenceCommand(getDescriptionText(), changedKeyList);
|
return new SequenceCommand(getRealDescriptionText(), changedKeyList);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -162,12 +162,15 @@ public class CreateConnectionsCommand extends Command {
|
||||||
final Optional<OsmDataLayer> optionalLayer = MainApplication.getLayerManager()
|
final Optional<OsmDataLayer> optionalLayer = MainApplication.getLayerManager()
|
||||||
.getLayersOfType(OsmDataLayer.class).parallelStream()
|
.getLayersOfType(OsmDataLayer.class).parallelStream()
|
||||||
.filter(layer -> layer.getDataSet().equals(dataSet)).findFirst();
|
.filter(layer -> layer.getDataSet().equals(dataSet)).findFirst();
|
||||||
|
|
||||||
OsmDataLayer layer;
|
OsmDataLayer layer;
|
||||||
|
final String generatedLayerName = "EvKlVarShAiAllsM generated layer";
|
||||||
if (optionalLayer.isPresent()) {
|
if (optionalLayer.isPresent()) {
|
||||||
layer = optionalLayer.get();
|
layer = optionalLayer.get();
|
||||||
} else {
|
} else {
|
||||||
layer = new OsmDataLayer(dataSet, "generated layer", null);
|
layer = new OsmDataLayer(dataSet, generatedLayerName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(
|
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(
|
||||||
tr("Downloading additional OsmPrimitives"));
|
tr("Downloading additional OsmPrimitives"));
|
||||||
final DownloadPrimitivesTask downloadPrimitivesTask = new DownloadPrimitivesTask(layer, toFetch, true, monitor);
|
final DownloadPrimitivesTask downloadPrimitivesTask = new DownloadPrimitivesTask(layer, toFetch, true, monitor);
|
||||||
|
@ -177,6 +180,10 @@ public class CreateConnectionsCommand extends Command {
|
||||||
final OsmPrimitive primitive = dataSet.getPrimitiveById(entry.getKey());
|
final OsmPrimitive primitive = dataSet.getPrimitiveById(entry.getKey());
|
||||||
primitiveConnections[index] = primitive;
|
primitiveConnections[index] = primitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (generatedLayerName.equals(layer.getName())) {
|
||||||
|
layer.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,6 +225,10 @@ public class CreateConnectionsCommand extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescriptionText() {
|
public String getDescriptionText() {
|
||||||
|
return getRealDescriptionText();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRealDescriptionText() {
|
||||||
return tr("Create connections from {0} data", RapiDPlugin.NAME);
|
return tr("Create connections from {0} data", RapiDPlugin.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@ import org.openstreetmap.josm.data.coor.LatLon;
|
||||||
import org.openstreetmap.josm.data.osm.DataSet;
|
import org.openstreetmap.josm.data.osm.DataSet;
|
||||||
import org.openstreetmap.josm.data.osm.Node;
|
import org.openstreetmap.josm.data.osm.Node;
|
||||||
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
||||||
|
import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
||||||
import org.openstreetmap.josm.data.osm.Way;
|
import org.openstreetmap.josm.data.osm.Way;
|
||||||
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
|
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,6 +133,41 @@ public class CreateConnectionsCommandTest {
|
||||||
Assert.assertNull(CreateConnectionsCommand.replaceNode(node1, node2));
|
Assert.assertNull(CreateConnectionsCommand.replaceNode(node1, node2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if we get missing primitives
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetMissingPrimitives() {
|
||||||
|
final Node node1 = new Node(new LatLon(39.0674124, -108.5592645));
|
||||||
|
final DataSet dataSet = new DataSet(node1);
|
||||||
|
node1.put(CreateConnectionsCommand.DUPE_KEY, "n6146500887");
|
||||||
|
Command replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet,
|
||||||
|
Collections.singleton(node1));
|
||||||
|
|
||||||
|
replaceNodeCommand.executeCommand();
|
||||||
|
Assert.assertEquals(1, dataSet.allNonDeletedPrimitives().size());
|
||||||
|
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE));
|
||||||
|
|
||||||
|
replaceNodeCommand.undoCommand();
|
||||||
|
Assert.assertEquals(2, dataSet.allNonDeletedPrimitives().size()); // We don't roll back downloaded data
|
||||||
|
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE));
|
||||||
|
|
||||||
|
node1.setCoor(new LatLon(39.067399, -108.5608433));
|
||||||
|
node1.put(CreateConnectionsCommand.DUPE_KEY, "n6151680832");
|
||||||
|
OsmDataLayer layer = new OsmDataLayer(dataSet, "temp layer", null);
|
||||||
|
MainApplication.getLayerManager().addLayer(layer);
|
||||||
|
|
||||||
|
replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1));
|
||||||
|
replaceNodeCommand.executeCommand();
|
||||||
|
Assert.assertEquals(2, dataSet.allNonDeletedPrimitives().size());
|
||||||
|
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE));
|
||||||
|
|
||||||
|
replaceNodeCommand.undoCommand();
|
||||||
|
Assert.assertEquals(3, dataSet.allNonDeletedPrimitives().size()); // We don't roll back downloaded data
|
||||||
|
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link CreateConnectionsCommand#getDescriptionText()}.
|
* Test method for {@link CreateConnectionsCommand#getDescriptionText()}.
|
||||||
*/
|
*/
|
||||||
|
|
Ładowanie…
Reference in New Issue