Changeset 35674 in osm for applications


Ignore:
Timestamp:
2020-12-22T14:11:32+01:00 (4 years ago)
Author:
GerdP
Message:
  • simplify updateEnabledState
  • minor performance improvements
  • checkstyle or sonarling issues, javadoc corrections
Location:
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java

    r35579 r35674  
    1111import java.util.List;
    1212import java.util.Set;
    13 import java.util.stream.Collectors;
    1413
    1514import javax.swing.JOptionPane;
     
    2726
    2827/**
    29  * Pastes relation membership from objects in the paste buffer onto selected object(s).
     28 * Align way nodes. Similar to Align nodes in line, but uses a parent way as context.
    3029 *
    3130 * @author Zverik
     
    139138    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    140139        Set<Node> nodes = filterNodes(selection);
    141         Set<Way> ways = findCommonWays(nodes);
    142         setEnabled(ways != null && ways.size() == 1 && !nodes.isEmpty());
    143     }
    144 
    145     private Set<Way> findCommonWays(Set<Node> nodes) {
     140        if (nodes.isEmpty())
     141            setEnabled(false);
     142        else {
     143            Set<Way> ways = findCommonWays(nodes);
     144            setEnabled(ways != null && ways.size() == 1);
     145        }
     146    }
     147
     148    private static Set<Way> findCommonWays(Set<Node> nodes) {
    146149        Set<Way> ways = null;
    147         for (Node n : nodes.stream().filter(n -> n.getDataSet() != null).collect(Collectors.toList())) {
     150        for (Node n : nodes) {
     151            if (n.getDataSet() == null)
     152                continue;
    148153            if (ways == null)
    149154                ways = new HashSet<>(n.getParentWays());
    150155            else {
    151156                ways.retainAll(n.getParentWays());
     157                if (ways.isEmpty())
     158                    break;
    152159            }
    153160        }
     
    155162    }
    156163
    157     private Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) {
     164    private static Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) {
    158165        Set<Node> result = new HashSet<>();
    159166        if (selection != null) {
     
    174181     * @return the index of the node right after the largest empty span
    175182     */
    176     private int findFirstNode(Way way, Set<Node> nodes) {
     183    private static int findFirstNode(Way way, Set<Node> nodes) {
    177184        int pos = 0;
    178185        while (pos < way.getNodesCount() && !nodes.contains(way.getNode(pos))) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java

    r35617 r35674  
    169169            nodeToReplace = findNearestNode(subjectNode, nodePool.stream().filter(Node::isNew).collect(Collectors.toList()));
    170170            if (nodeToReplace == null) {
    171                 nodeToReplace = findNearestNode(subjectNode, nodePool);
     171                nodeToReplace = findNearestNode(subjectNode, nodePool);
    172172            }
    173173        }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java

    r35579 r35674  
    6060    @Override
    6161    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    62         if (selection == null) {
    63             setEnabled(false);
    64             return;
    65         }
    66         setEnabled(!selection.isEmpty());
     62        setEnabled(selection != null && !selection.isEmpty());
    6763    }
    6864}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java

    r35579 r35674  
    5757    @Override
    5858    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    59         if (selection == null) {
    60             setEnabled(false);
    61             return;
    62         }
    63         setEnabled(!selection.isEmpty());
     59        setEnabled(selection != null && !selection.isEmpty());
    6460    }
    6561}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java

    r35579 r35674  
    5858    @Override
    5959    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    60         if (selection == null) {
    61             setEnabled(false);
    62             return;
    63         }
    64         setEnabled(!selection.isEmpty());
     60        setEnabled(selection != null && !selection.isEmpty());
    6561    }
    6662}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java

    r35579 r35674  
    5858    @Override
    5959    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    60         if (selection == null) {
    61             setEnabled(false);
    62             return;
    63         }
    64         setEnabled(!selection.isEmpty());
     60        setEnabled(selection != null && !selection.isEmpty());
    6561    }
    6662}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java

    r35579 r35674  
    6060    @Override
    6161    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    62         if (selection == null) {
    63             setEnabled(false);
    64             return;
    65         }
    66         setEnabled(!selection.isEmpty());
     62        setEnabled(selection != null && !selection.isEmpty());
    6763    }
    6864}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java

    r35613 r35674  
    5656    @Override
    5757    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    58         if (selection == null) {
    59             setEnabled(false);
    60             return;
    61         }
    62         setEnabled(!selection.isEmpty());
     58        setEnabled(selection != null && !selection.isEmpty());
    6359    }
    6460}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java

    r35579 r35674  
    119119    @Override
    120120    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    121         if (selection == null) {
    122             setEnabled(false);
    123             return;
    124         }
    125         int count = 0, rank = 100;
    126         for (OsmPrimitive p : selection) {
    127             if (p instanceof Way) {
    128                 count++;
    129                 rank = Math.min(rank, getHighwayRank(p));
     121        int count = 0;
     122        int rank = 100;
     123        if (selection != null) {
     124            for (OsmPrimitive p : selection) {
     125                if (p instanceof Way) {
     126                    count++;
     127                    if (count > 2)
     128                        break;
     129                    rank = Math.min(rank, getHighwayRank(p));
     130                }
    130131            }
    131132        }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java

    r35579 r35674  
    4141    @Override
    4242    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    43         if (selection == null) {
    44             setEnabled(false);
    45             return;
    46         }
    47         setEnabled(!selection.isEmpty());
     43        setEnabled(selection != null && !selection.isEmpty());
    4844    }
    4945}
Note: See TracChangeset for help on using the changeset viewer.