Ignore:
Timestamp:
2020-05-17T17:02:28+02:00 (6 years ago)
Author:
simon04
Message:

see #19251 - Java 8: use Stream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r16212 r16445  
    1111import java.util.Set;
    1212import java.util.stream.Collectors;
     13import java.util.stream.IntStream;
    1314
    1415import org.openstreetmap.josm.data.coor.LatLon;
     
    120121     */
    121122    public boolean containsNode(Node node) {
    122         if (node == null) return false;
    123 
    124         for (Node n : nodes) {
    125             if (n.equals(node))
    126                 return true;
    127         }
    128         return false;
     123        return node != null && Arrays.asList(nodes).contains(node);
    129124    }
    130125
     
    326321        if (!super.hasEqualSemanticAttributes(other, testInterestingTagsOnly))
    327322            return false;
    328         for (int i = 0; i < getNodesCount(); i++) {
    329             if (!getNode(i).hasEqualSemanticAttributes(w.getNode(i)))
    330                 return false;
    331         }
    332         return true;
     323        return IntStream.range(0, getNodesCount())
     324                .allMatch(i -> getNode(i).hasEqualSemanticAttributes(w.getNode(i)));
    333325    }
    334326
     
    373365        try {
    374366            boolean closed = isClosed() && selection.contains(lastNode());
    375             List<Node> copy = new ArrayList<>();
    376 
    377             for (Node n: nodes) {
    378                 if (!selection.contains(n)) {
    379                     copy.add(n);
    380                 }
    381             }
     367            List<Node> copy = Arrays.stream(nodes)
     368                    .filter(n -> !selection.contains(n))
     369                    .collect(Collectors.toList());
    382370
    383371            int i = copy.size();
     
    524512        /* circular ways have only inner nodes, so return true for them! */
    525513        if (n == nodes[0] && n == nodes[nodes.length-1]) return true;
    526         for (int i = 1; i < nodes.length - 1; ++i) {
    527             if (nodes[i] == n) return true;
    528         }
    529         return false;
     514        return IntStream.range(1, nodes.length - 1)
     515                .anyMatch(i -> nodes[i] == n);
    530516    }
    531517
Note: See TracChangeset for help on using the changeset viewer.