Changeset 2565 in josm for trunk/src


Ignore:
Timestamp:
2009-12-03T20:26:00+01:00 (12 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
Files:
1 added
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r2323 r2565  
    22package org.openstreetmap.josm.actions;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66
    77import java.awt.event.ActionEvent;
     
    2424import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2525import org.openstreetmap.josm.data.osm.Way;
    26 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    2726import org.openstreetmap.josm.tools.Shortcut;
    2827
     
    173172            if (a1 < 999) {
    174173                // if it is, delete it
    175                 CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet());
    176                 refs.initialize();
    177                 refs.visit(n1);
    178                 if (refs.getData().isEmpty() || ((refs.getData().size() == 1) && (refs.getData().contains(existingWay)))) {
     174                List<OsmPrimitive> parents = n1.getReferrers();
     175                if (parents.isEmpty() || ((parents.size() == 1) && (parents.contains(existingWay)))) {
    179176                    cmds.add(new DeleteCommand(n1));
    180177                }
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r2512 r2565  
    2525import org.openstreetmap.josm.command.DeleteCommand;
    2626import org.openstreetmap.josm.command.SequenceCommand;
    27 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
    2827import org.openstreetmap.josm.data.osm.Node;
    2928import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3030import org.openstreetmap.josm.data.osm.TagCollection;
    3131import org.openstreetmap.josm.data.osm.Way;
    32 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
    3332import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3433import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    9089
    9190    /**
    92      * Merges the nodes in <code>node</code> onto one of the nodes. Uses the dataset
    93      * managed by <code>layer</code> as reference.
    94      *
    95      * @param layer the reference data layer. Must not be null.
    96      * @param nodes the collection of nodes. Ignored if null.
    97      * @param targetNode the target node the collection of nodes is merged to. Must not be null.
    98      * @throws IllegalArgumentException thrown if layer is null
    99      * @throws IllegalArgumentException thrown if targetNode is null
    100      *
    101      */
    102     public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode) throws IllegalArgumentException{
    103         if (layer == null)
    104             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes"));
    105         if (targetNode == null)
    106             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "targetNode"));
    107 
    108         if (nodes == null)
    109             return null;
    110         nodes.remove(null); // just in case
    111         BackreferencedDataSet backreferences = new BackreferencedDataSet();
    112         return mergeNodes(layer,backreferences, nodes, targetNode);
    113     }
    114 
    115     /**
    11691     * Fixes the parent ways referring to one of the nodes.
    11792     *
     
    11994     * which is referred to by a relation.
    12095     *
    121      * @param backreferences the backreference data set
    12296     * @param nodesToDelete the collection of nodes to be deleted
    12397     * @param targetNode the target node the other nodes are merged to
    12498     * @return a list of commands; null, if the ways could not be fixed
    12599     */
    126     protected static List<Command> fixParentWays(BackreferencedDataSet backreferences, Collection<OsmPrimitive> nodesToDelete, Node targetNode) {
     100    protected static List<Command> fixParentWays(Collection<OsmPrimitive> nodesToDelete, Node targetNode) {
    127101        List<Command> cmds = new ArrayList<Command>();
    128102        Set<Way> waysToDelete = new HashSet<Way>();
    129103
    130         for (Way w: OsmPrimitive.getFilteredList(backreferences.getParents(nodesToDelete), Way.class)) {
     104        for (Way w: OsmPrimitive.getFilteredList(OsmPrimitive.getReferrer(nodesToDelete), Way.class)) {
    131105            ArrayList<Node> newNodes = new ArrayList<Node>(w.getNodesCount());
    132106            for (Node n: w.getNodes()) {
     
    145119            }
    146120            if (newNodes.size() < 2) {
    147                 if (backreferences.getParents(w).isEmpty()) {
     121                if (w.getReferrers().isEmpty()) {
    148122                    waysToDelete.add(w);
    149123                } else {
     
    171145                    return null;
    172146                }
    173             } else if(newNodes.size() < 2 && backreferences.getParents(w).isEmpty()) {
     147            } else if(newNodes.size() < 2 && w.getReferrers().isEmpty()) {
    174148                waysToDelete.add(w);
    175149            } else {
     
    187161    /**
    188162     * Merges the nodes in <code>nodes</code> onto one of the nodes. Uses the dataset
    189      * managed by <code>layer</code> as reference. <code>backreferences</code> is a precomputed
    190      * collection of all parent/child references in the dataset.
     163     * managed by <code>layer</code> as reference.
    191164     *
    192165     * @param layer layer the reference data layer. Must not be null.
    193      * @param backreferences if null, backreferences are first computed from layer.data; otherwise
    194      *    backreferences.getSource() == layer.data must be true
    195166     * @param nodes the collection of nodes. Ignored if null.
    196167     * @param targetNode the target node the collection of nodes is merged to. Must not be null.
    197168     * @throw IllegalArgumentException thrown if layer is null
    198      * @throw IllegalArgumentException thrown if  backreferences.getSource() != layer.data
    199169     */
    200     public static Command mergeNodes(OsmDataLayer layer, BackreferencedDataSet backreferences, Collection<Node> nodes, Node targetNode) {
     170    public static Command mergeNodes(OsmDataLayer layer,Collection<Node> nodes, Node targetNode) {
    201171        if (layer == null)
    202172            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes"));
     
    205175        if (nodes == null)
    206176            return null;
    207         if (backreferences == null) {
    208             backreferences = new BackreferencedDataSet();
    209         }
    210 
    211         Set<RelationToChildReference> relationToNodeReferences = backreferences.getRelationToChildReferences(nodes);
     177
     178
     179        Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes);
    212180
    213181        // build the tag collection
     
    245213        Collection<Way> waysToDelete= new HashSet<Way>();
    246214        List<Command> wayFixCommands = fixParentWays(
    247                 backreferences,
    248215                nodesToDelete,
    249216                targetNode
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r2510 r2565  
    2020import org.openstreetmap.josm.data.osm.User;
    2121import org.openstreetmap.josm.data.osm.Way;
    22 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    2322import org.openstreetmap.josm.tools.DateUtils;
    2423
     
    3332    private static String  rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}");
    3433    private PushbackTokenizer tokenizer;
    35     private CollectBackReferencesVisitor childBackRefs;
    3634
    3735    public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) {
     
    3937        this.regexSearch = regexSearch;
    4038        this.tokenizer = tokenizer;
    41         childBackRefs = new CollectBackReferencesVisitor(true);
    4239    }
    4340
     
    527524    private static class Child extends Match {
    528525        private final Match parent;
    529         private final CollectBackReferencesVisitor childBackRefs;
    530 
    531         public Child(Match m, CollectBackReferencesVisitor childBackRefs) {
     526
     527        public Child(Match m) {
    532528            // "child" (null) should mean the same as "child()"
    533529            // (Always). I.e. match everything
     
    537533                parent = m;
    538534            }
    539             this.childBackRefs = childBackRefs;
    540535        }
    541536
    542537        @Override public boolean match(OsmPrimitive osm) {
    543538            boolean isChild = false;
    544             childBackRefs.initialize();
    545             osm.visit(childBackRefs);
    546             for (OsmPrimitive p : childBackRefs.getData()) {
     539            for (OsmPrimitive p : osm.getReferrers()) {
    547540                isChild |= parent.match(p);
    548541            }
     
    651644            return new Selected();
    652645        else if (tok.equals("child"))
    653             return new Child(parseParens(), childBackRefs);
     646            return new Child(parseParens());
    654647        else if (tok.equals("parent"))
    655648            return new Parent(parseParens());
  • 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}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2512 r2565  
    149149    }
    150150
     151    /**
     152     * Replies the collection of referring primitives for the primitives in <code>primitives</code>.
     153     *
     154     * @param primitives the collection of primitives.
     155     * @return the collection of referring primitives for the primitives in <code>primitives</code>;
     156     * empty set if primitives is null or if there are no referring primitives
     157     */
     158    static public Set<OsmPrimitive> getReferrer(Collection<? extends OsmPrimitive> primitives) {
     159        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
     160        if (primitives == null || primitives.isEmpty()) return ret;
     161        for (OsmPrimitive p: primitives) {
     162            ret.addAll(p.getReferrers());
     163        }
     164        return ret;
     165    }
     166
     167
    151168    /* mappaint data */
    152169    public ElemStyle mappaintStyle = null;
  • trunk/src/org/openstreetmap/josm/gui/actionsupport/DeleteFromRelationConfirmationDialog.java

    r2512 r2565  
    22package org.openstreetmap.josm.gui.actionsupport;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56import static org.openstreetmap.josm.tools.I18n.trn;
     
    3839import org.openstreetmap.josm.data.osm.NameFormatter;
    3940import org.openstreetmap.josm.data.osm.OsmPrimitive;
    40 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
     41import org.openstreetmap.josm.data.osm.RelationToChildReference;
    4142import org.openstreetmap.josm.gui.DefaultNameFormatter;
    4243import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    4647import org.openstreetmap.josm.tools.ImageProvider;
    4748import org.openstreetmap.josm.tools.WindowGeometry;
    48 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    4949
    5050/**
     
    264264            RelationToChildReference ref = data.get(rowIndex);
    265265            switch(columnIndex) {
    266                 case 0: return ref.getChild();
    267                 case 1: return ref.getParent();
    268                 case 2: return ref.getPosition();
    269                 case 3: return ref.getRole();
    270                 default:
    271                     assert false: "Illegal column index";
     266            case 0: return ref.getChild();
     267            case 1: return ref.getParent();
     268            case 2: return ref.getPosition();
     269            case 3: return ref.getRole();
     270            default:
     271                assert false: "Illegal column index";
    272272            }
    273273            return null;
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java

    r2512 r2565  
    1818import org.openstreetmap.josm.data.osm.Relation;
    1919import org.openstreetmap.josm.data.osm.RelationMember;
    20 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;
     20import org.openstreetmap.josm.data.osm.RelationToChildReference;
    2121
    2222/**
     
    9292        RelationMemberConflictDecision d = decisions.get(row);
    9393        switch(column) {
    94             case 0: /* relation */ return d.getRelation();
    95             case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1
    96             case 2: /* role */ return d.getRole();
    97             case 3: /* original */ return d.getOriginalPrimitive();
    98             case 4: /* decision */ return d.getDecision();
     94        case 0: /* relation */ return d.getRelation();
     95        case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1
     96        case 2: /* role */ return d.getRole();
     97        case 3: /* original */ return d.getOriginalPrimitive();
     98        case 4: /* decision */ return d.getDecision();
    9999        }
    100100        return null;
     
    105105        RelationMemberConflictDecision d = decisions.get(row);
    106106        switch(column) {
    107             case 2: /* role */
    108                 d.setRole((String)value);
    109                 break;
    110             case 4: /* decision */
    111                 d.decide((RelationMemberConflictDecisionType)value);
    112                 refresh();
    113                 break;
     107        case 2: /* role */
     108            d.setRole((String)value);
     109            break;
     110        case 4: /* decision */
     111            d.decide((RelationMemberConflictDecisionType)value);
     112            refresh();
     113            break;
    114114        }
    115115        fireTableDataChanged();
     
    233233            } else {
    234234                switch(decision.getDecision()) {
    235                     case KEEP:
    236                         rmNew = new RelationMember(decision.getRole(),newPrimitive);
    237                         modifiedRelation.addMember(rmNew);
    238                         isChanged |= ! rm.equals(rmNew);
    239                         break;
    240                     case REMOVE:
    241                         isChanged = true;
    242                         // do nothing
    243                         break;
    244                     case UNDECIDED:
    245                         // FIXME: this is an error
    246                         break;
     235                case KEEP:
     236                    rmNew = new RelationMember(decision.getRole(),newPrimitive);
     237                    modifiedRelation.addMember(rmNew);
     238                    isChanged |= ! rm.equals(rmNew);
     239                    break;
     240                case REMOVE:
     241                    isChanged = true;
     242                    // do nothing
     243                    break;
     244                case UNDECIDED:
     245                    // FIXME: this is an error
     246                    break;
    247247                }
    248248            }
     
    278278            }
    279279            switch(decision.getDecision()) {
    280                 case REMOVE: return true;
    281                 case KEEP:
    282                     if (!relation.getMember(i).getRole().equals(decision.getRole()))
    283                         return true;
    284                     if (relation.getMember(i).getMember() != newPrimitive)
    285                         return true;
    286                 case UNDECIDED:
    287                     // FIXME: handle error
     280            case REMOVE: return true;
     281            case KEEP:
     282                if (!relation.getMember(i).getRole().equals(decision.getRole()))
     283                    return true;
     284                if (relation.getMember(i).getMember() != newPrimitive)
     285                    return true;
     286            case UNDECIDED:
     287                // FIXME: handle error
    288288            }
    289289        }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2512 r2565  
    4949import org.openstreetmap.josm.data.gpx.GpxTrack;
    5050import org.openstreetmap.josm.data.gpx.WayPoint;
    51 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
    5251import org.openstreetmap.josm.data.osm.DataSet;
    5352import org.openstreetmap.josm.data.osm.DataSetMerger;
     
    394393     */
    395394    protected PurgePrimitivesCommand buildPurgeCommand() {
    396         BackreferencedDataSet ds = new BackreferencedDataSet();
    397395        ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>();
    398396        conflictLoop: for (Conflict<?> c: conflicts) {
     
    416414                // gets purged.
    417415                //
    418                 for (OsmPrimitive parent: ds.getParents(c.getMy())) {
     416                for (OsmPrimitive parent: c.getMy().getReferrers()) {
    419417                    if (parent.isModified() && parent instanceof Way) {
    420418                        continue conflictLoop;
     
    426424        if (toPurge.isEmpty()) return null;
    427425        PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge);
    428         cmd.setBackreferenceDataSet(ds);
    429426        return cmd;
    430427    }
Note: See TracChangeset for help on using the changeset viewer.