Ignore:
Timestamp:
2020-05-17T14:18:22+02:00 (4 years ago)
Author:
simon04
Message:

see #19251 - Java 8: use Stream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r16187 r16438  
    3232import java.util.Map;
    3333import java.util.Map.Entry;
     34import java.util.Objects;
    3435import java.util.Optional;
    3536import java.util.Set;
     
    3839import java.util.concurrent.atomic.AtomicInteger;
    3940import java.util.regex.Pattern;
     41import java.util.stream.Collectors;
     42import java.util.stream.Stream;
    4043
    4144import javax.swing.AbstractAction;
     
    5255import org.openstreetmap.josm.data.APIDataSet;
    5356import org.openstreetmap.josm.data.Bounds;
    54 import org.openstreetmap.josm.data.DataSource;
    5557import org.openstreetmap.josm.data.ProjectionBounds;
    5658import org.openstreetmap.josm.data.UndoRedoHandler;
     
    826828
    827829    private static boolean containsOnlyGpxTags(Tagged t) {
    828         for (String key : t.getKeys().keySet()) {
    829             if (!GpxConstants.WPT_KEYS.contains(key) && !key.startsWith(GpxConstants.GPX_PREFIX)) {
    830                 return false;
    831             }
    832         }
    833         return true;
     830        return t.getKeys().keySet().stream()
     831                .allMatch(key -> GpxConstants.WPT_KEYS.contains(key) || key.startsWith(GpxConstants.GPX_PREFIX));
    834832    }
    835833
     
    890888        addStringIfPresent(wpt, n, GpxConstants.GPX_SRC, "source", "source:position");
    891889
    892         Collection<GpxLink> links = new ArrayList<>();
    893         for (String key : new String[]{"link", "url", "website", "contact:website"}) {
    894             String value = gpxVal(n, key);
    895             if (value != null) {
    896                 links.add(new GpxLink(value));
    897             }
    898         }
     890        Collection<GpxLink> links = Stream.of("link", "url", "website", "contact:website")
     891                .map(key -> gpxVal(n, key))
     892                .filter(Objects::nonNull)
     893                .map(GpxLink::new)
     894                .collect(Collectors.toList());
    899895        wpt.put(GpxConstants.META_LINKS, links);
    900896
     
    968964
    969965    private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String... osmKeys) {
    970         List<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys));
    971         possibleKeys.add(0, gpxKey);
    972         for (String key : possibleKeys) {
    973             String value = gpxVal(p, key);
    974             // Sanity checks
    975             if (value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) {
    976                 wpt.put(gpxKey, value);
    977                 break;
    978             }
    979         }
     966        Stream.concat(Stream.of(gpxKey), Arrays.stream(osmKeys))
     967                .map(key -> gpxVal(p, key))
     968                // Sanity checks
     969                .filter(value -> value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)))
     970                .findFirst()
     971                .ifPresent(value -> wpt.put(gpxKey, value));
    980972    }
    981973
     
    10291021            return true;
    10301022
    1031         boolean layerBoundsPoint = false;
    1032         for (DataSource src : this.data.getDataSources()) {
    1033             if (src.bounds.contains(coor)) {
    1034                 layerBoundsPoint = true;
    1035                 break;
    1036             }
    1037         }
    1038         return layerBoundsPoint;
     1023        return this.data.getDataSources().stream()
     1024                .anyMatch(src -> src.bounds.contains(coor));
    10391025    }
    10401026
     
    12291215     */
    12301216    private boolean isDataSetEmpty() {
    1231         if (data != null) {
    1232             for (OsmPrimitive osm : data.allNonDeletedPrimitives()) {
    1233                 if (!osm.isDeleted() || !osm.isNewOrUndeleted())
    1234                     return false;
    1235             }
    1236         }
    1237         return true;
     1217        return data == null || data.allNonDeletedPrimitives().stream()
     1218                .allMatch(osm -> osm.isDeleted() && osm.isNewOrUndeleted());
    12381219    }
    12391220
Note: See TracChangeset for help on using the changeset viewer.