Index: trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 2575)
+++ trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 2578)
@@ -29,8 +29,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.CombineWayAction;
-import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.actions.ReverseWayAction;
-import org.openstreetmap.josm.actions.SplitWayAction;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.ChangeCommand;
@@ -75,16 +71,21 @@
             if(this.pos == o.pos)
                 return (this.dis - o.dis) > 0 ? 1 : -1;
-            return this.pos - o.pos;
-        }
-    };
+                return this.pos - o.pos;
+        }
+    }
 
     // HelperClass
     // Saves a relation and a role an OsmPrimitve was part of until it was stripped from all relations
     private class RelationRole {
-        public Relation rel;
-        public String role;
+        public final Relation rel;
+        public final String role;
         public RelationRole(Relation rel, String role) {
             this.rel = rel;
             this.role = role;
+        }
+
+        @Override
+        public int hashCode() {
+            return rel.hashCode();
         }
 
@@ -100,5 +101,5 @@
     public JoinAreasAction() {
         super(tr("Join overlapping Areas"), "joinareas", tr("Joins areas that overlap each other"), Shortcut.registerShortcut("tools:joinareas", tr("Tool: {0}", tr("Join overlapping Areas")),
-        KeyEvent.VK_J, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
+                KeyEvent.VK_J, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
     }
 
@@ -116,6 +117,7 @@
         OsmDataLayer dataLayer = Main.map.mapView.getEditLayer();
         for (DataSource ds : dataLayer.data.dataSources) {
-            if (ds.bounds != null)
+            if (ds.bounds != null) {
                 bounds.add(ds.bounds);
+            }
         }
 
@@ -137,5 +139,7 @@
             // This is copied from SimplifyAction and should be probably ported to tools
             for (Node node : way.getNodes()) {
-                if(askedAlready) break;
+                if(askedAlready) {
+                    break;
+                }
                 boolean isInsideOneBoundingBox = false;
                 for (Bounds b : bounds) {
@@ -151,6 +155,6 @@
                                     + "This can lead to nodes being deleted accidentally.\n"
                                     + "Are you really sure to continue?"),
-                            tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
-                            JOptionPane.WARNING_MESSAGE);
+                                    tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION,
+                                    JOptionPane.WARNING_MESSAGE);
 
                     if (option != JOptionPane.YES_OPTION) return;
@@ -173,6 +177,7 @@
             DataSet ds = Main.main.getCurrentDataSet();
             ds.fireSelectionChanged();
-        } else
+        } else {
             JOptionPane.showMessageDialog(Main.parent, tr("No intersection found. Nothing was changed."));
+        }
     }
 
@@ -199,5 +204,7 @@
         // Remove ways from all relations so ways can be combined/split quietly
         ArrayList<RelationRole> relations = removeFromRelations(a);
-        if(!same) relations.addAll(removeFromRelations(b));
+        if(!same) {
+            relations.addAll(removeFromRelations(b));
+        }
 
         // Don't warn now, because it will really look corrupted
@@ -217,6 +224,7 @@
 
         // Delete the remaining inner ways
-        if(innerWays != null && innerWays.size() > 0)
+        if(innerWays != null && innerWays.size() > 0) {
             cmds.add(DeleteCommand.delete(Main.map.mapView.getEditLayer(), innerWays, true));
+        }
         commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
 
@@ -228,11 +236,12 @@
         stripTags(newInnerWays);
         makeCommitsOneAction(
-            same
+                same
                 ? marktr("Joined self-overlapping area")
-                : marktr("Joined overlapping areas")
+                        : marktr("Joined overlapping areas")
         );
 
-        if(warnAboutRelations)
+        if(warnAboutRelations) {
             JOptionPane.showMessageDialog(Main.parent, tr("Some of the ways were part of relations that have been modified. Please verify no errors have been introduced."));
+        }
 
         return true;
@@ -254,6 +263,7 @@
         for (Way w : ways) {
             for (Entry<String,String> e : w.entrySet()) {
-                if (!props.containsKey(e.getKey()))
+                if (!props.containsKey(e.getKey())) {
                     props.put(e.getKey(), new TreeSet<String>());
+                }
                 props.get(e.getKey()).add(e.getValue());
             }
@@ -338,8 +348,8 @@
                     continue;
                 } else
