Ignore:
Timestamp:
2010-01-23T15:12:03+01:00 (15 years ago)
Author:
jttt
Message:

Fixed #4398 validator: repair: "doppelte Knoten": please, always merge ID:0 to already existing node with ID

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java

    r19226 r19597  
    3838
    3939    /** The map of potential duplicates.
    40      * 
     40     *
    4141     * If there is exactly one node for a given pos, the map includes a pair <pos, Node>.
    42      * If there are multiple nodes for a given pos, the map includes a pair 
    43      * <pos, NodesByEqualTagsMap> 
     42     * If there are multiple nodes for a given pos, the map includes a pair
     43     * <pos, NodesByEqualTagsMap>
    4444     */
    4545    Map<LatLon,Object> potentialDuplicates;
     
    5959        potentialDuplicates = new HashMap<LatLon, Object>();
    6060    }
    61  
    62    
     61
     62
    6363        @Override
    64         public void endTest() { 
     64        public void endTest() {
    6565                for (Entry<LatLon, Object> entry: potentialDuplicates.entrySet()) {
    6666                        Object v = entry.getValue();
     
    6969                                // error
    7070                                continue;
    71                         }                       
    72                        
    73                         // multiple nodes at the same position -> report errors 
     71                        }
     72
     73                        // multiple nodes at the same position -> report errors
    7474                        //
    7575                        NodesByEqualTagsMap map = (NodesByEqualTagsMap)v;
     
    8484                if (n.isUsable()) {
    8585                        LatLon rounded = n.getCoor().getRoundedToOsmPrecision();
    86                         if (potentialDuplicates.get(rounded) == null) {         
     86                        if (potentialDuplicates.get(rounded) == null) {
    8787                                // in most cases there is just one node at a given position. We
    88                                 // avoid to create an extra object and add remember the node 
    89                                 // itself at this position 
     88                                // avoid to create an extra object and add remember the node
     89                                // itself at this position
    9090                                potentialDuplicates.put(rounded, n);
    9191                        } else if (potentialDuplicates.get(rounded) instanceof Node) {
     
    9999                                potentialDuplicates.put(rounded, map);
    100100                        } else if (potentialDuplicates.get(rounded) instanceof NodesByEqualTagsMap) {
    101                                 // we have multiple nodes at the same position. 
    102                                 // 
     101                                // we have multiple nodes at the same position.
     102                                //
    103103                                NodesByEqualTagsMap map = (NodesByEqualTagsMap)potentialDuplicates.get(rounded);
    104104                                map.add(n);
    105                         }                       
     105                        }
    106106                }
    107107        }
     
    116116        Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(testError.getPrimitives());
    117117        LinkedHashSet<Node> nodes = new LinkedHashSet<Node>(OsmPrimitive.getFilteredList(sel, Node.class));
    118         Node target = MergeNodesAction.selectTargetNode(nodes);
     118
     119        // Use first existing node or first node if all nodes are new
     120        Node target = null;
     121        for (Node n: nodes) {
     122            if (!n.isNew()) {
     123                target = n;
     124                break;
     125            }
     126        }
     127        if (target == null) {
     128            nodes.iterator().next();
     129        }
     130
    119131        if(checkAndConfirmOutlyingDeletes(nodes))
    120132            return MergeNodesAction.mergeNodes(Main.main.getEditLayer(), nodes, target);
     
    157169        return true;
    158170    }
    159    
     171
    160172    static private class NodesByEqualTagsMap {
    161173        /**
    162174         * a bag of primitives with the same position. The bag key is represented
    163175         * by the tag set of the primitive. This allows for easily find nodes at
    164          * the same position with the same tag sets later. 
     176         * the same position with the same tag sets later.
    165177         */
    166178        private Bag<Map<String,String>, OsmPrimitive> bag;
     
    169181                bag = new Bag<Map<String,String>, OsmPrimitive>();
    170182        }
    171        
     183
    172184        public void add(Node n) {
    173185                bag.add(n.getKeys(), n);
    174186        }
    175                
     187
    176188        public List<TestError> buildTestErrors(Test parentTest) {
    177189                List<TestError> errors = new ArrayList<TestError>();
    178190                // check whether we have multiple nodes at the same position with
    179                 // the same tag set 
    180                 //             
     191                // the same tag set
     192                //
    181193                for (Iterator<Map<String,String>> it = bag.keySet().iterator(); it.hasNext(); ) {
    182194                        Map<String,String> tagSet = it.next();
    183195                        if (bag.get(tagSet).size() > 1) {
    184196                                errors.add(new TestError(
    185                                                 parentTest, 
     197                                                parentTest,
    186198                                                Severity.ERROR,
    187                                                 tr("Duplicated nodes"), 
    188                                                 DUPLICATE_NODE, 
     199                                                tr("Duplicated nodes"),
     200                                                DUPLICATE_NODE,
    189201                                                bag.get(tagSet)
    190202                                ));
    191203                                it.remove();
    192204                        }
    193                        
     205
    194206                }
    195                
     207
    196208                // check whether we have multiple nodes at the same position with
    197                 // differing tag sets 
     209                // differing tag sets
    198210                //
    199211                if (!bag.isEmpty()) {
     
    204216                        if (duplicates.size() > 1) {
    205217                                errors.add(new TestError(
    206                                                 parentTest, 
     218                                                parentTest,
    207219                                                Severity.WARNING,
    208220                                                        tr("Nodes at same position"),
     
    213225                }
    214226                return errors;
    215         }       
     227        }
    216228    }
    217229}
Note: See TracChangeset for help on using the changeset viewer.