Changeset 35456 in osm


Ignore:
Timestamp:
2020-05-17T12:09:32+02:00 (4 years ago)
Author:
simon04
Message:

Java 8: use Stream

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java

    r35329 r35456  
    1717import java.util.logging.Logger;
    1818import java.util.regex.Pattern;
     19import java.util.stream.Collectors;
    1920
    2021import javax.xml.parsers.DocumentBuilder;
     
    290291            if (data == null)
    291292                return "Error loading Bing attribution data";
    292             StringBuilder a = new StringBuilder();
    293             for (Attribution attr : data) {
    294                 if (zoom <= attr.maxZoom && zoom >= attr.minZoom) {
    295                     if (topLeft.getLon() < attr.max.getLon() && botRight.getLon() > attr.min.getLon()
    296                             && topLeft.getLat() > attr.min.getLat() && botRight.getLat() < attr.max.getLat()) {
    297                         a.append(attr.attributionText);
    298                         a.append(' ');
    299                     }
    300                 }
    301             }
    302             return a.toString();
     293            return data.stream()
     294                    .filter(attr -> zoom <= attr.maxZoom && zoom >= attr.minZoom)
     295                    .filter(attr -> topLeft.getLon() < attr.max.getLon() && botRight.getLon() > attr.min.getLon())
     296                    .filter(attr -> topLeft.getLat() > attr.min.getLat() && botRight.getLat() < attr.max.getLat())
     297                    .map(attr -> attr.attributionText)
     298                    .collect(Collectors.joining(" "));
    303299        } catch (RuntimeException e) {
    304300            e.printStackTrace();
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

    r35421 r35456  
    33
    44import java.io.IOException;
     5import java.util.Arrays;
    56import java.util.HashMap;
    67import java.util.Map;
     
    187188        Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
    188189        while (m.find()) {
    189             boolean isSupportedPattern = false;
    190             for (Pattern pattern : ALL_PATTERNS) {
    191                 if (pattern.matcher(m.group()).matches()) {
    192                     isSupportedPattern = true;
    193                     break;
    194                 }
    195             }
     190            boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> pattern.matcher(m.group()).matches());
    196191            if (!isSupportedPattern) {
    197192                throw new IllegalArgumentException(
Note: See TracChangeset for help on using the changeset viewer.