-                if(a.getNode(i).equals(b.getNode(j+1)) || a.getNode(i+1).equals(b.getNode(j+1))) {
-                    nodes.add(b.getNode(j+1));
-                    continue;
-                }
+                    if(a.getNode(i).equals(b.getNode(j+1)) || a.getNode(i+1).equals(b.getNode(j+1))) {
+                        nodes.add(b.getNode(j+1));
+                        continue;
+                    }
                 LatLon intersection = getLineLineIntersection(
                         a.getNode(i)  .getEastNorth().east(), a.getNode(i)  .getEastNorth().north(),
@@ -347,5 +357,7 @@
                         b.getNode(j)  .getEastNorth().east(), b.getNode(j)  .getEastNorth().north(),
                         b.getNode(j+1).getEastNorth().east(), b.getNode(j+1).getEastNorth().north());
-                if(intersection == null) continue;
+                if(intersection == null) {
+                    continue;
+                }
 
                 // Create the node. Adding them to the ways must be delayed because we still loop over them
@@ -355,13 +367,16 @@
                 // The distance is needed to sort and add the nodes in direction of the way
                 nodesA.add(new NodeToSegs(i,  n, a.getNode(i).getCoor()));
-                if(same)
+                if(same) {
                     nodesA.add(new NodeToSegs(j,  n, a.getNode(j).getCoor()));
-                else
+                } else {
                     nodesB.add(new NodeToSegs(j,  n, b.getNode(j).getCoor()));
+                }
             }
         }
 
         addNodesToWay(a, nodesA);
-        if(!same) addNodesToWay(b, nodesB);
+        if(!same) {
+            addNodesToWay(b, nodesB);
+        }
 
         return nodes;
