Ignore:
Timestamp:
2009-08-03T21:18:50+02:00 (15 years ago)
Author:
jttt
Message:

Way refactoring - rewritten another parts of code to the new nodes api

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

Legend:

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

    r1856 r1898  
    6767     * Constructor for a single data item. Use the collection constructor to delete multiple
    6868     * objects.
    69      * 
     69     *
    7070     * @param layer the layer context for deleting this primitive
    7171     * @param data the primitive to delete
     
    7979     * Constructor for a collection of data to be deleted in the context of
    8080     * a specific layer
    81      * 
     81     *
    8282     * @param layer the layer context for deleting these primitives
    8383     * @param data the primitives to delete
     
    137137    /**
    138138     * Delete the primitives and everything they reference.
    139      * 
     139     *
    140140     * If a node is deleted, the node and all ways and relations the node is part of are deleted as
    141141     * well.
    142      * 
     142     *
    143143     * If a way is deleted, all relations the way is member of are also deleted.
    144      * 
     144     *
    145145     * If a way is deleted, only the way and no nodes are deleted.
    146      * 
     146     *
    147147     * @param selection The list of all object to be deleted.
    148148     * @return command A command to perform the deletions, or null of there is nothing to delete.
     
    204204                continue;
    205205            }
    206             for (Node n : ((Way) osm).nodes) {
     206            for (Node n : ((Way) osm).getNodes()) {
    207207                if (n.isTagged()) {
    208208                    continue;
     
    221221    /**
    222222     * Try to delete all given primitives.
    223      * 
     223     *
    224224     * If a node is used by a way, it's removed from that way. If a node or a way is used by a
    225225     * relation, inform the user and do not delete.
    226      * 
     226     *
    227227     * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If
    228228     * they are part of a relation, inform the user and do not delete.
    229      * 
     229     *
    230230     * @param layer the {@see OsmDataLayer} in whose context a primitive the primitives are deleted
    231231     * @param selection The objects to delete.
     
    279279            Way wnew = new Way(w);
    280280            wnew.removeNodes(primitivesToDelete);
    281             if (wnew.nodes.size() < 2) {
     281            if (wnew.getNodesCount() < 2) {
    282282                primitivesToDelete.add(w);
    283283
     
    347347            }
    348348            Way wnew = new Way(w);
    349             ArrayList<Node> nodesToStrip = new ArrayList<Node>();
     349            List<Node> nodesToKeep = new ArrayList<Node>();
    350350            // lookup new nodes which have been added to the set of deleted
    351351            // nodes ...
    352             for (Node n : wnew.nodes) {
    353                 if (n.id == 0 && primitivesToDelete.contains(n)) {
    354                     nodesToStrip.add(n);
     352            for (Node n : wnew.getNodes()) {
     353                if (n.id != 0 || !primitivesToDelete.contains(n)) {
     354                    nodesToKeep.add(n);
    355355                }
    356356            }
    357357            // .. and remove them from the way
    358358            //
    359             wnew.nodes.removeAll(nodesToStrip);
    360             if (!nodesToStrip.isEmpty()) {
     359            wnew.setNodes(nodesToKeep);
     360            if (nodesToKeep.size() < w.getNodesCount()) {
    361361                cmds.add(new ChangeCommand(w, wnew));
    362362            }
     
    373373        List<Node> n1 = new ArrayList<Node>(), n2 = new ArrayList<Node>();
    374374
    375         n1.addAll(ws.way.nodes.subList(0, ws.lowerIndex + 1));
    376         n2.addAll(ws.way.nodes.subList(ws.lowerIndex + 1, ws.way.nodes.size()));
     375        n1.addAll(ws.way.getNodes().subList(0, ws.lowerIndex + 1));
     376        n2.addAll(ws.way.getNodes().subList(ws.lowerIndex + 1, ws.way.getNodesCount()));
    377377
    378378        if (n1.size() < 2 && n2.size() < 2)
     
    380380
    381381        Way wnew = new Way(ws.way);
    382         wnew.nodes.clear();
    383382
    384383        if (n1.size() < 2) {
    385             wnew.nodes.addAll(n2);
     384            wnew.setNodes(n2);
    386385            return new ChangeCommand(ws.way, wnew);
    387386        } else if (n2.size() < 2) {
    388             wnew.nodes.addAll(n1);
     387            wnew.setNodes(n1);
    389388            return new ChangeCommand(ws.way, wnew);
    390389        } else {
    391390            Collection<Command> cmds = new LinkedList<Command>();
    392391
    393             wnew.nodes.addAll(n1);
     392            wnew.setNodes(n1);
    394393            cmds.add(new ChangeCommand(ws.way, wnew));
    395394
     
    398397                wnew2.keys = new HashMap<String, String>(wnew.keys);
    399398            }
    400             wnew2.nodes.addAll(n2);
     399            wnew2.setNodes(n2);
    401400            cmds.add(new AddCommand(wnew2));
    402401
     
    408407     * Check whether user is about to delete data outside of the download area. Request confirmation
    409408     * if he is.
    410      * 
     409     *
    411410     * @param layer the layer in whose context data is deleted
    412411     * @param primitivesToDelete the primitives to delete
  • trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java

    r1862 r1898  
    190190                // remember it on the "hive"
    191191                //
    192                 if (w.nodes.size() < 2) {
     192                if (w.getNodesCount() < 2) {
    193193                    System.out.println(tr("Warning: Purging way {0} because number of nodes dropped below 2. Current is {1}",
    194                             w.id,w.nodes.size()));
     194                            w.id,w.getNodesCount()));
    195195                    if (!hive.contains(w)) {
    196196                        hive.add(w);
Note: See TracChangeset for help on using the changeset viewer.