Skip to content

Commit

Permalink
Cleanup some lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Oct 25, 2023
1 parent 1d1f3a2 commit c9bd37b
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CreateNewStopPointOperation(DataSet currentDataSet) {
/**
* The *result* does not depend on the current map selection state, neither does
* the result *order*. It solely depends on the distance to point p.
*
* <p>
* This code is coped from JOSM code
*
* @return a sorted map with the keys representing the distance of their
Expand All @@ -58,7 +58,8 @@ private Map<Double, List<Node>> getNearestNodesImpl(Point p) {
DataSet ds = getCurrentDataSet();

if (ds != null) {
double dist, snapDistanceSq = 200;
double dist;
double snapDistanceSq = 200;
snapDistanceSq *= snapDistanceSq;

for (Node n : ds.searchNodes(getBBox(p, 200))) {
Expand All @@ -85,7 +86,7 @@ private Map<Double, List<Node>> getNearestNodesImpl(Point p) {
* @param snapDistance Distance for search
* @return Area
*/
private BBox getBBox(Point p, int snapDistance) {
private static BBox getBBox(Point p, int snapDistance) {
MapView mapView = MainApplication.getMap().mapView;
return new BBox(mapView.getLatLon(p.x - snapDistance, p.y - snapDistance),
mapView.getLatLon(p.x + snapDistance, p.y + snapDistance));
Expand All @@ -100,22 +101,18 @@ private BBox getBBox(Point p, int snapDistance) {
*/
public AbstractMap.SimpleEntry<Double, Node> getNearestNode(LatLon platformCoord, StopArea stopArea) {
Point p = MainApplication.getMap().mapView.getPoint(platformCoord);
Map<Double, List<Node>> dist_nodes = getNearestNodesImpl(p);
Double[] distances = dist_nodes.keySet().toArray(new Double[0]);
Map<Double, List<Node>> distNodes = getNearestNodesImpl(p);
Double[] distances = distNodes.keySet().toArray(new Double[0]);
Arrays.sort(distances);
Integer distanceIndex = -1;
Node nearestNode = null;
while (++distanceIndex < distances.length && nearestNode == null) {
List<Node> nodes = dist_nodes.get(distances[distanceIndex]);
int distanceIndex = -1;
while (++distanceIndex < distances.length) {
List<Node> nodes = distNodes.get(distances[distanceIndex]);
for (Node node : nodes) {
for (Way way : getCurrentDataSet().getWays()) {
if (way.getNodes().contains(node) && testWay(way, stopArea)) {
nearestNode = node;
return new AbstractMap.SimpleEntry<>(distances[distanceIndex], nearestNode);
return new AbstractMap.SimpleEntry<>(distances[distanceIndex], node);
}
}
if (nearestNode != null)
break;
}
}
return null;
Expand All @@ -128,7 +125,7 @@ public AbstractMap.SimpleEntry<Double, Node> getNearestNode(LatLon platformCoord
* @param stopArea Stop area
* @return true, if way can contain stop position
*/
public Boolean testWay(final Way way, final StopArea stopArea) {
public boolean testWay(final Way way, final StopArea stopArea) {
if (stopArea.isTrainStation || stopArea.isTrainStop) {
return OSMTags.RAIL_TAG_VALUE.equals(way.getKeys().get(OSMTags.RAILWAY_TAG)) &&
OSMTags.MAIN_TAG_VALUE.equals(way.getKeys().get(OSMTags.USAGE_TAG));
Expand All @@ -149,7 +146,7 @@ public Boolean testWay(final Way way, final StopArea stopArea) {
/**
* The *result* does not depend on the current map selection state, neither does
* the result *order*. It solely depends on the distance to point p.
*
* <p>
* This code is coped from JOSM code
*
* @return a sorted map with the keys representing the perpendicular distance of
Expand All @@ -176,17 +173,17 @@ private Map<Double, List<IWaySegment<Node, Way>>> getNearestWaySegmentsImpl(Poin
continue;
}

Point2D A = MainApplication.getMap().mapView.getPoint2D(lastN);
Point2D B = MainApplication.getMap().mapView.getPoint2D(n);
double c = A.distanceSq(B);
double a = p.distanceSq(B);
double b = p.distanceSq(A);
Point2D pointA = MainApplication.getMap().mapView.getPoint2D(lastN);
Point2D pointB = MainApplication.getMap().mapView.getPoint2D(n);
double c = pointA.distanceSq(pointB);
double a = p.distanceSq(pointB);
double b = p.distanceSq(pointA);

/*
* perpendicular distance squared loose some precision to account for possible
* deviations in the calculation above e.g. if identical (A and B) come about
* reversed in another way, values may differ -- zero out least significant 32
* dual digits of mantissa..
* dual digits of mantissa.
*/
double perDistSq = Double.longBitsToDouble(
// resolution in numbers with large exponent not needed here..
Expand Down Expand Up @@ -221,8 +218,8 @@ private Map<Double, List<IWaySegment<Node, Way>>> getNearestWaySegmentsImpl(Poin
protected NearestWaySegment getNearestWaySegment(LatLon platformCoord, StopArea stopArea) {
MapView mapView = MainApplication.getMap().mapView;
Point p = mapView.getPoint(platformCoord);
Map<Double, List<IWaySegment<Node, Way>>> dist_waySegments = getNearestWaySegmentsImpl(p);
for (Map.Entry<Double, List<IWaySegment<Node, Way>>> entry : dist_waySegments.entrySet()) {
Map<Double, List<IWaySegment<Node, Way>>> distWaySegments = getNearestWaySegmentsImpl(p);
for (Map.Entry<Double, List<IWaySegment<Node, Way>>> entry : distWaySegments.entrySet()) {
for (IWaySegment<Node, Way> waySegment : entry.getValue()) {
if (testWay(waySegment.getWay(), stopArea)) {
INode n = waySegment.getFirstNode();
Expand All @@ -234,7 +231,7 @@ protected NearestWaySegment getNearestWaySegment(LatLon platformCoord, StopArea
Point2D lastN2D = mapView.getPoint2D(lastN);
Point2D n2D = mapView.getPoint2D(n);
Point2D newNodePosition2D = mapView.getPoint2D(newNodePosition);
Double distCurrenNodes = lastN2D.distance(n2D);
double distCurrenNodes = lastN2D.distance(n2D);
if ((newNodePosition2D.distance(lastN2D) < distCurrenNodes)
&& (newNodePosition2D.distance(n2D) < distCurrenNodes)) {
return new NearestWaySegment(entry.getKey(), waySegment, new Node(newNodePosition));
Expand Down Expand Up @@ -281,7 +278,7 @@ public StopArea performCustomizing(StopArea stopArea) {
Node newStopPointNode = null;
if (nearestNode != null && nearestWaySegment != null) {
MapView mapView = MainApplication.getMap().mapView;
Double segmentDist = mapView.getPoint2D(platformCoord)
double segmentDist = mapView.getPoint2D(platformCoord)
.distanceSq(mapView.getPoint2D(nearestWaySegment.newNode));
Double nodeDistSq = nearestNode.getKey();
// nodeDistSq *= nodeDistSq - 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean testIsTransportTypeAssigned(OsmPrimitive platform) {
* @param stopArea Selected stop area
*/
public void fromSelectedObject(StopArea stopArea) {
Collection<OsmPrimitive> selectedObjects = new ArrayList<OsmPrimitive>();
Collection<OsmPrimitive> selectedObjects = new ArrayList<>();
selectedObjects.add(stopArea.selectedObject);
for (Relation rel : OsmPrimitive.getParentRelations(selectedObjects)) {
if (compareTag(rel, OSMTags.KEY_RELATION_TYPE, OSMTags.PUBLIC_TRANSPORT_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public class CustomizePublicTransportStopDialog implements ActionListener, ItemL
private static final String CITY_NETWORK_CAPTION = I18n.marktr("City transport");
private static final String HIGH_SPEED_NETWORK_CAPTION = I18n.marktr("High speed");

private String[] serviceCaptionStrings = {CITY_NETWORK_CAPTION, COMMUTER_NETWORK_CAPTION, REGIONAL_NETWORK_CAPTION,
private final String[] serviceCaptionStrings = {CITY_NETWORK_CAPTION, COMMUTER_NETWORK_CAPTION, REGIONAL_NETWORK_CAPTION,
LONG_DISTANCE_NETWORK_CAPTION, HIGH_SPEED_NETWORK_CAPTION};
private String[] serviceStrings = {OSMTags.CITY_NETWORK_TAG_VALUE, OSMTags.COMMUTER_NETWORK_TAG_VALUE,
private final String[] serviceStrings = {OSMTags.CITY_NETWORK_TAG_VALUE, OSMTags.COMMUTER_NETWORK_TAG_VALUE,
OSMTags.REGIONAL_NETWORK_TAG_VALUE, OSMTags.LONG_DISTANCE_NETWORK_TAG_VALUE,
OSMTags.HIGH_SPEED_NETWORK_TAG_VALUE};

private JDialog jDialog = null;
private JTextField textFieldName = null;
private JDialog jDialog;
private JTextField textFieldName;
private JTextField textFieldNameEn;
private JTextField textFieldNetwork;
private JTextField textFieldOperator;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class CustomizePublicTransportStopDialog implements ActionListener, ItemL
/**
* Map of check boxes
*/
private HashMap<JCheckBox, Boolean> checkBoxValues = new HashMap<JCheckBox, Boolean>();
private final HashMap<JCheckBox, Boolean> checkBoxValues = new HashMap<>();

/**
* Previous stop name
Expand All @@ -112,11 +112,11 @@ public class CustomizePublicTransportStopDialog implements ActionListener, ItemL
/**
* Network name at previous call
*/
private static String previousNetwork = null;
private static String previousNetwork;
/**
* Operator name at previous call
*/
private static String previousOperator = null;
private static String previousOperator;

/**
* Reference to dialog object
Expand Down Expand Up @@ -238,7 +238,7 @@ private JPanel createContentPane() {
for (int i = 0; i < serviceCaptionStrings.length; i++) {
serviceTransStrings[i] = tr(serviceCaptionStrings[i]);
}
comboBoxService = new JComboBox<String>(serviceTransStrings);
comboBoxService = new JComboBox<>(serviceTransStrings);
comboBoxService.setSelectedIndex(0);
layoutCons.gridx = 1;
layoutCons.gridy = 4;
Expand Down Expand Up @@ -435,7 +435,7 @@ public void setCustomizeStopAction(CustomizeStopAction newCustomizeStopAction) {
* @param checkBox Check box
* @param value Value of check box
*/
public void setCheckBoxValue(JCheckBox checkBox, Boolean value) {
public void setCheckBoxValue(JCheckBox checkBox, boolean value) {
checkBoxValues.put(checkBox, value);
checkBox.setSelected(value);
}
Expand All @@ -446,7 +446,7 @@ public void setCheckBoxValue(JCheckBox checkBox, Boolean value) {
* @param checkBox Check box
* @return Value of check box
*/
public Boolean getCheckBoxValue(JCheckBox checkBox) {
public boolean getCheckBoxValue(JCheckBox checkBox) {
try {
if (checkBoxValues.containsKey(checkBox)) {
return checkBoxValues.get(checkBox);
Expand Down Expand Up @@ -476,7 +476,7 @@ public void itemStateChanged(ItemEvent event) {
*
* @param isVisible Flag of dialog visibility
*/
public void setVisible(Boolean isVisible) {
public void setVisible(boolean isVisible) {
if (jDialog != null)
jDialog.setVisible(isVisible);
}
Expand Down Expand Up @@ -554,35 +554,39 @@ public String getTextFromControl(JTextField textField) {
* @return Stop area
*/
public StopArea saveValues() {
StopArea stopArea = this.stopArea;
StopArea currentStopArea = this.stopArea;
try {
if (stopArea == null)
stopArea = new StopArea();
stopArea.name = getTextFromControl(textFieldName);
previousName = stopArea.name;
stopArea.nameEn = getTextFromControl(textFieldNameEn);
previousNameEn = stopArea.nameEn;
stopArea.network = getTextFromControl(textFieldNetwork);
previousNetwork = stopArea.network;
stopArea.operator = getTextFromControl(textFieldOperator);
previousOperator = stopArea.operator;
stopArea.service = serviceStrings[comboBoxService.getSelectedIndex()];
stopArea.isBus = getCheckBoxValue(checkBoxIsBus);
stopArea.isShareTaxi = getCheckBoxValue(checkBoxIsShareTaxi);
stopArea.isTrolleybus = getCheckBoxValue(checkBoxIsTrolleybus);
stopArea.isBusStation = getCheckBoxValue(checkBoxIsBusStation);
stopArea.isAssignTransportType = getCheckBoxValue(checkBoxIsAssignTransportType);
stopArea.isTram = getCheckBoxValue(checkBoxIsTram);
stopArea.isTrainStation = getCheckBoxValue(checkBoxIsTrainStation);
stopArea.isTrainStop = getCheckBoxValue(checkBoxIsTrainStop);
stopArea.isBench = getCheckBoxValue(checkBoxIsBench);
stopArea.isShelter = getCheckBoxValue(checkBoxIsShelder);
stopArea.isCovered = getCheckBoxValue(checkBoxIsCover);
stopArea.isArea = getCheckBoxValue(checkBoxIsArea);
if (currentStopArea == null)
currentStopArea = new StopArea();
currentStopArea.name = getTextFromControl(textFieldName);
currentStopArea.nameEn = getTextFromControl(textFieldNameEn);
currentStopArea.network = getTextFromControl(textFieldNetwork);
currentStopArea.operator = getTextFromControl(textFieldOperator);
currentStopArea.service = serviceStrings[comboBoxService.getSelectedIndex()];
currentStopArea.isBus = getCheckBoxValue(checkBoxIsBus);
currentStopArea.isShareTaxi = getCheckBoxValue(checkBoxIsShareTaxi);
currentStopArea.isTrolleybus = getCheckBoxValue(checkBoxIsTrolleybus);
currentStopArea.isBusStation = getCheckBoxValue(checkBoxIsBusStation);
currentStopArea.isAssignTransportType = getCheckBoxValue(checkBoxIsAssignTransportType);
currentStopArea.isTram = getCheckBoxValue(checkBoxIsTram);
currentStopArea.isTrainStation = getCheckBoxValue(checkBoxIsTrainStation);
currentStopArea.isTrainStop = getCheckBoxValue(checkBoxIsTrainStop);
currentStopArea.isBench = getCheckBoxValue(checkBoxIsBench);
currentStopArea.isShelter = getCheckBoxValue(checkBoxIsShelder);
currentStopArea.isCovered = getCheckBoxValue(checkBoxIsCover);
currentStopArea.isArea = getCheckBoxValue(checkBoxIsArea);
setPreviousFields(stopArea);
} catch (Exception ex) {
DialogUtils.showOkWarning("Exception when saving preferences!", ex.getMessage());
}
return stopArea;
return currentStopArea;
}

private static void setPreviousFields(StopArea stopArea) {
previousName = stopArea.name;
previousNameEn = stopArea.nameEn;
previousNetwork = stopArea.network;
previousOperator = stopArea.operator;
}

/**
Expand All @@ -593,8 +597,8 @@ public void actionPerformed(ActionEvent event) {
if (SAVE_COMMAND.equals(event.getActionCommand())) {
setVisible(false);
if (customizeStopAction != null) {
StopArea stopArea = saveValues();
customizeStopAction.performCustomizing(stopArea);
StopArea currentStopArea = saveValues();
customizeStopAction.performCustomizing(currentStopArea);
}
} else {
setVisible(false);
Expand Down
Loading

0 comments on commit c9bd37b

Please sign in to comment.