Ignore:
Timestamp:
2010-09-10T21:51:20+02:00 (14 years ago)
Author:
skela
Message:

'Optimize WaySelection.findWay().'

Location:
applications/editors/josm/plugins/wayselector
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wayselector/build.xml

    r23100 r23103  
    3131
    3232        <!-- enter the SVN commit message -->
    33         <property name="commit.message" value="Do not mutate the collection of selected ways. Convert TAB to spaces." />
     33        <property name="commit.message" value="Optimize WaySelection.findWay()." />
    3434        <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    3535        <property name="plugin.main.version" value="3095" />
  • applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java

    r23100 r23103  
    6969     @param node perimeter node from which to extend the selection
    7070     @return a way by which to extend the selection, or null */
    71     private Way findWay(Collection<OsmPrimitive> selection, Node node) {
    72         TreeSet<Way> foundWays = new TreeSet<Way>();
     71    private static Way findWay(Collection<OsmPrimitive> selection, Node node) {
     72        Way foundWay = null;
    7373
    7474        for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(),
    75                                                     Way.class))
    76             if (way.getNodesCount() >= 2 && !selection.contains(way) &&
    77                 way.isFirstLastNode(node))
    78                 foundWays.add(way);
     75                                                    Way.class)) {
     76            if (way.getNodesCount() < 2 || !way.isFirstLastNode(node)
     77                || selection.contains(way))
     78                continue;
    7979
    80         return foundWays.size() == 1 ? foundWays.first() : null;
     80            /* A previously unselected way was found that is connected
     81            to the node. */
     82            if (foundWay != null)
     83                /* This is not the only qualifying way. There is a
     84                branch at the node, and we cannot extend the selection. */
     85                return null;
     86
     87            /* Remember the first found qualifying way. */
     88            foundWay = way;
     89        }
     90
     91        /* Return the only way found, or null if none was found. */
     92        return foundWay;
    8193    }
    8294
Note: See TracChangeset for help on using the changeset viewer.