Changeset 6006 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2013-06-15T11:06:38+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8793 - NullPointerException in DistributeAction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DistributeAction.java

    r4982 r6006  
    22package org.openstreetmap.josm.actions;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    99import java.util.Collection;
     10import java.util.HashSet;
     11import java.util.Iterator;
    1012import java.util.LinkedList;
     13import java.util.Set;
    1114
    1215import javax.swing.JOptionPane;
     
    2831public final class DistributeAction extends JosmAction {
    2932
     33    /**
     34     * Constructs a new {@code DistributeAction}.
     35     */
    3036    public DistributeAction() {
    3137        super(tr("Distribute Nodes"), "distribute", tr("Distribute the selected nodes to equal distances along a line."),
     
    3440        putValue("help", ht("/Action/DistributeNodes"));
    3541    }
    36 
     42   
    3743    /**
    3844     * The general algorithm here is to find the two selected nodes
     
    5965                    itnodes.addAll(((Way)osm).getNodes());
    6066                }
     67        }
     68       
     69        Set<Node> ignoredNodes = removeNodesWithoutCoordinates(nodes);
     70        ignoredNodes.addAll(removeNodesWithoutCoordinates(itnodes));
     71        if (!ignoredNodes.isEmpty()) {
     72            Main.warn(tr("Ignoring {0} nodes with null coordinates", ignoredNodes.size()));
     73            ignoredNodes.clear();
    6174        }
    6275
     
    136149        Main.map.repaint();
    137150    }
     151   
     152    private Set<Node> removeNodesWithoutCoordinates(Collection<Node> col) {
     153        Set<Node> result = new HashSet<Node>();
     154        for (Iterator<Node> it = col.iterator(); it.hasNext();) {
     155            Node n = it.next();
     156            if (n.getCoor() == null) {
     157                it.remove();
     158                result.add(n);
     159            }
     160        }
     161        return result;
     162    }
    138163
    139164    @Override
Note: See TracChangeset for help on using the changeset viewer.