@@ -373,6 +388,6 @@
      */
     static private LatLon getLineLineIntersection(
-                double x1, double y1, double x2, double y2,
-                double x3, double y3, double x4, double y4) {
+            double x1, double y1, double x2, double y2,
+            double x3, double y3, double x4, double y4) {
 
         if (!Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return null;
@@ -392,6 +407,6 @@
 
         return Main.proj.eastNorth2latlon(new EastNorth(
-            (b1*c2 - b2*c1)/det,
-            (a2*c1 -a1*c2)/det
+                (b1*c2 - b2*c1)/det,
+                (a2*c1 -a1*c2)/det
         ));
     }
@@ -421,13 +436,13 @@
     private void commitCommands(String description) {
         switch(cmds.size()) {
-            case 0:
-                return;
-            case 1:
-                Main.main.undoRedo.add(cmds.getFirst());
-                break;
-            default:
-                Command c = new SequenceCommand(tr(description), cmds);
-                Main.main.undoRedo.add(c);
-                break;
+        case 0:
+            return;
+        case 1:
+            Main.main.undoRedo.add(cmds.getFirst());
+            break;
+        default:
+            Command c = new SequenceCommand(tr(description), cmds);
+            Main.main.undoRedo.add(c);
+            break;
         }
 
@@ -444,7 +459,11 @@
         ArrayList<RelationRole> result = new ArrayList<RelationRole>();
         for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
-            if (r.isDeleted() || r.incomplete) continue;
+            if (r.isDeleted() || r.isIncomplete()) {
+                continue;
+            }
             for (RelationMember rm : r.getMembers()) {
-                if (rm.getMember() != osm) continue;
+                if (rm.getMember() != osm) {
+                    continue;
+                }
 
                 Relation newRel = new Relation(r);
@@ -455,5 +474,7 @@
                 cmds.add(new ChangeCommand(r, newRel));
                 RelationRole saverel =  new RelationRole(r, rm.getRole());
-                if(!result.contains(saverel)) result.add(saverel);
+                if(!result.contains(saverel)) {
+                    result.add(saverel);
+                }
                 break;
             }
@@ -471,5 +492,7 @@
         ArrayList<Way> ways = new ArrayList<Way>();
         ways.add(a);
-        if(!a.equals(b)) ways.add(b);
+        if(!a.equals(b)) {
+            ways.add(b);
+        }
 
         List<OsmPrimitive> affected = new ArrayList<OsmPrimitive>();
@@ -493,5 +516,7 @@
         Collection<Way> result = new ArrayList<Way>();
         for(OsmPrimitive w: ways) {
-            if(w instanceof Way) result.add((Way) w);
+            if(w instanceof Way) {
+                result.add((Way) w);
+            }
         }
         return result;
@@ -505,5 +530,7 @@
     private Collection<Node> getNodesFromWays(Collection<Way> ways) {
         Collection<Node> allNodes = new ArrayList<Node>();
-        for(Way w: ways) allNodes.addAll(w.getNodes());
+        for(Way w: ways) {
+            allNodes.addAll(w.getNodes());
+        }
         return allNodes;
     }
@@ -521,5 +548,7 @@
         for(Way w: multigonWays) {
             Polygon poly = new Polygon();
-            for(Node n: (w).getNodes()) poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()));
+            for(Node n: (w).getNodes()) {
+                poly.addPoint(latlonToXY(n.getCoor().lat()), latlonToXY(n.getCoor().lon()));
+            }
 
             for(Node n: multigonNodes) {
@@ -546,6 +575,10 @@
     private void getWaysByNode(Collection<Way> innerWays, Collection<Way> w, Node n) {
         for(Way way : w) {
-            if(!(way).containsNode(n)) continue;
-            if(!innerWays.contains(way)) innerWays.add(way); // Will need this later for multigons
+            if(!(way).containsNode(n)) {
+                continue;
+            }
+            if(!innerWays.contains(way)) {
+                innerWays.add(way); // Will need this later for multigons
+            }
         }
     }
@@ -561,10 +594,13 @@
         for(Way w: multigonWays) {
             // Skip inner ways
-            if(innerWays.contains(w)) continue;
-
-            if(w.getNodesCount() <= 2)
+            if(innerWays.contains(w)) {
+                continue;
+            }
+
+            if(w.getNodesCount() <= 2) {
                 cmds.add(new DeleteCommand(w));
-            else
+            } else {
                 join.add(w);
+            }
         }
 
@@ -606,5 +642,5 @@
             }
             if(a.getNode(0).equals(b.getNode(0)) ||
-               a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
+                    a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
                 Main.main.getCurrentDataSet().setSelected(b);
                 new ReverseWayAction().actionPerformed(null);
@@ -644,8 +680,14 @@
             boolean hasInnerNodes = false;
             for(Node n : w.getNodes()) {
-                if(outerNodes.contains(n)) continue wayIterator;
-                if(!hasInnerNodes && innerNodes.contains(n)) hasInnerNodes = true;
-            }
-            if(!hasInnerNodes || w.getNodesCount() < 2) continue;
+                if(outerNodes.contains(n)) {
+                    continue wayIterator;
+                }
+                if(!hasInnerNodes && innerNodes.contains(n)) {
+                    hasInnerNodes = true;
+                }
+            }
+            if(!hasInnerNodes || w.getNodesCount() < 2) {
+                continue;
+            }
             possibleWays.add(w);
         }
@@ -671,5 +713,7 @@
                 for(Way w2 : possibleWays) {
                     // w2 cannot be closed, otherwise it would have been removed above
-                    if(!waysCanBeCombined(w1, w2)) continue;
+                    if(!waysCanBeCombined(w1, w2)) {
+                        continue;
+                    }
 
                     ArrayList<Way> joinThem = new ArrayList<Way>();
@@ -719,17 +763,23 @@
         List<Way> removables = new ArrayList<Way>();
         for(Way a : ways) {
-            if(a.isClosed()) continue;
+            if(a.isClosed()) {
+                continue;
+            }
             boolean connectedStart = false;
             boolean connectedEnd = false;
             for(Way b : ways) {
-                if(a.equals(b))
+                if(a.equals(b)) {
                     continue;
-                if(b.isFirstLastNode(a.firstNode()))
+                }
+                if(b.isFirstLastNode(a.firstNode())) {
                     connectedStart = true;
-                if(b.isFirstLastNode(a.lastNode()))
+                }
+                if(b.isFirstLastNode(a.lastNode())) {
                     connectedEnd = true;
-            }
-            if(!connectedStart || !connectedEnd)
+                }
+            }
+            if(!connectedStart || !connectedEnd) {
                 removables.add(a);
+            }
         }
         ways.removeAll(removables);
