Changeset 6776 in josm for trunk/src


Ignore:
Timestamp:
2014-01-29T22:41:40+01:00 (6 years ago)
Author:
simon04
Message:

fix #9624 - Create a sensible upload order of relations to be deleted

This fixes "Precondition failed: The relation X is used in relation Y" when X and Y are to be deleted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/APIDataSet.java

    r6317 r6776  
    232232        relationsToAdd.removeAll(noProblemRelations);
    233233
    234         RelationUploadDependencyGraph graph = new RelationUploadDependencyGraph(relationsToAdd);
     234        RelationUploadDependencyGraph graph = new RelationUploadDependencyGraph(relationsToAdd, true);
    235235        newToAdd.addAll(graph.computeUploadOrder());
    236236        toAdd = newToAdd;
     237
     238        LinkedList<OsmPrimitive> newToDelete = new LinkedList<OsmPrimitive>();
     239        newToDelete.addAll(Utils.filteredCollection(toDelete, Node.class));
     240        newToDelete.addAll(Utils.filteredCollection(toDelete, Way.class));
     241        graph = new RelationUploadDependencyGraph(Utils.filteredCollection(toDelete, Relation.class), false);
     242        newToDelete.addAll(graph.computeUploadOrder());
     243        toDelete = newToDelete;
    237244    }
    238245
     
    268275     */
    269276    private static class RelationUploadDependencyGraph {
    270         private Map<Relation, Set<Relation>> children;
     277        private Map<Relation, Set<Relation>> children = new HashMap<Relation, Set<Relation>>();
    271278        private Collection<Relation> relations;
    272         private Set<Relation> visited;
     279        private Set<Relation> visited = new HashSet<Relation>();
    273280        private List<Relation> uploadOrder;
    274 
    275         public RelationUploadDependencyGraph() {
    276             this.children = new HashMap<Relation, Set<Relation>>();
    277             this.visited = new HashSet<Relation>();
    278         }
    279 
    280         public RelationUploadDependencyGraph(Collection<Relation> relations) {
    281             this();
     281        private final boolean newOrUndeleted;
     282
     283        public RelationUploadDependencyGraph(Collection<Relation> relations, boolean newOrUndeleted) {
     284            this.newOrUndeleted = newOrUndeleted;
    282285            build(relations);
    283286        }
     
    286289            this.relations = new HashSet<Relation>();
    287290            for(Relation relation: relations) {
    288                 if (!relation.isNewOrUndeleted() ) {
     291                if (newOrUndeleted ? !relation.isNewOrUndeleted() : !relation.isDeleted()) {
    289292                    continue;
    290293                }
    291294                this.relations.add(relation);
    292295                for (RelationMember m: relation.getMembers()) {
    293                     if (m.isRelation() && m.getMember().isNewOrUndeleted()) {
     296                    if (m.isRelation() && (newOrUndeleted ? m.getMember().isNewOrUndeleted() : m.getMember().isDeleted())) {
    294297                        addDependency(relation, (Relation)m.getMember());
    295298                    }
Note: See TracChangeset for help on using the changeset viewer.