Changeset 16436 in josm for trunk/src/org/openstreetmap/josm/data/imagery
- Timestamp:
- 2020-05-17T12:08:17+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java
r15586 r16436 5 5 import java.net.MalformedURLException; 6 6 import java.net.URL; 7 import java.util.Arrays; 7 8 import java.util.Locale; 8 9 import java.util.function.BiPredicate; … … 35 36 36 37 static TransferMode fromString(String s) { 37 for (TransferMode type : TransferMode.values()) { 38 if (type.getTypeString().equals(s)) { 39 return type; 40 } 41 } 42 return null; 38 return Arrays.stream(TransferMode.values()) 39 .filter(type -> type.getTypeString().equals(s)) 40 .findFirst().orElse(null); 43 41 } 44 42 } -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r16130 r16436 48 48 import org.openstreetmap.josm.tools.Logging; 49 49 import org.openstreetmap.josm.tools.MultiMap; 50 import org.openstreetmap.josm.tools.StreamUtils; 50 51 import org.openstreetmap.josm.tools.Utils; 51 52 … … 95 96 */ 96 97 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); 103 101 } 104 102 } … … 170 168 */ 171 169 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); 178 173 } 179 174 } … … 403 398 if (i.bounds != null) { 404 399 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; 414 403 } 415 404 } … … 1093 1082 */ 1094 1083 public static Collection<String> getActiveIds() { 1095 ArrayList<String> ids = new ArrayList<>();1096 1084 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()); 1109 1097 } 1110 1098 … … 1230 1218 this.serverProjections = serverProjections.stream() 1231 1219 .map(String::intern) 1232 .collect( Collectors.collectingAndThen(Collectors.toList(), Utils::toUnmodifiableList));1220 .collect(StreamUtils.toUnmodifiableList()); 1233 1221 } 1234 1222 -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r16426 r16436 17 17 import java.util.TreeSet; 18 18 import java.util.concurrent.ExecutorService; 19 import java.util.stream.Collectors; 19 20 20 21 import org.openstreetmap.josm.data.StructUtils; … … 266 267 if (def.getId() != null) { 267 268 newKnownDefaults.add(def.getId()); 268 for (ImageryInfo i : layers) { 269 if (isSimilar(def, i)) { 270 isInUserList = true; 271 break; 272 } 273 } 269 isInUserList = layers.stream().anyMatch(i -> isSimilar(def, i)); 274 270 } else { 275 271 Logging.error("Default imagery ''{0}'' has no id. Skipping.", def.getName()); … … 362 358 */ 363 359 public void save() { 364 List<ImageryPreferenceEntry> entries = new ArrayList<>(); 365 for (ImageryInfo info : layers) { 366 entries.add(new ImageryPreferenceEntry(info)); 367 } 360 List<ImageryPreferenceEntry> entries = layers.stream() 361 .map(ImageryPreferenceEntry::new) 362 .collect(Collectors.toList()); 368 363 StructUtils.putListOfStructs(Config.getPref(), "imagery.entries", entries, ImageryPreferenceEntry.class); 369 364 } -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r14120 r16436 348 348 */ 349 349 public static OffsetBookmark getBookmarkByName(ImageryLayer layer, String name) { 350 for (OffsetBookmark b : allBookmarks) { 351 if (b.isUsable(layer) && name.equals(b.name)) 352 return b; 353 } 354 return null; 350 return allBookmarks.stream() 351 .filter(b -> b.isUsable(layer) && name.equals(b.name)) 352 .findFirst().orElse(null); 355 353 } 356 354 -
trunk/src/org/openstreetmap/josm/data/imagery/Shape.java
r12453 r16436 8 8 import java.util.List; 9 9 import java.util.Objects; 10 import java.util.stream.Collectors; 11 import java.util.stream.Stream; 10 12 11 13 import org.openstreetmap.gui.jmapviewer.Coordinate; … … 43 45 } 44 46 47 /** 48 * Encodes this as a string so that it may be parsed using {@link #Shape(String, String)} 49 * @param separator The separator 50 * @return The string encoded shape 51 */ 45 52 public String encodeAsString(String separator) { 46 StringBuilder sb = new StringBuilder(); 47 for (Coordinate c : coords) { 48 if (sb.length() != 0) { 49 sb.append(separator); 50 } 51 sb.append(c.getLat()).append(separator).append(c.getLon()); 52 } 53 return sb.toString(); 53 return coords.stream() 54 .flatMap(c -> Stream.of(c.getLat(), c.getLon())) 55 .map(String::valueOf) 56 .collect(Collectors.joining(separator)); 57 } 58 59 /** 60 * Encodes the shapes as a string using {@code ,} and {@code ;} as separators 61 * @return The string encoded shapes 62 */ 63 public static String encodeAsString(List<Shape> shapes) { 64 return shapes.stream() 65 .map(s -> s.encodeAsString(",")) 66 .collect(Collectors.joining(";")); 54 67 } 55 68 … … 61 74 if (latlon == null) 62 75 return false; 63 List<Node> nodes = new ArrayList<>(coords.size()); 64 for (Coordinate c : coords) { 65 nodes.add(new Node(new LatLon(c.getLat(), c.getLon()))); 66 } 76 List<Node> nodes = coords.stream() 77 .map(c -> new Node(new LatLon(c.getLat(), c.getLon()))) 78 .collect(Collectors.toList()); 67 79 return Geometry.nodeInsidePolygon(new Node(latlon), nodes); 68 80 } -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r16106 r16436 856 856 if (this.currentLayer != null) { 857 857 this.currentTileMatrixSet = this.currentLayer.tileMatrixSet; 858 Collection<Double> scales = new ArrayList<>(currentTileMatrixSet.tileMatrix.size()); 859 for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) { 860 scales.add(tileMatrix.scaleDenominator * 0.28e-03); 861 } 858 Collection<Double> scales = currentTileMatrixSet.tileMatrix.stream() 859 .map(tileMatrix -> tileMatrix.scaleDenominator * 0.28e-03) 860 .collect(Collectors.toList()); 862 861 this.nativeScaleList = new ScaleList(scales); 863 862 } … … 1061 1060 Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url); 1062 1061 while (m.find()) { 1063 boolean isSupportedPattern = false; 1064 for (String pattern : ALL_PATTERNS) { 1065 if (m.group().matches(pattern)) { 1066 isSupportedPattern = true; 1067 break; 1068 } 1069 } 1062 boolean isSupportedPattern = Arrays.stream(ALL_PATTERNS).anyMatch(pattern -> m.group().matches(pattern)); 1070 1063 if (!isSupportedPattern) { 1071 1064 throw new IllegalArgumentException( … … 1089 1082 */ 1090 1083 public Collection<String> getSupportedProjections() { 1091 Collection<String> ret = new LinkedHashSet<>(); 1092 if (currentLayer == null) { 1093 for (Layer layer: this.layers) { 1094 ret.add(layer.tileMatrixSet.crs); 1095 } 1096 } else { 1097 for (Layer layer: this.layers) { 1098 if (currentLayer.identifier.equals(layer.identifier)) { 1099 ret.add(layer.tileMatrixSet.crs); 1100 } 1101 } 1102 } 1103 return ret; 1084 return this.layers.stream() 1085 .filter(layer -> currentLayer == null || currentLayer.identifier.equals(layer.identifier)) 1086 .map(layer -> layer.tileMatrixSet.crs) 1087 .collect(Collectors.toCollection(LinkedHashSet::new)); 1104 1088 } 1105 1089
Note:
See TracChangeset
for help on using the changeset viewer.