Ignore:
Timestamp:
2020-05-17T12:08:17+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/data/imagery/ImageryInfo.java

    r16130 r16436  
    4848import org.openstreetmap.josm.tools.Logging;
    4949import org.openstreetmap.josm.tools.MultiMap;
     50import org.openstreetmap.josm.tools.StreamUtils;
    5051import org.openstreetmap.josm.tools.Utils;
    5152
     
    9596         */
    9697        public static ImageryType fromString(String s) {
    97             for (ImageryType type : ImageryType.values()) {
    98                 if (type.getTypeString().equals(s)) {
    99                     return type;
    100                 }
    101             }
    102             return null;
     98            return Arrays.stream(ImageryType.values())
     99                    .filter(type -> type.getTypeString().equals(s))
     100                    .findFirst().orElse(null);
    103101        }
    104102    }
     
    170168         */
    171169        public static ImageryCategory fromString(String s) {
    172             for (ImageryCategory category : ImageryCategory.values()) {
    173                 if (category.getCategoryString().equals(s)) {
    174                     return category;
    175                 }
    176             }
    177             return null;
     170            return Arrays.stream(ImageryCategory.values())
     171                    .filter(category -> category.getCategoryString().equals(s))
     172                    .findFirst().orElse(null);
    178173        }
    179174    }
     
    403398            if (i.bounds != null) {
    404399                bounds = i.bounds.encodeAsString(",");
    405                 StringBuilder shapesString = new StringBuilder();
    406                 for (Shape s : i.bounds.getShapes()) {
    407                     if (shapesString.length() > 0) {
    408                         shapesString.append(';');
    409                     }
    410                     shapesString.append(s.encodeAsString(","));
    411                 }
    412                 if (shapesString.length() > 0) {
    413                     shapes = shapesString.toString();
     400                String shapesString = Shape.encodeAsString(i.bounds.getShapes());
     401                if (!shapesString.isEmpty()) {
     402                    shapes = shapesString;
    414403                }
    415404            }
     
    10931082     */
    10941083    public static Collection<String> getActiveIds() {
    1095         ArrayList<String> ids = new ArrayList<>();
    10961084        IPreferences pref = Config.getPref();
    1097         if (pref != null) {
    1098             List<ImageryPreferenceEntry> entries = StructUtils.getListOfStructs(
    1099                 pref, "imagery.entries", null, ImageryPreferenceEntry.class);
    1100             if (entries != null) {
    1101                 for (ImageryPreferenceEntry prefEntry : entries) {
    1102                     if (prefEntry.id != null && !prefEntry.id.isEmpty())
    1103                         ids.add(prefEntry.id);
    1104                 }
    1105                 Collections.sort(ids);
    1106             }
    1107         }
    1108         return ids;
     1085        if (pref == null) {
     1086            return Collections.emptyList();
     1087        }
     1088        List<ImageryPreferenceEntry> entries = StructUtils.getListOfStructs(pref, "imagery.entries", null, ImageryPreferenceEntry.class);
     1089        if (entries == null) {
     1090            return Collections.emptyList();
     1091        }
     1092        return entries.stream()
     1093                .filter(prefEntry -> prefEntry.id != null && !prefEntry.id.isEmpty())
     1094                .map(prefEntry -> prefEntry.id)
     1095                .sorted()
     1096                .collect(Collectors.toList());
    11091097    }
    11101098
     
    12301218        this.serverProjections = serverProjections.stream()
    12311219                .map(String::intern)
    1232                 .collect(Collectors.collectingAndThen(Collectors.toList(), Utils::toUnmodifiableList));
     1220                .collect(StreamUtils.toUnmodifiableList());
    12331221    }
    12341222
Note: See TracChangeset for help on using the changeset viewer.