@@ -749,5 +799,7 @@
         for(Node n : w.getNodes()) {
             x.removeNode(n);
-            if(x.containsNode(n)) count++;
+            if(x.containsNode(n)) {
+                count++;
+            }
             if(count == 2) return true;
         }
@@ -784,6 +836,7 @@
         Relation newRel = new Relation();
         newRel.put("type", "multipolygon");
-        for(Way w : inner)
+        for(Way w : inner) {
             newRel.addMember(new RelationMember("inner", w));
+        }
         cmds.add(new AddCommand(newRel));
 
@@ -806,7 +859,7 @@
         for(RelationRole r : rels) {
             if( r.rel.get("type") != null &&
-                r.rel.get("type").equalsIgnoreCase("multipolygon") &&
-                r.role.equalsIgnoreCase("outer")
-              ) {
+                    r.rel.get("type").equalsIgnoreCase("multipolygon") &&
+                    r.role.equalsIgnoreCase("outer")
+            ) {
                 multiouters.add(r);
                 continue;
@@ -820,28 +873,30 @@
         Relation newRel = null;
         switch(multiouters.size()) {
-            case 0:
-                return;
-            case 1:
-                // Found only one to be part of a multipolygon relation, so just add it back as well
-                newRel = new Relation(multiouters.get(0).rel);
-                newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
-                cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
-                return;
-            default:
-                // Create a new relation with all previous members and (Way)outer as outer.
-                newRel = new Relation();
-                for(RelationRole r : multiouters) {
-                    // Add members
-                    for(RelationMember rm : r.rel.getMembers())
-                        if(!newRel.getMembers().contains(rm)) newRel.addMember(rm);
-                    // Add tags
-                    for (String key : r.rel.keySet()) {
-                        newRel.put(key, r.rel.get(key));
+        case 0:
+            return;
+        case 1:
+            // Found only one to be part of a multipolygon relation, so just add it back as well
+            newRel = new Relation(multiouters.get(0).rel);
+            newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
+            cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
+            return;
+        default:
+            // Create a new relation with all previous members and (Way)outer as outer.
+            newRel = new Relation();
+            for(RelationRole r : multiouters) {
+                // Add members
+                for(RelationMember rm : r.rel.getMembers())
+                    if(!newRel.getMembers().contains(rm)) {
+                        newRel.addMember(rm);
                     }
-                    // Delete old relation
-                    cmds.add(new DeleteCommand(r.rel));
-                }
-                newRel.addMember(new RelationMember("outer", outer));
-                cmds.add(new AddCommand(newRel));
+                // Add tags
+                for (String key : r.rel.keySet()) {
+                    newRel.put(key, r.rel.get(key));
+                }
+                // Delete old relation
+                cmds.add(new DeleteCommand(r.rel));
+            }
+            newRel.addMember(new RelationMember("outer", outer));
+            cmds.add(new AddCommand(newRel));
         }
     }
@@ -851,5 +906,7 @@
      */
     private void stripTags(Collection<Way> ways) {
-        for(Way w: ways) stripTags(w);
+        for(Way w: ways) {
+            stripTags(w);
+        }
         commitCommands(marktr("Remove tags from inner ways"));
     }
@@ -861,6 +918,7 @@
         if(x.getKeys() == null) return;
         Way y = new Way(x);
-        for (String key : x.keySet())
+        for (String key : x.keySet()) {
             y.remove(key);
+        }
         cmds.add(new ChangeCommand(x, y));
     }
@@ -875,9 +933,11 @@
         cmds.clear();
         int i = Math.max(ur.commands.size() - cmdsCount, 0);
-        for(; i < ur.commands.size(); i++)
+        for(; i < ur.commands.size(); i++) {
             cmds.add(ur.commands.get(i));
-
-        for(i = 0; i < cmds.size(); i++)
+        }
+
+        for(i = 0; i < cmds.size(); i++) {
             ur.undo();
+        }
 
         commitCommands(message == null ? marktr("Join Areas Function") : message);
