Index: /applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java
===================================================================
--- /applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java	(revision 36131)
+++ /applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java	(revision 36132)
@@ -55,8 +55,10 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.data.osm.Tagged;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.widgets.UrlLabel;
 import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Logging;
 
 /**
@@ -65,11 +67,11 @@
 public class AddrInterpolationDialog extends JDialog implements ActionListener {
 
-    private Way selectedStreet = null;
-    private Way addrInterpolationWay = null;
-    private Relation associatedStreetRelation = null;
-    private ArrayList<Node> houseNumberNodes = null;  // Additional nodes with addr:housenumber
+    private Way selectedStreet;
+    private Way addrInterpolationWay;
+    private Relation associatedStreetRelation;
+    private ArrayList<Node> houseNumberNodes;  // Additional nodes with addr:housenumber
 
     private static String lastIncrement = "";
-    private static int lastAccuracyIndex = 0;
+    private static int lastAccuracyIndex;
     private static String lastCity = "";
     private static String lastState = "";
@@ -77,23 +79,23 @@
     private static String lastCountry = "";
     private static String lastFullAddress = "";
-    private static boolean lastConvertToHousenumber = false;
+    private static boolean lastConvertToHousenumber;
 
     // Edit controls
-    private EscapeDialog dialog = null;
-    private JRadioButton streetNameButton = null;
-    private JRadioButton streetRelationButton = null;
-    private JTextField startTextField = null;
-    private JTextField endTextField = null;
-    private JTextField incrementTextField = null;
-    private JTextField cityTextField = null;
-    private JTextField stateTextField = null;
-    private JTextField postCodeTextField = null;
-    private JTextField countryTextField = null;
-    private JTextField fullTextField = null;
-    private Checkbox cbConvertToHouseNumbers = null;
-
-    private boolean relationChanged = false; // Whether to re-trigger data changed for relation
+    private EscapeDialog dialog;
+    private JRadioButton streetNameButton;
+    private JRadioButton streetRelationButton;
+    private JTextField startTextField;
+    private JTextField endTextField;
+    private JTextField incrementTextField;
+    private JTextField cityTextField;
+    private JTextField stateTextField;
+    private JTextField postCodeTextField;
+    private JTextField countryTextField;
+    private JTextField fullTextField;
+    private Checkbox cbConvertToHouseNumbers;
+
+    private boolean relationChanged; // Whether to re-trigger data changed for relation
     // Track whether interpolation method is known so that auto detect doesn't override a previous choice.
-    private boolean interpolationMethodSet = false;
+    private boolean interpolationMethodSet;
 
     // NOTE: The following 2 arrays must match in number of elements and position
@@ -101,28 +103,37 @@
     String[] addrInterpolationTags = {"odd", "even", "all", "alphabetic", "Numeric"};
     String[] addrInterpolationStrings = {tr("Odd"), tr("Even"), tr("All"), tr("Alphabetic"), tr("Numeric") }; // Translatable names for display
-    private final int NumericIndex = 4;
-    private JComboBox<String> addrInterpolationList = null;
+    private static final int NUMERIC_INDEX = 4;
+    private JComboBox<String> addrInterpolationList;
 
     // NOTE: The following 2 arrays must match in number of elements and position
     String[] addrInclusionTags = {"actual", "estimate", "potential" }; // Tag values for map
     String[] addrInclusionStrings = {tr("Actual"), tr("Estimate"), tr("Potential") }; // Translatable names for display
-    private JComboBox<String> addrInclusionList = null;
+    private JComboBox<String> addrInclusionList;
 
     // For tracking edit changes as group for undo
-    private Collection<Command> commandGroup = null;
-    private Relation editedRelation = null;
-
+    private Collection<Command> commandGroup;
+    private Relation editedRelation;
+
+    /**
+     * Create a new address interpolation dialog with a specified name
+     * @param name The name to show in the title bar
+     */
     public AddrInterpolationDialog(String name) {
 
-        if (!FindAndSaveSelections()) {
+        if (!findAndSaveSelections()) {
             return;
         }
 
-        JPanel editControlsPane = CreateEditControls();
-
-        ShowDialog(editControlsPane, name);
-    }
-
-    private void ShowDialog(JPanel editControlsPane, String name) {
+        JPanel editControlsPane = createEditControls();
+
+        showDialog(editControlsPane, name);
+    }
+
+    /**
+     * Show the dialog
+     * @param editControlsPane The controls to show
+     * @param name The name of the dialog
+     */
+    private void showDialog(JPanel editControlsPane, String name) {
         dialog = new EscapeDialog(MainApplication.getMainFrame(), name, true);
 
@@ -144,17 +155,22 @@
 
         dialog.setVisible(true);
-
-        lastIncrement = incrementTextField.getText();
-        lastCity = cityTextField.getText();
-        lastState = stateTextField.getText();
-        lastPostCode = postCodeTextField.getText();
-        lastCountry = countryTextField.getText();
-        lastFullAddress = fullTextField.getText();
-        lastConvertToHousenumber = cbConvertToHouseNumbers.getState();
-
-    }
-
-    // Create edit control items and return JPanel on which they reside
-    private JPanel CreateEditControls() {
+        updateFields(this);
+    }
+
+    private static void updateFields(AddrInterpolationDialog dialog) {
+        lastIncrement = dialog.incrementTextField.getText();
+        lastCity = dialog.cityTextField.getText();
+        lastState = dialog.stateTextField.getText();
+        lastPostCode = dialog.postCodeTextField.getText();
+        lastCountry = dialog.countryTextField.getText();
+        lastFullAddress = dialog.fullTextField.getText();
+        lastConvertToHousenumber = dialog.cbConvertToHouseNumbers.getState();
+    }
+
+    /**
+     * Create edit control items and return JPanel on which they reside
+     * @return the edit controls
+     */
+    private JPanel createEditControls() {
 
         JPanel editControlsPane = new JPanel();
@@ -167,6 +183,6 @@
 
         String streetName = selectedStreet.get("name");
-        String streetRelation = FindRelation();
-        if (streetRelation.equals("")) {
+        String streetRelation = findRelation();
+        if ("".equals(streetRelation)) {
             streetRelation = " (Create new)";
         }
@@ -213,10 +229,10 @@
 
         // Preload any values already set in map
-        GetExistingMapKeys();
+        getExistingMapKeys();
 
 
         JLabel[] textLabels = {startLabel, endLabel, numberingLabel, incrementLabel, inclusionLabel};
         Component[] editFields = {startTextField, endTextField, addrInterpolationList, incrementTextField, addrInclusionList};
-        AddEditControlRows(textLabels, editFields, editControlsPane);
+        addEditControlRows(textLabels, editFields, editControlsPane);
 
         cbConvertToHouseNumbers = new Checkbox(tr("Convert way to individual house numbers."), null, lastConvertToHousenumber);
@@ -231,5 +247,5 @@
         }
 
-        JPanel optionPanel = CreateOptionalFields();
+        JPanel optionPanel = createOptionalFields();
         c.gridx = 0;
         c.gridwidth = 2; // # of columns to span
@@ -242,8 +258,6 @@
             @Override
             public void keyPressed(KeyEvent e) {
-                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
-                    if (ValidateAndSave()) {
-                        dialog.dispose();
-                    }
+                if (e.getKeyCode() == KeyEvent.VK_ENTER && validateAndSave()) {
+                    dialog.dispose();
                 }
             }
@@ -261,8 +275,6 @@
             @Override
             public void focusGained(FocusEvent fe) {
-                if (!interpolationMethodSet) {
-                    if (AutoDetectInterpolationMethod()) {
-                        interpolationMethodSet = true;  // Don't auto detect over a previous choice
-                    }
+                if (!interpolationMethodSet && autoDetectInterpolationMethod()) {
+                    interpolationMethodSet = true;  // Don't auto detect over a previous choice
                 }
             }
@@ -271,15 +283,12 @@
         // Watch when Interpolation Method combo box is changed so that
         // Numeric increment box can be enabled or disabled.
-        addrInterpolationList.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                int selectedIndex = addrInterpolationList.getSelectedIndex();
-                incrementTextField.setEnabled(selectedIndex == NumericIndex); // Enable or disable numeric field
-            }
+        addrInterpolationList.addActionListener(e -> {
+            int selectedIndex = addrInterpolationList.getSelectedIndex();
+            incrementTextField.setEnabled(selectedIndex == NUMERIC_INDEX); // Enable or disable numeric field
         });
 
         editControlsPane.add(cbConvertToHouseNumbers, c);
 
-        if (houseNumberNodes.size() > 0) {
+        if (!houseNumberNodes.isEmpty()) {
             JLabel houseNumberNodeNote = new JLabel(tr("Will associate {0} additional house number nodes",
                     houseNumberNodes.size()));
@@ -318,8 +327,7 @@
     // combo box gets focus.
     // Return true if a method was detected
-    private boolean AutoDetectInterpolationMethod() {
-
-        String startValueString = ReadTextField(startTextField);
-        String endValueString = ReadTextField(endTextField);
+    private boolean autoDetectInterpolationMethod() {
+        String startValueString = readTextField(startTextField);
+        String endValueString = readTextField(endTextField);
         if ((startValueString == null) || (endValueString == null)) {
             // Not all values entered yet
@@ -336,13 +344,13 @@
             if (isEven(startValue)) {
                 if (isEven(endValue)) {
-                    SelectInterpolationMethod("even");
+                    selectInterpolationMethod("even");
                 } else {
-                    SelectInterpolationMethod("all");
+                    selectInterpolationMethod("all");
                 }
             } else {
                 if (!isEven(endValue)) {
-                    SelectInterpolationMethod("odd");
+                    selectInterpolationMethod("odd");
                 } else {
-                    SelectInterpolationMethod("all");
+                    selectInterpolationMethod("all");
                 }
             }
@@ -352,15 +360,15 @@
             char endingChar = endValueString.charAt(endValueString.length()-1);
 
-            if (!IsNumeric("" + startingChar) && !IsNumeric("" + endingChar)) {
+            if (!isNumeric("" + startingChar) && !isNumeric("" + endingChar)) {
                 // Both end with alpha
-                SelectInterpolationMethod("alphabetic");
+                selectInterpolationMethod("alphabetic");
                 return true;
             }
 
-            if (IsNumeric("" + startingChar) && !IsNumeric("" + endingChar)) {
+            if (isNumeric("" + startingChar) && !isNumeric("" + endingChar)) {
                 endingChar = Character.toUpperCase(endingChar);
                 if ((endingChar >= 'A') && (endingChar <= 'Z')) {
                     // First is a number, last is Latin alpha
-                    SelectInterpolationMethod("alphabetic");
+                    selectInterpolationMethod("alphabetic");
                     return true;
                 }
@@ -373,6 +381,9 @@
     }
 
-    // Set Interpolation Method combo box to method specified by 'currentMethod' (an OSM key value)
-    private void SelectInterpolationMethod(String currentMethod) {
+    /**
+     * Set Interpolation Method combo box to method specified by 'currentMethod' (an OSM key value)
+     * @param currentMethod The current interpolation method (number or key values)
+     */
+    private void selectInterpolationMethod(String currentMethod) {
         int currentIndex = 0;
         if (isLong(currentMethod)) {
@@ -394,6 +405,9 @@
     }
 
-    // Set Inclusion Method combo box to method specified by 'currentMethod' (an OSM key value)
-    private void SelectInclusion(String currentMethod) {
+    /**
+     * Set Inclusion Method combo box to method specified by 'currentMethod' (an OSM key value)
+     * @param currentMethod The key to use
+     */
+    private void selectInclusion(String currentMethod) {
         int currentIndex = 0;
         // Must scan OSM key values because combo box is already loaded with translated strings
@@ -407,6 +421,9 @@
     }
 
-    // Create optional control fields in a group box
-    private JPanel CreateOptionalFields() {
+    /**
+     * Create optional control fields in a group box
+     * @return a panel with optional fields
+     */
+    private JPanel createOptionalFields() {
 
         JPanel editControlsPane = new JPanel();
@@ -450,5 +467,5 @@
 
         Component[] optionalEditFields = {cityTextField, stateTextField, postCodeTextField, countryTextField, fullTextField};
-        AddEditControlRows(optionalTextLabels, optionalEditFields, editControlsPane);
+        addEditControlRows(optionalTextLabels, optionalEditFields, editControlsPane);
 
         JPanel optionPanel = new JPanel(new BorderLayout());
@@ -463,11 +480,13 @@
     }
 
-    // Populate dialog for any possible existing settings if editing an existing Address interpolation way
-    private void GetExistingMapKeys() {
+    /**
+     * Populate dialog for any possible existing settings if editing an existing Address interpolation way
+     */
+    private void getExistingMapKeys() {
 
         // Check all nodes for optional addressing data
         //    Address interpolation nodes will overwrite these value if they contain optional data
         for (Node node : houseNumberNodes) {
-            CheckNodeForAddressTags(node);
+            checkNodeForAddressTags(node);
         }
 
@@ -476,5 +495,5 @@
             if (currentMethod != null) {
 
-                SelectInterpolationMethod(currentMethod);
+                selectInterpolationMethod(currentMethod);
                 interpolationMethodSet = true;  // Don't auto detect over a previous choice
             }
@@ -482,5 +501,5 @@
             String currentInclusion = addrInterpolationWay.get("addr:inclusion");
             if (currentInclusion != null) {
-                SelectInclusion(currentInclusion);
+                selectInclusion(currentInclusion);
             }
 
@@ -498,13 +517,15 @@
                 endTextField.setText(value);
             }
-            CheckNodeForAddressTags(firstNode);
-            CheckNodeForAddressTags(lastNode);
-        }
-    }
-
-    // Check for any existing address data.   If found,
-    // overwrite any previous data
-    private void CheckNodeForAddressTags(Node checkNode) {
-
+            checkNodeForAddressTags(firstNode);
+            checkNodeForAddressTags(lastNode);
+        }
+    }
+
+    /**
+     * Check for any existing address data.
+     * If found, overwrite any previous data
+     * @param checkNode The node to look for possible existing values
+     */
+    private static void checkNodeForAddressTags(Tagged checkNode) {
         // Interrogate possible existing optional values
         String value = checkNode.get("addr:city");
@@ -530,33 +551,30 @@
     }
 
-    // Look for a possible 'associatedStreet' type of relation for selected street
-    // Returns relation description, or an empty string
-    private String FindRelation() {
-        String relationDescription = null;
-        DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
+    /**
+     * Look for a possible 'associatedStreet' type of relation for selected street
+     * @return relation description, or an empty string
+     */
+    private String findRelation() {
+        final DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
         if (currentDataSet != null) {
             for (Relation relation : currentDataSet.getRelations()) {
-
-                String relationType = relation.get("type");
-                if (relationType != null) {
-                    if (relationType.equals("associatedStreet")) {
-                        for (RelationMember relationMember : relation.getMembers()) {
-                            if (relationMember.isWay()) {
-                                Way way = (Way) relationMember.getMember();
-                                // System.out.println("Name: " + way.get("name") );
-                                if (way == selectedStreet) {
-                                    associatedStreetRelation = relation;
-                                    relationDescription = Long.toString(way.getId());
-
-                                    String streetName = "";
-                                    if (relation.getKeys().containsKey("name")) {
-                                        streetName = relation.get("name");
-                                    } else {
-                                        // Relation is unnamed - use street name
-                                        streetName = selectedStreet.get("name");
-                                    }
-                                    relationDescription += " (" + streetName + ")";
-                                    return relationDescription;
+                if ("associatedStreet".equals(relation.get("type"))) {
+                    for (RelationMember relationMember : relation.getMembers()) {
+                        if (relationMember.isWay()) {
+                            final StringBuilder relationDescription = new StringBuilder();
+                            Way way = (Way) relationMember.getMember();
+                            // System.out.println("Name: " + way.get("name") );
+                            if (way == selectedStreet) {
+                                associatedStreetRelation = relation;
+                                relationDescription.append(way.getId()).append('(');
+
+                                if (relation.getKeys().containsKey("name")) {
+                                    relationDescription.append(relation.get("name"));
+                                } else {
+                                    // Relation is unnamed - use street name
+                                    relationDescription.append(selectedStreet.get("name"));
                                 }
+                                relationDescription.append(')');
+                                return relationDescription.toString();
                             }
                         }
@@ -565,15 +583,16 @@
             }
         }
-
         return "";
     }
 
-    // We can proceed only if there is both a named way (the 'street') and
-    // one un-named way (the address interpolation way ) selected.
-    //    The plugin menu item is enabled after a single way is selected to display a more meaningful
-    //    message (a new user may not realize that they need to select both the street and
-    //    address interpolation way first).
-    // Also, selected street and working address interpolation ways are saved.
-    private boolean FindAndSaveSelections() {
+    /** We can proceed only if there is both a named way (the 'street') and
+     * one un-named way (the address interpolation way ) selected.
+     *    The plugin menu item is enabled after a single way is selected to display a more meaningful
+     *    message (a new user may not realize that they need to select both the street and
+     *    address interpolation way first).
+     * Also, selected street and working address interpolation ways are saved.
+     * @return {@code true} if
+     */
+    private boolean findAndSaveSelections() {
 
         boolean isValid = false;
@@ -583,6 +602,5 @@
         DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
         if (currentDataSet != null) {
-            for (OsmPrimitive osm : currentDataSet.getSelectedWays()) {
-                Way way = (Way) osm;
+            for (Way way : currentDataSet.getSelectedWays()) {
                 if (way.getKeys().containsKey("name")) {
                     namedWayCount++;
@@ -599,6 +617,5 @@
             houseNumberNodes = new ArrayList<>();
             // Check selected nodes
-            for (OsmPrimitive osm : currentDataSet.getSelectedNodes()) {
-                Node node = (Node) osm;
+            for (Node node : currentDataSet.getSelectedNodes()) {
                 if (node.getKeys().containsKey("addr:housenumber")) {
                     houseNumberNodes.add(node);
@@ -606,12 +623,10 @@
             }
 
-            if (addrInterpolationWay != null) {
-                // Check nodes in middle of address interpolation way
-                if (addrInterpolationWay.getNodesCount() > 2) {
-                    for (int i = 1; i < (addrInterpolationWay.getNodesCount()-2); i++) {
-                        Node testNode = addrInterpolationWay.getNode(i);
-                        if (testNode.getKeys().containsKey("addr:housenumber")) {
-                            houseNumberNodes.add(testNode);
-                        }
+            // Check nodes in middle of address interpolation way
+            if (addrInterpolationWay != null && addrInterpolationWay.getNodesCount() > 2) {
+                for (int i = 1; i < (addrInterpolationWay.getNodesCount()-2); i++) {
+                    Node testNode = addrInterpolationWay.getNode(i);
+                    if (testNode.getKeys().containsKey("addr:housenumber")) {
+                        houseNumberNodes.add(testNode);
                     }
                 }
@@ -630,5 +645,5 @@
             if (unNamedWayCount != 1) {
                 // Allow for street + house number nodes only to be selected (no address interpolation way).
-                if (houseNumberNodes.size() > 0) {
+                if (!houseNumberNodes.isEmpty()) {
                     isValid = true;
                 } else {
@@ -655,7 +670,7 @@
      * @param container container
      */
-    private void AddEditControlRows(JLabel[] labels,
-            Component[] editFields,
-            Container container) {
+    private static void addEditControlRows(JLabel[] labels,
+                                    Component[] editFields,
+                                    Container container) {
         GridBagConstraints c = new GridBagConstraints();
         c.anchor = GridBagConstraints.EAST;
@@ -680,5 +695,5 @@
     public void actionPerformed(ActionEvent e) {
         if ("ok".equals(e.getActionCommand())) {
-            if (ValidateAndSave()) {
+            if (validateAndSave()) {
                 dialog.dispose();
             }
@@ -688,11 +703,15 @@
     }
 
-    // For Alpha interpolation, return base string
-    //   For example: "22A" -> "22"
-    //   For example: "A" -> ""
-    //    Input string must not be empty
-    private String BaseAlpha(String strValue) {
+    /**
+     * For Alpha interpolation, return base string
+     * For example: "22A" -> "22"
+     * For example: "A" -> ""
+     *  Input string must not be empty
+     * @param strValue The value to get the base string of
+     * @return the base string, or an empty string
+     */
+    private static String baseAlpha(String strValue) {
         if (strValue.length() > 0) {
-            return strValue.substring(0, strValue.length()-1);
+            return strValue.substring(0, strValue.length() - 1);
         } else {
             return "";
@@ -700,7 +719,12 @@
     }
 
-    private char LastChar(String strValue) {
+    /**
+     * Get the last char of a string
+     * @param strValue The string to get the last char of
+     * @return The last char, or {@code 0}.
+     */
+    private static char lastChar(String strValue) {
         if (strValue.length() > 0) {
-            return strValue.charAt(strValue.length()-1);
+            return strValue.charAt(strValue.length() - 1);
         } else {
             return 0;
@@ -708,33 +732,50 @@
     }
 
-    // Test for valid positive long int
-    private boolean isLong(String input) {
+    /**
+     * Test for valid positive long int
+     * @param input The input string
+     * @return {@code true} if the input is a positive long
+     */
+    private static boolean isLong(String input) {
         try {
-            Long val = Long.parseLong(input);
+            long val = Long.parseLong(input);
             return (val > 0);
-        } catch (Exception e) {
+        } catch (NumberFormatException e) {
+            Logging.trace(e);
             return false;
         }
     }
 
-    private boolean isEven(Long input) {
+    /**
+     * Check if a number is even
+     * @param input The input number
+     * @return {@code true} if the number is even
+     */
+    private static boolean isEven(long input) {
         return ((input % 2) == 0);
     }
 
-    private static Pattern p = Pattern.compile("^[0-9]+$");
-    private static boolean IsNumeric(String s) {
-        return p.matcher(s).matches();
-    }
-
-    private void InterpolateAlphaSection(int startNodeIndex, int endNodeIndex, String endValueString,
-            char startingChar, char endingChar) {
-
-
-        String baseAlpha = BaseAlpha(endValueString);
+    private static final Pattern PATTERN_NUMERIC = Pattern.compile("^[0-9]+$");
+
+    /**
+     * Check if a string is numeric
+     * @param s The string to check
+     * @return {@code true} if it is a numeric string
+     */
+    private static boolean isNumeric(String s) {
+        return PATTERN_NUMERIC.matcher(s).matches();
+    }
+
+
+    private void interpolateAlphaSection(int startNodeIndex, int endNodeIndex, String endValueString,
+                                         char startingChar, char endingChar) {
+
+
+        String baseAlpha = baseAlpha(endValueString);
         int nSegments = endNodeIndex - startNodeIndex;
 
         double[] segmentLengths = new double[nSegments];
         // Total length of address interpolation way section
-        double totalLength = CalculateSegmentLengths(startNodeIndex, endNodeIndex, segmentLengths);
+        double totalLength = calculateSegmentLengths(startNodeIndex, endNodeIndex, segmentLengths);
 
 
@@ -784,7 +825,7 @@
     }
 
-    private void CreateAlphaInterpolation(String startValueString, String endValueString) {
-        char startingChar = LastChar(startValueString);
-        char endingChar = LastChar(endValueString);
+    private void createAlphaInterpolation(String startValueString, String endValueString) {
+        char startingChar = lastChar(startValueString);
+        char endingChar = lastChar(endValueString);
 
         if (isLong(startValueString)) {
@@ -798,27 +839,24 @@
             Node testNode = addrInterpolationWay.getNode(i);
             String endNodeNumber = testNode.get("addr:housenumber");
-            if (endNodeNumber != null) {
-                // This is a potential anchor node
-                if (endNodeNumber != "") {
-                    char anchorChar = LastChar(endNodeNumber);
-                    if ((anchorChar > startingChar) && (anchorChar < endingChar)) {
-                        // Lies within the expected range
-                        InterpolateAlphaSection(startIndex, i, endNodeNumber, startingChar, anchorChar);
-
-                        // For next interpolation section
-                        startingChar = anchorChar;
-                        startValueString = endNodeNumber;
-                        startIndex = i;
-                    }
-                }
-
+            // This is a potential anchor node
+            if (endNodeNumber != null && !"".equals(endNodeNumber)) {
+                char anchorChar = lastChar(endNodeNumber);
+                if ((anchorChar > startingChar) && (anchorChar < endingChar)) {
+                    // Lies within the expected range
+                    interpolateAlphaSection(startIndex, i, endNodeNumber, startingChar, anchorChar);
+
+                    // For next interpolation section
+                    startingChar = anchorChar;
+                    startValueString = endNodeNumber;
+                    startIndex = i;
+                }
             }
         }
 
         // End nodes do not actually contain housenumber value yet (command has not executed), so use user-entered value
-        InterpolateAlphaSection(startIndex, addrInterpolationWay.getNodesCount()-1, endValueString, startingChar, endingChar);
-    }
-
-    private double CalculateSegmentLengths(int startNodeIndex, int endNodeIndex, double[] segmentLengths) {
+        interpolateAlphaSection(startIndex, addrInterpolationWay.getNodesCount()-1, endValueString, startingChar, endingChar);
+    }
+
+    private double calculateSegmentLengths(int startNodeIndex, int endNodeIndex, double[] segmentLengths) {
         Node fromNode = addrInterpolationWay.getNode(startNodeIndex);
         double totalLength = 0.0;
@@ -834,7 +872,7 @@
     }
 
-    private void InterpolateNumericSection(int startNodeIndex, int endNodeIndex,
-            long startingAddr, long endingAddr,
-            long increment) {
+    private void interpolateNumericSection(int startNodeIndex, int endNodeIndex,
+                                           long startingAddr, long endingAddr,
+                                           long increment) {
 
         int nSegments = endNodeIndex - startNodeIndex;
@@ -843,5 +881,5 @@
 
         // Total length of address interpolation way section
-        double totalLength = CalculateSegmentLengths(startNodeIndex, endNodeIndex, segmentLengths);
+        double totalLength = calculateSegmentLengths(startNodeIndex, endNodeIndex, segmentLengths);
 
         int nHouses = (int) ((endingAddr - startingAddr) / increment) -1;
@@ -885,5 +923,5 @@
     }
 
-    private void CreateNumericInterpolation(String startValueString, String endValueString, long increment) {
+    private void createNumericInterpolation(String startValueString, String endValueString, long increment) {
 
         long startingAddr = Long.parseLong(startValueString);
@@ -895,56 +933,52 @@
             Node testNode = addrInterpolationWay.getNode(i);
             String strEndNodeNumber = testNode.get("addr:housenumber");
-            if (strEndNodeNumber != null) {
-                // This is a potential anchor node
-                if (isLong(strEndNodeNumber)) {
-
-                    long anchorAddrNumber = Long.parseLong(strEndNodeNumber);
-                    if ((anchorAddrNumber > startingAddr) && (anchorAddrNumber < endingAddr)) {
-                        // Lies within the expected range
-                        InterpolateNumericSection(startIndex, i, startingAddr, anchorAddrNumber, increment);
-
-                        // For next interpolation section
-                        startingAddr = anchorAddrNumber;
-                        startValueString = strEndNodeNumber;
-                        startIndex = i;
-                    }
-                }
-
+            // This is a potential anchor node
+            if (strEndNodeNumber != null && isLong(strEndNodeNumber)) {
+                long anchorAddrNumber = Long.parseLong(strEndNodeNumber);
+                if ((anchorAddrNumber > startingAddr) && (anchorAddrNumber < endingAddr)) {
+                    // Lies within the expected range
+                    interpolateNumericSection(startIndex, i, startingAddr, anchorAddrNumber, increment);
+
+                    // For next interpolation section
+                    startingAddr = anchorAddrNumber;
+                    startValueString = strEndNodeNumber;
+                    startIndex = i;
+                }
             }
         }
 
         // End nodes do not actually contain housenumber value yet (command has not executed), so use user-entered value
-        InterpolateNumericSection(startIndex, addrInterpolationWay.getNodesCount()-1, startingAddr, endingAddr, increment);
+        interpolateNumericSection(startIndex, addrInterpolationWay.getNodesCount()-1, startingAddr, endingAddr, increment);
     }
 
     // Called if user has checked "Convert to House Numbers" checkbox.
-    private void ConvertWayToHousenumbers(String selectedMethod, String startValueString, String endValueString,
-            String incrementString) {
+    private void convertWayToHousenumbers(String selectedMethod, String startValueString, String endValueString,
+                                          String incrementString) {
         // - Use nodes labeled with 'same type' as interim anchors in the middle of the way to identify unequal spacing.
         // - Ignore nodes of different type; for example '25b' is ignored in sequence 5..15
 
         // Calculate required number of house numbers to create
-        if (selectedMethod.equals("alphabetic")) {
-
-            CreateAlphaInterpolation(startValueString, endValueString);
+        if ("alphabetic".equals(selectedMethod)) {
+
+            createAlphaInterpolation(startValueString, endValueString);
 
         } else {
             long increment = 1;
-            if (selectedMethod.equals("odd") || selectedMethod.equals("even")) {
+            if ("odd".equals(selectedMethod) || "even".equals(selectedMethod)) {
                 increment = 2;
-            } else if (selectedMethod.equals("Numeric")) {
+            } else if ("Numeric".equals(selectedMethod)) {
                 increment = Long.parseLong(incrementString);
             }
-            CreateNumericInterpolation(startValueString, endValueString, increment);
-        }
-
-        RemoveAddressInterpolationWay();
-
-    }
-
-    private void RemoveAddressInterpolationWay() {
+            createNumericInterpolation(startValueString, endValueString, increment);
+        }
+
+        removeAddressInterpolationWay();
+
+    }
+
+    private void removeAddressInterpolationWay() {
 
         // Remove way - nodes of the way remain
-        commandGroup.add(new DeleteCommand(addrInterpolationWay));
+        commandGroup.add(DeleteCommand.delete(Collections.singleton(addrInterpolationWay)));
 
         // Remove untagged nodes
@@ -952,5 +986,5 @@
             Node testNode = addrInterpolationWay.getNode(i);
             if (!testNode.hasKeys()) {
-                commandGroup.add(new DeleteCommand(testNode));
+                commandGroup.add(DeleteCommand.delete(Collections.singleton(testNode)));
             }
         }
@@ -959,21 +993,21 @@
     }
 
-    private boolean ValidateAndSave() {
-
-        String startValueString = ReadTextField(startTextField);
-        String endValueString = ReadTextField(endTextField);
-        String incrementString = ReadTextField(incrementTextField);
-        String city = ReadTextField(cityTextField);
-        String state = ReadTextField(stateTextField);
-        String postCode = ReadTextField(postCodeTextField);
-        String country = ReadTextField(countryTextField);
-        String fullAddress = ReadTextField(fullTextField);
-
-        String selectedMethod = GetInterpolationMethod();
+    private boolean validateAndSave() {
+
+        String startValueString = readTextField(startTextField);
+        String endValueString = readTextField(endTextField);
+        String incrementString = readTextField(incrementTextField);
+        String city = readTextField(cityTextField);
+        String state = readTextField(stateTextField);
+        String postCode = readTextField(postCodeTextField);
+        String country = readTextField(countryTextField);
+        String fullAddress = readTextField(fullTextField);
+
+        String selectedMethod = getInterpolationMethod();
         if (addrInterpolationWay != null) {
             Long startAddr = 0L, endAddr = 0L;
-            if (!selectedMethod.equals("alphabetic")) {
+            if (!"alphabetic".equals(selectedMethod)) {
                 Long[] addrArray = {startAddr, endAddr};
-                if (!ValidAddressNumbers(startValueString, endValueString, addrArray)) {
+                if (!validAddressNumbers(startValueString, endValueString, addrArray)) {
                     return false;
                 }
@@ -983,25 +1017,28 @@
 
             String errorMessage = "";
-            if (selectedMethod.equals("odd")) {
-                if (isEven(startAddr) || isEven(endAddr)) {
-                    errorMessage = tr("Expected odd numbers for addresses");
-                }
-
-            } else if (selectedMethod.equals("even")) {
-                if (!isEven(startAddr) || !isEven(endAddr)) {
-                    errorMessage = tr("Expected even numbers for addresses");
-                }
-            } else if (selectedMethod.equals("all")) {
-
-            } else if (selectedMethod.equals("alphabetic")) {
-                errorMessage = ValidateAlphaAddress(startValueString, endValueString);
-
-            } else if (selectedMethod.equals("Numeric")) {
-
-                if (!ValidNumericIncrementString(incrementString, startAddr, endAddr)) {
-                    errorMessage = tr("Expected valid number for increment");
-                }
-            }
-            if (!errorMessage.equals("")) {
+            switch (selectedMethod) {
+                case "odd":
+                    if (isEven(startAddr) || isEven(endAddr)) {
+                        errorMessage = tr("Expected odd numbers for addresses");
+                    }
+                    break;
+                case "even":
+                    if (!isEven(startAddr) || !isEven(endAddr)) {
+                        errorMessage = tr("Expected even numbers for addresses");
+                    }
+                    break;
+                case "alphabetic":
+                    errorMessage = validateAlphaAddress(startValueString, endValueString);
+                    break;
+                case "Numeric":
+                    if (!validNumericIncrementString(incrementString, startAddr, endAddr)) {
+                        errorMessage = tr("Expected valid number for increment");
+                    }
+                    break;
+                case "all":
+                default:
+                    // Fall through
+            }
+            if (!"".equals(errorMessage)) {
                 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), errorMessage, tr("Error"), JOptionPane.ERROR_MESSAGE);
                 return false;
@@ -1009,10 +1046,8 @@
         }
 
-        if (country != null) {
-            if (country.length() != 2) {
-                JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
-                        tr("Country code must be 2 letters"), tr("Error"), JOptionPane.ERROR_MESSAGE);
-                return false;
-            }
+        if (country != null && country.length() != 2) {
+            JOptionPane.showMessageDialog(MainApplication.getMainFrame(),
+                    tr("Country code must be 2 letters"), tr("Error"), JOptionPane.ERROR_MESSAGE);
+            return false;
         }
 
@@ -1034,5 +1069,5 @@
 
             String interpolationTagValue = selectedMethod;
-            if (selectedMethod.equals("Numeric")) {
+            if ("Numeric".equals(selectedMethod)) {
                 // The interpolation method is the number for 'Numeric' case
                 interpolationTagValue = incrementString;
@@ -1042,9 +1077,9 @@
                 // Convert way to house numbers is checked.
                 //  Create individual nodes and delete interpolation way
-                ConvertWayToHousenumbers(selectedMethod, startValueString, endValueString, incrementString);
+                convertWayToHousenumbers(selectedMethod, startValueString, endValueString, incrementString);
             } else {
                 // Address interpolation way will remain
                 commandGroup.add(new ChangePropertyCommand(addrInterpolationWay, "addr:interpolation", interpolationTagValue));
-                commandGroup.add(new ChangePropertyCommand(addrInterpolationWay, "addr:inclusion", GetInclusionMethod()));
+                commandGroup.add(new ChangePropertyCommand(addrInterpolationWay, "addr:inclusion", getInclusionMethod()));
             }
 
@@ -1061,5 +1096,5 @@
             // Relation button was selected
             if (associatedStreetRelation == null) {
-                CreateRelation(currentDataSet, streetName);
+                createRelation(currentDataSet, streetName);
                 // relationChanged = true;   (not changed since it was created)
             }
@@ -1068,5 +1103,5 @@
 
             if (addrInterpolationWay != null) {
-                AddToRelation(associatedStreetRelation, addrInterpolationWay, "house");
+                addToRelation(associatedStreetRelation, addrInterpolationWay, "house");
             }
         }
@@ -1077,5 +1112,5 @@
 
             if (streetRelationButton.isSelected()) {
-                AddToRelation(associatedStreetRelation, node, "house");
+                addToRelation(associatedStreetRelation, node, "house");
             }
             Map<String, String> tags = new HashMap<>();
@@ -1105,5 +1140,5 @@
     }
 
-    private boolean ValidNumericIncrementString(String incrementString, long startingAddr, long endingAddr) {
+    private static boolean validNumericIncrementString(String incrementString, long startingAddr, long endingAddr) {
 
         if (!isLong(incrementString)) {
@@ -1115,12 +1150,9 @@
         }
 
-        if (((endingAddr - startingAddr) % testIncrement) != 0) {
-            return false;
-        }
-        return true;
+        return ((endingAddr - startingAddr) % testIncrement) == 0;
     }
 
     // Create Associated Street relation, add street, and add to list of commands to perform
-    private void CreateRelation(DataSet currentDataSet, String streetName) {
+    private void createRelation(DataSet currentDataSet, String streetName) {
         associatedStreetRelation = new Relation();
         associatedStreetRelation.put("name", streetName);
@@ -1133,9 +1165,9 @@
     // Read from dialog text box, removing leading and trailing spaces
     // Return the string, or null for a zero length string
-    private String ReadTextField(JTextField field) {
+    private static String readTextField(JTextField field) {
         String value = field.getText();
         if (value != null) {
             value = value.trim();
-            if (value.equals("")) {
+            if ("".equals(value)) {
                 value = null;
             }
@@ -1146,5 +1178,5 @@
     // Test if relation contains specified member
     //   If not already present, it is added
-    private void AddToRelation(Relation relation, OsmPrimitive testMember, String role) {
+    private void addToRelation(Relation relation, OsmPrimitive testMember, String role) {
         boolean isFound = false;
         for (RelationMember relationMember : relation.getMembers()) {
@@ -1168,17 +1200,17 @@
     //   Last character of ending must be greater than starting
     //   Return empty error message if OK
-    private String ValidateAlphaAddress(String startValueString,
-            String endValueString) {
+    private static String validateAlphaAddress(String startValueString,
+                                        String endValueString) {
         String errorMessage = "";
 
-        if (startValueString.equals("") || endValueString.equals("")) {
+        if ("".equals(startValueString) || "".equals(endValueString)) {
             errorMessage = tr("Please enter valid number for starting and ending address");
         } else {
-            char startingChar = LastChar(startValueString);
-            char endingChar = LastChar(endValueString);
+            char startingChar = lastChar(startValueString);
+            char endingChar = lastChar(endValueString);
 
 
             boolean isOk = false;
-            if (IsNumeric("" + startingChar) && !IsNumeric("" + endingChar)) {
+            if (isNumeric("" + startingChar) && !isNumeric("" + endingChar)) {
                 endingChar = Character.toUpperCase(endingChar);
                 if ((endingChar >= 'A') && (endingChar <= 'Z')) {
@@ -1186,5 +1218,5 @@
                     isOk = true;
                 }
-            } else if (!IsNumeric("" + startingChar) && !IsNumeric("" + endingChar)) {
+            } else if (!isNumeric("" + startingChar) && !isNumeric("" + endingChar)) {
                 // Both are alpha
                 isOk = true;
@@ -1198,10 +1230,10 @@
 
                 // Get number portion of first item: may or may not have letter suffix
-                String numStart = BaseAlpha(startValueString);
-                if (IsNumeric(startValueString)) {
+                String numStart = baseAlpha(startValueString);
+                if (isNumeric(startValueString)) {
                     numStart = startValueString;
                 }
 
-                String numEnd = BaseAlpha(endValueString);
+                String numEnd = baseAlpha(endValueString);
                 if (!numStart.equals(numEnd)) {
                     errorMessage = tr("Starting and ending numbers must be the same for alphabetic addresses");
@@ -1219,6 +1251,6 @@
 
     // Convert string addresses to numeric, with error check
-    private boolean ValidAddressNumbers(String startValueString,
-            String endValueString, Long[] addrArray) {
+    private static boolean validAddressNumbers(String startValueString,
+                                        String endValueString, Long[] addrArray) {
         String errorMessage = "";
 
@@ -1229,5 +1261,5 @@
             errorMessage = tr("Please enter valid number for ending address");
         }
-        if (errorMessage.equals("")) {
+        if ("".equals(errorMessage)) {
             addrArray[0] = Long.parseLong(startValueString);
             addrArray[1] = Long.parseLong(endValueString);
@@ -1238,5 +1270,5 @@
         }
 
-        if (errorMessage.equals("")) {
+        if ("".equals(errorMessage)) {
             return true;
 
@@ -1247,10 +1279,10 @@
     }
 
-    private String GetInterpolationMethod() {
+    private String getInterpolationMethod() {
         int selectedIndex = addrInterpolationList.getSelectedIndex();
         return addrInterpolationTags[selectedIndex];
     }
 
-    private String GetInclusionMethod() {
+    private String getInclusionMethod() {
         int selectedIndex = addrInclusionList.getSelectedIndex();
         lastAccuracyIndex = selectedIndex;
Index: /applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java
===================================================================
--- /applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java	(revision 36131)
+++ /applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java	(revision 36132)
@@ -49,5 +49,5 @@
     private double width;
     private double heading;
-    private AngleSnap angleSnap = new AngleSnap();
+    private final AngleSnap angleSnap = new AngleSnap();
     private Double drawingAngle;
     private static final double EQUAL_NODE_DIST_TOLERANCE = 1e-6;
@@ -471,5 +471,5 @@
 
     private static void addAddress(Way w, Collection<Command> cmdList) {
-        if (ToolSettings.PROP_USE_ADDR_NODE.get()) {
+        if (Boolean.TRUE.equals(ToolSettings.PROP_USE_ADDR_NODE.get())) {
             Node addrNode = getAddressNode(w);
             if (addrNode != null) {
@@ -487,5 +487,5 @@
                     addressCmds.add(new ChangeMembersCommand(r, members));
                 }
-                addressCmds.add(new DeleteCommand(addrNode));
+                addressCmds.add(DeleteCommand.delete(Collections.singleton(addrNode)));
                 if (cmdList == null) {
                     Command c = new SequenceCommand(tr("Add address for building"), addressCmds);
Index: /applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java
===================================================================
--- /applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java	(revision 36131)
+++ /applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java	(revision 36132)
@@ -34,4 +34,5 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.Pair;
 import org.openstreetmap.josm.tools.Shortcut;
@@ -80,8 +81,5 @@
                 Way way = (Way) osm;
                 ways.add(way);
-                List<Relation> rels = new ArrayList<>();
-                for (Relation r : Utils.filteredCollection(way.getReferrers(), Relation.class)) {
-                    rels.add(r);
-                }
+                List<Relation> rels = new ArrayList<>(Utils.filteredCollection(way.getReferrers(), Relation.class));
                 relations.put(way, rels);
             }
@@ -208,4 +206,5 @@
                     combineResult = combineWaysWorker(combine);
                 } catch (UserCancelException ex) {
+                    Logging.trace(ex);
                     return;
                 }
@@ -215,6 +214,6 @@
         }
 
-        for (Relation old : newRelations.keySet()) {
-            cmds.add(new ChangeCommand(old, newRelations.get(old)));
+        for (Map.Entry<Relation, Relation> entry : newRelations.entrySet()) {
+            cmds.add(new ChangeCommand(entry.getKey(), entry.getValue()));
         }
 
@@ -226,5 +225,5 @@
         }
         if (!del.isEmpty()) {
-            cmds.add(new DeleteCommand(del));
+            cmds.add(DeleteCommand.delete(del));
         }
 
@@ -258,5 +257,5 @@
     }
 
-    private boolean addNodes(NodePos start, NodePos end, Way way,
+    private static boolean addNodes(NodePos start, NodePos end, Way way,
             Set<Node> nodes, boolean hasFirst) {
         if (way.isClosed() || (start.node != way.getNode(0) && start.node != way.getNode(way.getNodesCount() - 1))) {
@@ -274,5 +273,5 @@
     }
 
-    private boolean follows(Way way1, Way way2, NodePos np1, NodePos np2,
+    private static boolean follows(Way way1, Way way2, NodePos np1, NodePos np2,
             int incr) {
         if (way2.isClosed() && incr == 1 && np1.opositPos == way2.getNodesCount() - 2) {
@@ -290,8 +289,8 @@
 
     /**
-     * @param ways
+     * @param ways The ways to be combined
      * @return null if ways cannot be combined. Otherwise returns the combined
      *         ways and the commands to combine
-     * @throws UserCancelException
+     * @throws UserCancelException If the user cancelled the operation
      */
     private Pair<Way, List<Command>> combineWaysWorker(Collection<Way> ways) throws UserCancelException {
@@ -434,13 +433,13 @@
      */
     private boolean duplicateParentRelations(Collection<Way> ways) {
-        Set<Relation> relations = new HashSet<>();
+        Set<Relation> duplicateRelations = new HashSet<>();
         for (Way w : ways) {
             List<Relation> rs = getParentRelations(w);
             for (Relation r : rs) {
-                if (relations.contains(r)) {
+                if (duplicateRelations.contains(r)) {
                     return true;
                 }
             }
-            relations.addAll(rs);
+            duplicateRelations.addAll(rs);
         }
         return false;
@@ -455,9 +454,5 @@
         List<Relation> rels = new ArrayList<>();
         for (Relation r : relations.get(way)) {
-            if (newRelations.containsKey(r)) {
-                rels.add(newRelations.get(r));
-            } else {
-                rels.add(r);
-            }
+            rels.add(newRelations.getOrDefault(r, r));
         }
         return rels;
@@ -479,9 +474,5 @@
 
     public static Way getOld(Way w, Map<Way, Way> oldWays) {
-        if (oldWays.containsKey(w)) {
-            return oldWays.get(w);
-        } else {
-            return w;
-        }
+        return oldWays.getOrDefault(w, w);
     }
 
Index: /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
===================================================================
--- /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java	(revision 36131)
+++ /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java	(revision 36132)
@@ -174,5 +174,5 @@
                                 candidateWay = tmp;
                             }
-                            commands.add(new DeleteCommand(w));
+                            commands.add(DeleteCommand.delete(Collections.singleton(w)));
                         }
                     }
@@ -204,5 +204,5 @@
     }
 
-    private boolean isSuitableRelation(Relation newRelation) {
+    private static boolean isSuitableRelation(Relation newRelation) {
         return newRelation != null && "multipolygon".equals(newRelation.get("type")) && newRelation.getMembersCount() != 0;
     }
Index: /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java
===================================================================
--- /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java	(revision 36131)
+++ /applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java	(revision 36132)
@@ -6,4 +6,5 @@
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -39,5 +40,5 @@
     private final Way source;
     private final List<RingSegment> segments;
-    private Relation relation = null;
+    private Relation relation;
 
     public TheRing(Way source) {
@@ -212,5 +213,5 @@
     }
 
-    private boolean areSegmentsEqual(RingSegment seg1, RingSegment seg2) {
+    private static boolean areSegmentsEqual(RingSegment seg1, RingSegment seg2) {
         List<Node> nodes1 = seg1.getNodes();
         List<Node> nodes2 = seg2.getNodes();
@@ -262,5 +263,5 @@
      * Tries to arrange segments in order for each ring to have at least one.
      * Also, sets source way for all rings.
-     *
+     * <p>
      * If this method is not called, do not forget to call {@link #putSourceWayFirst()} for all rings.
      */
@@ -338,5 +339,5 @@
                     continue;
                 }
-                if (key.equals("natural") && sourceCopy.get("natural").equals("coastline")) {
+                if ("natural".equals(key) && "coastline".equals(sourceCopy.get("natural"))) {
                     continue;
                 }
@@ -387,6 +388,7 @@
                 foundOwnWay = true;
             } else {
-                for (Relation rel : referencingRelations.keySet()) {
-                    int relIndex = referencingRelations.get(rel);
+                for (Map.Entry<Relation, Integer> entry : referencingRelations.entrySet()) {
+                    Relation rel = entry.getKey();
+                    int relIndex = entry.getValue();
                     rel.addMember(new RelationMember(rel.getMember(relIndex).getRole(), w));
                 }
@@ -397,5 +399,5 @@
         }
         if (!foundOwnWay) {
-            commands.add(new DeleteCommand(source));
+            commands.add(DeleteCommand.delete(Collections.singleton(source)));
         }
         commands.addAll(relationCommands);
@@ -407,6 +409,6 @@
 
     public static void updateCommandsWithRelations(List<Command> commands, Map<Relation, Relation> relationCache) {
-        for (Relation src : relationCache.keySet()) {
-            commands.add(new ChangeCommand(src, relationCache.get(src)));
+        for (Map.Entry<Relation, Relation> entry : relationCache.entrySet()) {
+            commands.add(new ChangeCommand(entry.getKey(), entry.getValue()));
         }
     }
@@ -441,6 +443,6 @@
         private List<Node> nodes;
         private RingSegment references;
-        private Way resultingWay = null;
-        private boolean wasTemplateApplied = false;
+        private Way resultingWay;
+        private boolean wasTemplateApplied;
         private boolean isRing;
 
