Ignore:
Timestamp:
2009-12-03T20:26:00+01:00 (10 years ago)
Author:
Gubaer
Message:

Removed BackReferenceDataSet and CollectBackReferenceVisitor because we now have referrer support in OsmPrimitive.
This could cause some problems in the next few days. I'm sure I didn't test every possibly affected feature.

Location:
trunk/src/org/openstreetmap/josm/command
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r2521 r2565  
    2424import org.openstreetmap.josm.Main;
    2525import org.openstreetmap.josm.actions.SplitWayAction;
    26 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
    2726import org.openstreetmap.josm.data.osm.Node;
    2827import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2928import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3029import org.openstreetmap.josm.data.osm.Relation;
     30import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3131import org.openstreetmap.josm.data.osm.Way;
    3232import org.openstreetmap.josm.data.osm.WaySegment;
    33 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
    34 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    3533import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    3634import org.openstreetmap.josm.gui.DefaultNameFormatter;
     
    218216            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "layer"));
    219217        if (selection == null || selection.isEmpty()) return null;
    220         CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data);
    221         v.initialize();
    222         for (OsmPrimitive osm : selection) {
    223             osm.visit(v);
    224         }
    225         v.getData().addAll(selection);
    226         if (v.getData().isEmpty())
     218        Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection);
     219        parents.addAll(selection);
     220
     221        if (parents.isEmpty())
    227222            return null;
    228         if (!checkAndConfirmOutlyingDeletes(layer,v.getData()) && !silent)
     223        if (!checkAndConfirmOutlyingDeletes(layer,parents) && !silent)
    229224            return null;
    230         return new DeleteCommand(layer,v.getData());
     225        return new DeleteCommand(layer,parents);
    231226    }
    232227
     
    246241     *    <li>it is not referred to by other non-deleted primitives outside of  <code>primitivesToDelete</code></li>
    247242     * <ul>
    248      * @param backreferences backreference data structure
    249243     * @param layer  the layer in whose context primitives are deleted
    250244     * @param primitivesToDelete  the primitives to delete
     
    252246     * can be deleted too
    253247     */
    254     protected static Collection<Node> computeNodesToDelete(BackreferencedDataSet backreferences, OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
     248    protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {
    255249        Collection<Node> nodesToDelete = new HashSet<Node>();
    256250        for (Way way : OsmPrimitive.getFilteredList(primitivesToDelete, Way.class)) {
     
    259253                    continue;
    260254                }
    261                 Collection<OsmPrimitive> referringPrimitives = backreferences.getParents(n);
     255                Collection<OsmPrimitive> referringPrimitives = n.getReferrers();
    262256                referringPrimitives.removeAll(primitivesToDelete);
    263257                int count = 0;
     
    314308            return null;
    315309
    316         BackreferencedDataSet backreferences = new BackreferencedDataSet();
    317310        Set<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection);
    318311        Collection<Way> waysToBeChanged = new HashSet<Way>();
     
    321314            // delete untagged nodes only referenced by primitives in primitivesToDelete,
    322315            // too
    323             Collection<Node> nodesToDelete = computeNodesToDelete(backreferences, layer, primitivesToDelete);
     316            Collection<Node> nodesToDelete = computeNodesToDelete(layer, primitivesToDelete);
    324317            primitivesToDelete.addAll(nodesToDelete);
    325318        }
     
    328321            return null;
    329322
    330         waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(backreferences.getParents(primitivesToDelete), Way.class));
     323        waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
    331324
    332325        Collection<Command> cmds = new LinkedList<Command>();
     
    345338        //
    346339        if (!silent) {
    347             Set<RelationToChildReference> references = backreferences.getRelationToChildReferences(primitivesToDelete);
     340            Set<RelationToChildReference> references = RelationToChildReference.getRelationToChildReferences(primitivesToDelete);
    348341            Iterator<RelationToChildReference> it = references.iterator();
    349342            while(it.hasNext()) {
     
    364357        // remove the objects from their parent relations
    365358        //
    366         Iterator<Relation> iterator = OsmPrimitive.getFilteredSet(backreferences.getParents(primitivesToDelete), Relation.class).iterator();
     359        Iterator<Relation> iterator = OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Relation.class).iterator();
    367360        while (iterator.hasNext()) {
    368361            Relation cur = iterator.next();
  • trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java

    r2512 r2565  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.data.conflict.ConflictCollection;
    19 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
    2019import org.openstreetmap.josm.data.osm.Node;
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5150    private Set<OsmPrimitive> origVersionsOfTouchedPrimitives;
    5251
    53     /**
    54      * the data structure with child->parent references
    55      */
    56     private BackreferencedDataSet backreferenceDataSet;
    57 
    5852    protected void init(Collection<OsmPrimitive> toPurge) {
    5953        this.toPurge = toPurge;
     
    141135    protected void removeReferecesToPrimitive(OsmPrimitive child, Set<OsmPrimitive> hive) {
    142136        hive.remove(child);
    143         for (OsmPrimitive parent: this.backreferenceDataSet.getParents(child)) {
     137        for (OsmPrimitive parent: child.getReferrers()) {
    144138            if (toPurge.contains(parent))
    145139                // parent itself is to be purged. This method is going to be
     
    177171    @Override
    178172    public boolean executeCommand() {
    179         if (backreferenceDataSet == null) {
    180             backreferenceDataSet = new BackreferencedDataSet();
    181         }
    182173        HashSet<OsmPrimitive> hive = new HashSet<OsmPrimitive>();
    183174
     
    198189            }
    199190        }
    200         // we don't need this any more
    201         backreferenceDataSet = null;
    202191        return super.executeCommand();
    203192    }
     
    231220        super.undoCommand();
    232221    }
    233 
    234     /**
    235      * Use to inject a backreference data set used when the command
    236      * is executed.
    237      *
    238      * @param ds the backreference data set
    239      */
    240     public void setBackreferenceDataSet(BackreferencedDataSet ds) {
    241         this.backreferenceDataSet = ds;
    242     }
    243222}
Note: See TracChangeset for help on using the changeset viewer.