More checkstyle and error prone fixes

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-03 14:16:52 -06:00
rodzic c9f2201a16
commit f1d2e064c6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
11 zmienionych plików z 141 dodań i 81 usunięć

Wyświetl plik

@ -39,7 +39,7 @@ public class RapiDPreferences implements SubPreferenceSetting {
final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
final JLabel maximumAddition = new JLabel(tr("Maximum features (add)"));
final JPanel container = new JPanel(new GridBagLayout());
container.setAlignmentY(JPanel.TOP_ALIGNMENT);
container.setAlignmentY(Component.TOP_ALIGNMENT);
final GridBagConstraints constraints = new GridBagConstraints();
possibleRapidApiUrl.setEditable(true);
@ -53,7 +53,7 @@ public class RapiDPreferences implements SubPreferenceSetting {
}
possibleRapidApiUrl.setSelectedItem(RapiDDataUtils.getRapiDURL());
switchLayerCheckBox.setSelected(RapiDDataUtils.getSwitchLayers());
switchLayerCheckBox.setSelected(RapiDDataUtils.isSwitchLayers());
constraints.gridx = 0;
constraints.gridy = 0;

Wyświetl plik

@ -86,45 +86,58 @@ public final class RapiDDataUtils {
@Override
public void run() {
final DataSet temporaryDataSet = getDataReal(bbox);
final DataSet temporaryDataSet = getDataReal(getBbox());
synchronized (RapiDDataUtils.GetDataRunnable.class) {
dataSet.mergeFrom(temporaryDataSet);
getDataSet().mergeFrom(temporaryDataSet);
}
}
}
/**
* @return The {@code BBox} associated with this object
*/
public BBox getBbox() {
return bbox;
}
private static DataSet getDataReal(BBox bbox) {
InputStream inputStream = null;
final DataSet dataSet = new DataSet();
final String urlString = getRapiDURL();
try {
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
final HttpClient client = HttpClient.create(url);
final StringBuilder defaultUserAgent = new StringBuilder();
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
if (defaultUserAgent.toString().trim().length() == 0) {
defaultUserAgent.append("JOSM");
}
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
client.setHeader("User-Agent", defaultUserAgent.toString());
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
final Response response = client.connect();
inputStream = response.getContent();
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
response.disconnect();
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
Logging.debug(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (final IOException e) {
Logging.debug(e);
/**
* @return The {@code DataSet} associated with this object
*/
public DataSet getDataSet() {
return dataSet;
}
private static DataSet getDataReal(BBox bbox) {
InputStream inputStream = null;
final DataSet dataSet = new DataSet();
final String urlString = getRapiDURL();
try {
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
final HttpClient client = HttpClient.create(url);
final StringBuilder defaultUserAgent = new StringBuilder();
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
if (defaultUserAgent.toString().trim().length() == 0) {
defaultUserAgent.append("JOSM");
}
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
client.setHeader("User-Agent", defaultUserAgent.toString());
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
final Response response = client.connect();
inputStream = response.getContent();
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
response.disconnect();
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
Logging.debug(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (final IOException e) {
Logging.debug(e);
}
}
}
return dataSet;
}
return dataSet;
}
/**
@ -263,7 +276,7 @@ public final class RapiDDataUtils {
/**
* @return {@code true} if we want to automatically switch layers
*/
public static boolean getSwitchLayers() {
public static boolean isSwitchLayers() {
return Config.getPref().getBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), true);
}

Wyświetl plik

@ -50,7 +50,7 @@ public class RapiDMoveAction extends JosmAction {
if (editLayer != null) {
final RapiDAddCommand command = new RapiDAddCommand(rapid, editLayer, selected);
UndoRedoHandler.getInstance().add(command);
if (RapiDDataUtils.getSwitchLayers()) {
if (RapiDDataUtils.isSwitchLayers()) {
MainApplication.getLayerManager().setActiveLayer(editLayer);
final DataSet editable = editLayer.getDataSet();
editable.setSelected(

Wyświetl plik

@ -14,35 +14,36 @@ import org.openstreetmap.josm.data.osm.Way;
public class AddNodeToWayCommand extends Command {
private final Node toAddNode;
private final Way way;
private final Node first;
private final Node second;
private final Node firstNode;
private final Node secondNode;
/**
* Add a node to a way in an undoable manner
*
* @param toAddNode The node to add
* @param way The way to add the node to
* @param first The node that comes before the node to add
* @param second The node that comes after the node to add
* @param toAddNode The node to add
* @param way The way to add the node to
* @param firstNode The node that comes before the node to add
* @param secondNode The node that comes after the node to add
*/
public AddNodeToWayCommand(Node toAddNode, Way way, Node first, Node second) {
super(way.getDataSet());
this.toAddNode = toAddNode;
this.way = way;
this.first = first;
this.second = second;
this.firstNode = first;
this.secondNode = second;
}
@Override
public boolean executeCommand() {
final int index = Math.max(way.getNodes().indexOf(first), way.getNodes().indexOf(second));
way.addNode(index, toAddNode);
final int index = Math.max(getWay().getNodes().indexOf(getFirstNode()),
getWay().getNodes().indexOf(getSecondNode()));
getWay().addNode(index, getToAddNode());
return true;
}
@Override
public void undoCommand() {
way.removeNode(toAddNode);
getWay().removeNode(getToAddNode());
}
@Override
@ -53,6 +54,34 @@ public class AddNodeToWayCommand extends Command {
@Override
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
Collection<OsmPrimitive> added) {
modified.addAll(Arrays.asList(toAddNode, way));
modified.addAll(Arrays.asList(getToAddNode(), getWay()));
}
/**
* @return {@link Node} to add to {@link Way}
*/
public Node getToAddNode() {
return toAddNode;
}
/**
* @return {@link Way} that we are adding a {@link Node} to
*/
public Way getWay() {
return way;
}
/**
* @return {@link Node} that we are adding another {@link Node} after.
*/
public Node getFirstNode() {
return firstNode;
}
/**
* @return {@link Node} that we are adding another {@link Node} before.
*/
public Node getSecondNode() {
return secondNode;
}
}

Wyświetl plik

@ -150,11 +150,11 @@ public class CreateConnectionsCommand extends Command {
missingPrimitives.put(i, new Pair<>(id, type));
}
}
getMissingPrimitives(dataSet, primitiveConnections, missingPrimitives);
obtainMissingPrimitives(dataSet, primitiveConnections, missingPrimitives);
return primitiveConnections;
}
private static void getMissingPrimitives(DataSet dataSet, OsmPrimitive[] primitiveConnections,
private static void obtainMissingPrimitives(DataSet dataSet, OsmPrimitive[] primitiveConnections,
Map<Integer, Pair<Long, OsmPrimitiveType>> missingPrimitives) {
final Map<PrimitiveId, Integer> ids = missingPrimitives.entrySet().stream().collect(Collectors
.toMap(entry -> new SimplePrimitiveId(entry.getValue().a, entry.getValue().b), Entry::getKey));

Wyświetl plik

@ -25,14 +25,13 @@ public class MovePrimitiveDataSetCommand extends Command {
private final DataSet to;
private final DataSet from;
private final Collection<OsmPrimitive> primitives;
private SequenceCommand command;
private SequenceCommand command = null;
public MovePrimitiveDataSetCommand(DataSet to, DataSet from, Collection<OsmPrimitive> primitives) {
super(to);
this.to = to;
this.from = from;
this.primitives = primitives;
command = null;
}
@Override
@ -52,22 +51,23 @@ public class MovePrimitiveDataSetCommand extends Command {
* @param selection The primitives to move
*/
public SequenceCommand moveCollection(DataSet from, DataSet to, Collection<OsmPrimitive> selection) {
SequenceCommand returnCommand = null;
if (from == null || to.isLocked() || from.isLocked() || to.equals(from)) {
Logging.error("{0}: Cannot move primitives from {1} to {2}", RapiDPlugin.NAME, from, to);
return null;
} else {
final List<Command> commands = new ArrayList<>();
final Collection<OsmPrimitive> allNeededPrimitives = new ArrayList<>();
RapiDDataUtils.addPrimitivesToCollection(allNeededPrimitives, selection);
commands.add(new DeletePrimitivesCommand(from, selection, true));
final AddPrimitivesCommand addPrimitivesCommand = new AddPrimitivesCommand(to, allNeededPrimitives, selection);
commands.add(addPrimitivesCommand);
returnCommand = new SequenceCommand(trn("Move {0} OSM Primitive between data sets",
"Move {0} OSM Primitives between data sets", selection.size(), selection.size()), commands);
}
final List<Command> commands = new ArrayList<>();
final Collection<OsmPrimitive> allNeededPrimitives = new ArrayList<>();
RapiDDataUtils.addPrimitivesToCollection(allNeededPrimitives, selection);
commands.add(new DeletePrimitivesCommand(from, selection, true));
final AddPrimitivesCommand addPrimitivesCommand = new AddPrimitivesCommand(to, allNeededPrimitives, selection);
commands.add(addPrimitivesCommand);
return new SequenceCommand(trn("Move {0} OSM Primitive between data sets",
"Move {0} OSM Primitives between data sets", selection.size(), selection.size()), commands);
return returnCommand;
}
@Override

Wyświetl plik

@ -43,16 +43,16 @@ public class RapiDPreferencesTest {
Assert.assertEquals(tabs + 1, pane.getPluginPreference().getTabPane().getTabCount());
Assert.assertEquals(pane.getPluginPreference(), preferences.getTabPreferenceSetting(pane));
final boolean switchLayers = RapiDDataUtils.getSwitchLayers();
final boolean switchLayers = RapiDDataUtils.isSwitchLayers();
Assert.assertEquals(switchLayers, preferences.getSwitchLayerCheckBox().isSelected());
preferences.ok();
Assert.assertEquals(switchLayers, RapiDDataUtils.getSwitchLayers());
Assert.assertEquals(switchLayers, RapiDDataUtils.isSwitchLayers());
preferences.getSwitchLayerCheckBox().setSelected(!switchLayers);
Assert.assertNotEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
Assert.assertNotEquals(!switchLayers, RapiDDataUtils.isSwitchLayers());
preferences.ok();
Assert.assertEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
Assert.assertEquals(!switchLayers, RapiDDataUtils.isSwitchLayers());
final Object tmp = preferences.getMaximumAdditionSpinner().getModel();
SpinnerNumberModel spinnerModel = null;

Wyświetl plik

@ -22,7 +22,7 @@ public class RapiDMoveActionTest {
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection();
@Before
public void setup() {
public void setUp() {
moveAction = new RapiDMoveAction();
}

Wyświetl plik

@ -14,7 +14,7 @@ import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.testutils.JOSMTestRules;;
import org.openstreetmap.josm.testutils.JOSMTestRules;
public class AddNodeToWayCommandTest {
private Node toAdd;

Wyświetl plik

@ -34,7 +34,7 @@ public class MovePrimitiveDataSetCommandTest {
from.addPrimitive(way1);
from.addPrimitive(new Node(new LatLon(-0.1, 0.1)));
MovePrimitiveDataSetCommand move = new MovePrimitiveDataSetCommand(to, from, Collections.singleton(way1));
final MovePrimitiveDataSetCommand move = new MovePrimitiveDataSetCommand(to, from, Collections.singleton(way1));
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
@ -51,6 +51,22 @@ public class MovePrimitiveDataSetCommandTest {
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
Assert.assertEquals(from, way1.getDataSet());
}
@Test
public void testMovePrimitivesAdditionalData() {
final Collection<OsmPrimitive> added = new ArrayList<>();
final Collection<OsmPrimitive> modified = new ArrayList<>();
final Collection<OsmPrimitive> deleted = new ArrayList<>();
final DataSet to = new DataSet();
final DataSet from = new DataSet();
final Way way1 = TestUtils.newWay("highway=tertiary", new Node(new LatLon(0, 0)),
new Node(new LatLon(0.1, 0.1)));
way1.getNodes().stream().forEach(node -> from.addPrimitive(node));
from.addPrimitive(way1);
from.addPrimitive(new Node(new LatLon(-0.1, 0.1)));
MovePrimitiveDataSetCommand move = new MovePrimitiveDataSetCommand(to, from, Collections.singleton(way1));
way1.firstNode().put("highway", "stop");

Wyświetl plik

@ -16,6 +16,8 @@ import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.testutils.JOSMTestRules;
public class RapiDAddComandTest {
private final static String HIGHWAY_RESIDENTIAL = "highway=residential";
@Rule
public JOSMTestRules test = new JOSMTestRules();
@ -23,10 +25,10 @@ public class RapiDAddComandTest {
public void testMoveCollection() {
final DataSet ds1 = new DataSet();
final DataSet ds2 = new DataSet();
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
final Way way1 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)),
new Node(new LatLon(0, 0.1)));
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
final Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(65, 65)),
final Way way2 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
final Way way3 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(65, 65)),
new Node(new LatLon(66, 66)));
for (final Way way : Arrays.asList(way1, way2, way3)) {
for (final Node node : way.getNodes()) {
@ -68,14 +70,14 @@ public class RapiDAddComandTest {
@Test
public void testCreateConnections() {
final DataSet ds1 = new DataSet();
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
final Way way1 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)),
new Node(new LatLon(0, 0.15)));
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0.05)),
final Way way2 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0.05)),
new Node(new LatLon(0.05, 0.2)));
way2.firstNode().put("conn",
"w".concat(Long.toString(way1.getUniqueId())).concat(",n")
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
.concat(Long.toString(way1.lastNode().getUniqueId())));
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
.concat(Long.toString(way1.lastNode().getUniqueId())));
way1.getNodes().forEach(node -> ds1.addPrimitive(node));
way2.getNodes().forEach(node -> ds1.addPrimitive(node));
ds1.addPrimitive(way2);
@ -84,7 +86,7 @@ public class RapiDAddComandTest {
Assert.assertEquals(3, way1.getNodesCount());
Assert.assertFalse(way1.isFirstLastNode(way2.firstNode()));
final Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
final Way way3 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)),
new Node(new LatLon(-0.1, -0.1)));
way3.firstNode().put("dupe", "n".concat(Long.toString(way1.firstNode().getUniqueId())));
way3.getNodes().forEach(node -> ds1.addPrimitive(node));
@ -100,9 +102,9 @@ public class RapiDAddComandTest {
public void testCreateConnectionsUndo() {
final DataSet osmData = new DataSet();
final DataSet rapidData = new DataSet();
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
final Way way1 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)),
new Node(new LatLon(0.1, 0.1)));
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.1)),
final Way way2 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(-0.1, -0.1)),
new Node(new LatLon(0.1, 0.1)));
way1.getNodes().forEach(node -> rapidData.addPrimitive(node));
way2.getNodes().forEach(node -> osmData.addPrimitive(node));