Ignore:
Timestamp:
2023-09-07T16:52:05+02:00 (22 months ago)
Author:
taylor.smock
Message:

Fix some potential DataIntegrityProblemException sources

This also fixes some lint issues.

merge-overlap: See #19627
reltoolbox: See #23074, #23077, #23123

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java

    r35583 r36132  
    3434import org.openstreetmap.josm.data.osm.Way;
    3535import org.openstreetmap.josm.gui.MainApplication;
     36import org.openstreetmap.josm.tools.Logging;
    3637import org.openstreetmap.josm.tools.Pair;
    3738import org.openstreetmap.josm.tools.Shortcut;
     
    8081                Way way = (Way) osm;
    8182                ways.add(way);
    82                 List<Relation> rels = new ArrayList<>();
    83                 for (Relation r : Utils.filteredCollection(way.getReferrers(), Relation.class)) {
    84                     rels.add(r);
    85                 }
     83                List<Relation> rels = new ArrayList<>(Utils.filteredCollection(way.getReferrers(), Relation.class));
    8684                relations.put(way, rels);
    8785            }
     
    208206                    combineResult = combineWaysWorker(combine);
    209207                } catch (UserCancelException ex) {
     208                    Logging.trace(ex);
    210209                    return;
    211210                }
     
    215214        }
    216215
    217         for (Relation old : newRelations.keySet()) {
    218             cmds.add(new ChangeCommand(old, newRelations.get(old)));
     216        for (Map.Entry<Relation, Relation> entry : newRelations.entrySet()) {
     217            cmds.add(new ChangeCommand(entry.getKey(), entry.getValue()));
    219218        }
    220219
     
    226225        }
    227226        if (!del.isEmpty()) {
    228             cmds.add(new DeleteCommand(del));
     227            cmds.add(DeleteCommand.delete(del));
    229228        }
    230229
     
    258257    }
    259258
    260     private boolean addNodes(NodePos start, NodePos end, Way way,
     259    private static boolean addNodes(NodePos start, NodePos end, Way way,
    261260            Set<Node> nodes, boolean hasFirst) {
    262261        if (way.isClosed() || (start.node != way.getNode(0) && start.node != way.getNode(way.getNodesCount() - 1))) {
     
    274273    }
    275274
    276     private boolean follows(Way way1, Way way2, NodePos np1, NodePos np2,
     275    private static boolean follows(Way way1, Way way2, NodePos np1, NodePos np2,
    277276            int incr) {
    278277        if (way2.isClosed() && incr == 1 && np1.opositPos == way2.getNodesCount() - 2) {
     
    290289
    291290    /**
    292      * @param ways
     291     * @param ways The ways to be combined
    293292     * @return null if ways cannot be combined. Otherwise returns the combined
    294293     *         ways and the commands to combine
    295      * @throws UserCancelException
     294     * @throws UserCancelException If the user cancelled the operation
    296295     */
    297296    private Pair<Way, List<Command>> combineWaysWorker(Collection<Way> ways) throws UserCancelException {
     
    434433     */
    435434    private boolean duplicateParentRelations(Collection<Way> ways) {
    436         Set<Relation> relations = new HashSet<>();
     435        Set<Relation> duplicateRelations = new HashSet<>();
    437436        for (Way w : ways) {
    438437            List<Relation> rs = getParentRelations(w);
    439438            for (Relation r : rs) {
    440                 if (relations.contains(r)) {
     439                if (duplicateRelations.contains(r)) {
    441440                    return true;
    442441                }
    443442            }
    444             relations.addAll(rs);
     443            duplicateRelations.addAll(rs);
    445444        }
    446445        return false;
     
    455454        List<Relation> rels = new ArrayList<>();
    456455        for (Relation r : relations.get(way)) {
    457             if (newRelations.containsKey(r)) {
    458                 rels.add(newRelations.get(r));
    459             } else {
    460                 rels.add(r);
    461             }
     456            rels.add(newRelations.getOrDefault(r, r));
    462457        }
    463458        return rels;
     
    479474
    480475    public static Way getOld(Way w, Map<Way, Way> oldWays) {
    481         if (oldWays.containsKey(w)) {
    482             return oldWays.get(w);
    483         } else {
    484             return w;
    485         }
     476        return oldWays.getOrDefault(w, w);
    486477    }
    487478
Note: See TracChangeset for help on using the changeset viewer.