Ticket #3798: merge-order.patch

File merge-order.patch, 3.9 KB (added by bastiK, 15 years ago)
  • src/org/openstreetmap/josm/actions/MergeNodesAction.java

     
    1313import java.util.ArrayList;
    1414import java.util.Collection;
    1515import java.util.HashSet;
     16import java.util.LinkedHashSet;
    1617import java.util.LinkedList;
    1718import java.util.List;
    1819import java.util.Set;
     
    5354        if (!isEnabled())
    5455            return;
    5556        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    56         Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
     57        LinkedHashSet<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
    5758        if (selectedNodes.size() < 2) {
    5859            JOptionPane.showMessageDialog(
    5960                    Main.parent,
     
    7374    }
    7475
    7576    /**
    76      * Selects a node out of a collection of candidate nodes. The selected
    77      * node will become the target node the remaining nodes are merged to.
    78      *
     77     * Find which node to merge into (i.e. which one will be left)
     78     * The selected node will become the target node the remaining
     79     * nodes are merged to.
     80     * It will be the last node in the list.
     81     *
    7982     * @param candidates the collection of candidate nodes
    8083     * @return the selected target node
    8184     */
    82     public static Node selectTargetNode(Collection<Node> candidates) {
    83         // Find which node to merge into (i.e. which one will be left)
    84         // - this should be combined from two things:
    85         //   1. It will be the first node in the list that has a
    86         //      positive ID number, OR the first node.
    87         //   2. It will be at the position of the first node in the
    88         //      list.
    89         //
    90         // *However* - there is the problem that the selection list is
    91         // _not_ in the order that the nodes were clicked on, meaning
    92         // that the user doesn't know which node will be chosen (so
    93         // (2) is not implemented yet.)  :-(
     85    public static Node selectTargetNode(LinkedHashSet<Node> candidates) {
    9486        Node targetNode = null;
    95         for (Node n: candidates) {
    96             if (!n.isNew()) {
    97                 targetNode = n;
    98                 break;
    99             }
     87        for (Node n : candidates) { // pick last one
     88            targetNode = n;
    10089        }
    101         if (targetNode == null) {
    102             // an arbitrary node
    103             targetNode = candidates.iterator().next();
    104         }
    10590        return targetNode;
    10691    }
    10792
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

     
    1010import java.util.Date;
    1111import java.util.HashMap;
    1212import java.util.HashSet;
     13import java.util.LinkedHashSet;
    1314import java.util.LinkedList;
    1415import java.util.List;
    1516import java.util.Locale;
     
    8283     * @param type the type to filter for
    8384     * @return the sub-set of OSM primitives of type <code>type</code>
    8485     */
    85     static public <T extends OsmPrimitive>  Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) {
    86         if (set == null) return Collections.emptySet();
    87         HashSet<T> ret = new HashSet<T>();
    88         for(OsmPrimitive p: set) {
    89             if (type.isInstance(p)) {
    90                 ret.add(type.cast(p));
     86    static public <T extends OsmPrimitive>  LinkedHashSet<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) {
     87        LinkedHashSet<T> ret = new LinkedHashSet<T>();
     88        if (set != null) {
     89            for(OsmPrimitive p: set) {
     90                if (type.isInstance(p)) {
     91                    ret.add(type.cast(p));
     92                }
    9193            }
    9294        }
    9395        return ret;