Changeset 16438 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-05-17T14:18:22+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 127 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r14397 r16438 14 14 import java.util.List; 15 15 import java.util.Set; 16 import java.util.stream.Collectors; 16 17 17 18 import javax.swing.JOptionPane; … … 128 129 129 130 for (Node n: nodes) { 130 boolean isInside = false; 131 for (Way w: ways) { 132 if (w.getNodes().contains(n)) { 133 isInside = true; 134 break; 135 } 136 } 131 boolean isInside = ways.stream().anyMatch(w -> w.getNodes().contains(n)); 137 132 if (isInside) 138 133 inside.add(n); … … 252 247 */ 253 248 private static List<Node> collectNodesWithExternReferers(List<Way> ways) { 254 List<Node> withReferrers = new ArrayList<>(); 255 for (Way w: ways) { 256 for (Node n: w.getNodes()) { 257 if (n.getReferrers().size() > 1) { 258 withReferrers.add(n); 259 } 260 } 261 } 249 List<Node> withReferrers = ways.stream().flatMap(w -> w.getNodes().stream()).filter(n -> n.getReferrers().size() > 1).collect(Collectors.toList()); 262 250 return withReferrers; 263 251 } … … 316 304 */ 317 305 private static boolean actionAllowed(Collection<Node> nodes) { 318 boolean outside = false; 319 for (Node n: nodes) { 320 if (n.isOutsideDownloadArea()) { 321 outside = true; 322 break; 323 } 324 } 306 boolean outside = nodes.stream().anyMatch(Node::isOutsideDownloadArea); 325 307 if (outside) 326 308 new Notification( … … 353 335 for (Node node: way.getNodes()) { 354 336 if (way.isFirstLastNode(node)) continue; 355 for (Way wayOther: ways) { 356 if (way == wayOther) continue; 357 if (node.getReferrers().contains(wayOther)) return false; 337 if (ways.stream().filter(wayOther -> way != wayOther).anyMatch(wayOther -> node.getReferrers().contains(wayOther))) { 338 return false; 358 339 } 359 340 } -
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r16136 r16438 14 14 import java.util.Map; 15 15 import java.util.Set; 16 import java.util.stream.Collectors; 17 import java.util.stream.IntStream; 16 18 17 19 import javax.swing.JOptionPane; … … 234 236 // Choose nodes used as anchor points for projection. 235 237 Node[] anchors = nodePairFurthestApart(nodes); 236 Collection<Command> cmds = new ArrayList<>(nodes.size());237 238 Line line = new Line(anchors[0], anchors[1]); 238 for (Node node: nodes) {239 if (node != anchors[0] && node != anchors[1])240 cmds.add(line.projectionCommand(node));241 }239 Collection<Command> cmds = nodes.stream() 240 .filter(node -> node != anchors[0] && node != anchors[1]) 241 .map(line::projectionCommand) 242 .collect(Collectors.toList()); 242 243 return new SequenceCommand(tr("Align Nodes in Line"), cmds); 243 244 } … … 312 313 // see #9081 comment 6 313 314 EastNorth c = node.getEastNorth(); 314 double[] angle = new double[4]; 315 for (int i = 0; i < 4; i++) { 316 angle[i] = PolarCoor.computeAngle(neighbors.get(i).getEastNorth(), c); 317 } 315 double[] angle = IntStream.range(0, 4) 316 .mapToDouble(i -> PolarCoor.computeAngle(neighbors.get(i).getEastNorth(), c)).toArray(); 318 317 double[] deltaAngle = new double[3]; 319 318 for (int i = 0; i < 3; i++) { -
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r16135 r16438 18 18 import java.util.Set; 19 19 import java.util.stream.Collectors; 20 import java.util.stream.IntStream; 20 21 21 22 import javax.swing.JOptionPane; … … 219 220 unreversedWays.add(w); 220 221 } else { 221 boolean foundStartSegment = false;222 222 int last = path.lastIndexOf(w.getNode(0)); 223 223 224 for (int i = path.indexOf(w.getNode(0)); i <= last; i++) { 225 if (path.get(i) == w.getNode(0) && i + 1 < path.size() && w.getNode(1) == path.get(i + 1)) { 226 foundStartSegment = true; 227 break; 228 } 229 } 224 boolean foundStartSegment = IntStream.rangeClosed(path.indexOf(w.getNode(0)), last) 225 .anyMatch(i -> path.get(i) == w.getNode(0) && i + 1 < path.size() && w.getNode(1) == path.get(i + 1)); 230 226 if (foundStartSegment) { 231 227 unreversedWays.add(w); -
trunk/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java
r16138 r16438 8 8 import java.util.Collection; 9 9 import java.util.Collections; 10 import java.util.Objects; 11 import java.util.stream.Collectors; 10 12 13 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 14 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat; 11 15 import org.openstreetmap.josm.data.osm.DataSet; 12 16 import org.openstreetmap.josm.data.osm.Node; … … 34 38 @Override 35 39 public void actionPerformed(ActionEvent ae) { 36 StringBuilder s = new StringBuilder(); 37 for (Node n : getSelectedNodes()) { 38 s.append(n.lat()); 39 s.append(", "); 40 s.append(n.lon()); 41 s.append('\n'); 42 } 43 ClipboardUtils.copyString(s.toString().trim()); 40 ICoordinateFormat coordinateFormat = CoordinateFormatManager.getDefaultFormat(); 41 String string = getSelectedNodes().stream() 42 .map(Node::getCoor) 43 .filter(Objects::nonNull) 44 .map(c -> coordinateFormat.toString(c, ", ")) 45 .collect(Collectors.joining("\n")); 46 ClipboardUtils.copyString(string); 44 47 } 45 48 -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r14967 r16438 248 248 */ 249 249 private static List<Node> orderNodesByTrafficHand(List<Node> nodes) { 250 boolean rightHandTraffic = true; 251 for (Node n: nodes) { 252 if (!RightAndLefthandTraffic.isRightHandTraffic(n.getCoor())) { 253 rightHandTraffic = false; 254 break; 255 } 256 } 250 boolean rightHandTraffic = nodes.stream().allMatch(n -> RightAndLefthandTraffic.isRightHandTraffic(n.getCoor())); 257 251 if (rightHandTraffic == Geometry.isClockwise(nodes)) { 258 252 Collections.reverse(nodes); -
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r15531 r16438 20 20 import java.util.Set; 21 21 import java.util.TreeSet; 22 import java.util.stream.Collectors; 22 23 23 24 import javax.swing.JOptionPane; … … 447 448 448 449 for (Entry<String, String> entry : values.entrySet()) { 449 List<OsmPrimitive> affectedWays = new ArrayList<>();450 450 String key = entry.getKey(); 451 451 String value = entry.getValue(); 452 453 for (Way way : innerWays) { 454 if (value.equals(way.get(key))) { 455 affectedWays.add(way); 456 } 457 } 452 List<OsmPrimitive> affectedWays = innerWays.stream().filter(way -> value.equals(way.get(key))).collect(Collectors.toList()); 458 453 459 454 if (moveTags) { -
trunk/src/org/openstreetmap/josm/actions/DistributeAction.java
r14397 r16438 115 115 return false; 116 116 } 117 for (Node node: nodes) { 118 if (!w.containsNode(node)) { 119 return false; 120 } 121 } 122 return true; 117 return nodes.stream().allMatch(w::containsNode); 123 118 } 124 119 return false; -
trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r15716 r16438 14 14 import java.util.ServiceConfigurationError; 15 15 import java.util.function.Predicate; 16 import java.util.stream.Collectors; 16 17 17 18 import javax.swing.filechooser.FileFilter; … … 248 249 public static List<ExtensionFileFilter> getImportExtensionFileFilters() { 249 250 updateAllFormatsImporter(); 250 List<ExtensionFileFilter> filters = new LinkedList<>(); 251 for (FileImporter importer : importers) { 252 filters.add(importer.filter); 253 } 254 sort(filters); 255 return filters; 251 return importers.stream() 252 .map(importer -> importer.filter) 253 .sorted() 254 .collect(Collectors.toList()); 256 255 } 257 256 … … 326 325 public static void applyChoosableImportFileFilters( 327 326 AbstractFileChooser fileChooser, String extension, Predicate<ExtensionFileFilter> additionalTypes) { 328 for (ExtensionFileFilter filter: getImportExtensionFileFilters()) { 329 330 if (additionalTypes.test(filter) || filter.acceptName("file."+extension)) { 331 fileChooser.addChoosableFileFilter(filter); 332 } 333 } 327 getImportExtensionFileFilters().stream() 328 .filter(filter -> additionalTypes.test(filter) || filter.acceptName("file."+extension)) 329 .forEach(fileChooser::addChoosableFileFilter); 334 330 fileChooser.setFileFilter(getDefaultImportExtensionFileFilter(extension)); 335 331 } -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r15872 r16438 368 368 @Override 369 369 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 370 boolean ok = OsmUtils.isOsmCollectionEditable(selection); 371 if (ok) { 372 for (OsmPrimitive osm : selection) { 373 if (!(osm instanceof Node)) { 374 ok = false; 375 break; 376 } 377 } 378 } 379 setEnabled(ok); 370 setEnabled(OsmUtils.isOsmCollectionEditable(selection) && selection.stream().allMatch(osm -> osm instanceof Node)); 380 371 } 381 372 } -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r14397 r16438 9 9 import java.util.Collection; 10 10 import java.util.HashSet; 11 import java.util.LinkedList;12 11 import java.util.Set; 13 12 … … 23 22 import org.openstreetmap.josm.gui.Notification; 24 23 import org.openstreetmap.josm.tools.Shortcut; 24 import org.openstreetmap.josm.tools.StreamUtils; 25 25 26 26 /** … … 74 74 double middle = (minEast + maxEast) / 2; 75 75 76 Collection<Command> cmds = new LinkedList<>(); 77 78 for (Node n : nodes) { 79 cmds.add(new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0)); 80 } 81 76 Collection<Command> cmds = nodes.stream() 77 .map(n -> new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0)) 78 .collect(StreamUtils.toUnmodifiableList()); 82 79 UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Mirror"), cmds)); 83 80 } -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r16175 r16438 19 19 import java.util.Set; 20 20 import java.util.stream.Collectors; 21 import java.util.stream.IntStream; 21 22 22 23 import javax.swing.JOptionPane; … … 508 509 */ 509 510 public void calcDirections(Direction pInitialDirection) throws InvalidUserInputException { 510 final EastNorth[] en = new EastNorth[nNode]; // alias: wayNodes.get(i).getEastNorth() ---> en[i] 511 for (int i = 0; i < nNode; i++) { 512 en[i] = wayNodes.get(i).getEastNorth(); 513 } 511 // alias: wayNodes.get(i).getEastNorth() ---> en[i] 512 final EastNorth[] en = IntStream.range(0, nNode).mapToObj(i -> wayNodes.get(i).getEastNorth()).toArray(EastNorth[]::new); 514 513 Direction direction = pInitialDirection; 515 514 segDirections[0] = direction; -
trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequences.java
r14654 r16438 4 4 import java.util.Collection; 5 5 import java.util.LinkedList; 6 import java.util.Objects; 6 7 import java.util.Set; 7 8 import java.util.TreeSet; … … 120 121 */ 121 122 private Way findWay(Collection<OsmPrimitive> selection) { 122 for (Node node : outerNodes) { 123 Way way = findWay(selection, node); 124 if (way != null) 125 return way; 126 } 123 return outerNodes.stream() 124 .map(node -> findWay(selection, node)) 125 .filter(Objects::nonNull) 126 .findFirst().orElse(null); 127 127 128 return null;129 128 } 130 129 -
trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java
r14657 r16438 19 19 import java.util.Map; 20 20 import java.util.Set; 21 import java.util.stream.Collectors; 21 22 22 23 import javax.swing.BorderFactory; … … 108 109 } 109 110 110 boolean zipRequired = false; 111 for (Layer l : layers) { 112 SessionLayerExporter ex = exporters.get(l); 113 if (ex != null && ex.requiresZip()) { 114 zipRequired = true; 115 break; 116 } 117 } 111 boolean zipRequired = layers.stream().map(l -> exporters.get(l)) 112 .anyMatch(ex -> ex != null && ex.requiresZip()); 118 113 119 114 FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)")); … … 156 151 } 157 152 158 List<Layer> layersOut = new ArrayList<>(); 159 for (Layer layer : layers) { 160 if (exporters.get(layer) == null || !exporters.get(layer).shallExport()) continue; 161 // TODO: resolve dependencies for layers excluded by the user 162 layersOut.add(layer); 163 } 153 // TODO: resolve dependencies for layers excluded by the user 154 List<Layer> layersOut = layers.stream() 155 .filter(layer -> exporters.get(layer) != null && exporters.get(layer).shallExport()) 156 .collect(Collectors.toList()); 164 157 165 158 int active = -1; -
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r16138 r16438 222 222 223 223 private static List<String> paramCleanup(Collection<String> params) { 224 List<String> result = new ArrayList<>(params.size()); 225 for (String param : params) { 226 result.add(paramCleanup(param)); 227 } 228 return result; 224 return params.stream() 225 .map(ShowStatusReportAction::paramCleanup) 226 .collect(Collectors.toList()); 229 227 } 230 228 … … 270 268 private static void appendCollection(StringBuilder text, String label, Collection<String> col) { 271 269 if (!col.isEmpty()) { 272 text.append(label).append(":\n"); 273 for (String o : col) { 274 text.append(paramCleanup(o)).append('\n'); 275 } 276 text.append('\n'); 270 text.append(col.stream().map(o -> paramCleanup(o) + '\n') 271 .collect(Collectors.joining("", label + ":\n", "\n"))); 277 272 } 278 273 } -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r16187 r16438 16 16 import java.util.LinkedList; 17 17 import java.util.List; 18 import java.util.Objects; 18 19 import java.util.Set; 19 20 import java.util.stream.Collectors; … … 49 50 import org.openstreetmap.josm.tools.ImageProvider; 50 51 import org.openstreetmap.josm.tools.Shortcut; 52 import org.openstreetmap.josm.tools.StreamUtils; 51 53 52 54 /** … … 231 233 */ 232 234 private static Set<Node> getMultiUseNodes(Way w) { 233 Set<Node> multipleUseNodes = new HashSet<>();234 235 Set<Node> allNodes = new HashSet<>(); 235 for (Node n : w.getNodes()) { 236 if (!allNodes.add(n)) 237 multipleUseNodes.add(n); 238 } 239 return multipleUseNodes; 236 return w.getNodes().stream() 237 .filter(n -> !allNodes.add(n)) 238 .collect(Collectors.toSet()); 240 239 } 241 240 … … 248 247 */ 249 248 public static void simplifyWays(List<Way> ways, double threshold) { 250 Collection<Command> allCommands = new LinkedList<>(); 251 for (Way way : ways) { 252 SequenceCommand simplifyCommand = createSimplifyCommand(way, threshold); 253 if (simplifyCommand == null) { 254 continue; 255 } 256 allCommands.add(simplifyCommand); 257 } 249 Collection<Command> allCommands = ways.stream() 250 .map(way -> createSimplifyCommand(way, threshold)) 251 .filter(Objects::nonNull) 252 .collect(StreamUtils.toUnmodifiableList()); 258 253 if (allCommands.isEmpty()) 259 254 return; -
trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
r15013 r16438 13 13 import java.util.LinkedList; 14 14 import java.util.List; 15 import java.util.stream.Collectors; 15 16 16 17 import javax.swing.JOptionPane; … … 116 117 private List<Node> cleanSelectedNodes(List<Way> selectedWays, 117 118 List<Node> selectedNodes) { 118 List<Node> resultingNodes = new LinkedList<>();119 119 120 120 // List of node referenced by a route 121 for (Node n: selectedNodes) { 122 if (n.isReferredByWays(1)) { 123 resultingNodes.add(n); 124 } 125 } 121 List<Node> resultingNodes = selectedNodes.stream() 122 .filter(n -> n.isReferredByWays(1)) 123 .collect(Collectors.toCollection(LinkedList::new)); 126 124 // If exactly one selected way, remove node not referencing par this way. 127 125 if (selectedWays.size() == 1) { 128 126 Way w = selectedWays.get(0); 129 for (Node n: new ArrayList<>(resultingNodes)) { 130 if (!w.containsNode(n)) { 131 resultingNodes.remove(n); 132 } 133 } 127 resultingNodes.removeIf(n -> !w.containsNode(n)); 134 128 } 135 129 // Warn if nodes were removed -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r15205 r16438 8 8 import java.awt.event.KeyEvent; 9 9 import java.awt.geom.Area; 10 import java.util.ArrayList;11 10 import java.util.List; 12 11 import java.util.concurrent.Future; 12 import java.util.stream.Collectors; 13 13 14 14 import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList; 15 import org.openstreetmap.josm.data.DataSource;16 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 16 import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor; … … 58 57 return; 59 58 60 List<Area> areas = new ArrayList<>(); 61 for (DataSource ds : editLayer.data.getDataSources()) { 62 areas.add(new Area(ds.bounds.asRect())); 63 } 59 List<Area> areas = editLayer.data.getDataSources().stream() 60 .map(ds -> new Area(ds.bounds.asRect())) 61 .collect(Collectors.toList()); 64 62 65 63 // The next two blocks removes every intersection from every DataSource Area … … 78 76 } 79 77 80 List<Area> areasToDownload = new ArrayList<>(); 81 for (Area a : areas) { 82 if (a.isEmpty()) { 83 continue; 84 } 85 areasToDownload.add(a); 86 } 78 List<Area> areasToDownload = areas.stream() 79 .filter(a -> !a.isEmpty()) 80 .collect(Collectors.toList()); 87 81 88 82 if (areasToDownload.isEmpty()) { -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r15513 r16438 216 216 // 217 217 if (apiData != null) { 218 for (UploadHook hook : UPLOAD_HOOKS) { 219 if (!hook.checkUpload(apiData)) 220 return false; 221 } 218 return UPLOAD_HOOKS.stream().allMatch(hook -> hook.checkUpload(apiData)); 222 219 } 223 220 -
trunk/src/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrector.java
r14256 r16438 5 5 6 6 import java.util.ArrayList; 7 import java.util.Arrays; 7 8 import java.util.Collection; 8 9 import java.util.HashMap; … … 70 71 71 72 static IStringSwitcher combined(IStringSwitcher... switchers) { 72 return key -> { 73 for (IStringSwitcher switcher : switchers) { 74 final String newKey = switcher.apply(key); 75 if (!key.equals(newKey)) { 76 return newKey; 77 } 78 } 79 return key; 80 }; 73 return key -> Arrays.stream(switchers) 74 .map(switcher -> switcher.apply(key)) 75 .filter(newKey -> !key.equals(newKey)) 76 .findFirst().orElse(key); 81 77 } 82 78 } … … 302 298 303 299 private static boolean ignoreKeyForCorrection(String key) { 304 for (Pattern ignoredKey : IGNORED_KEYS) { 305 if (ignoredKey.matcher(key).matches()) { 306 return true; 307 } 308 } 309 return false; 300 return IGNORED_KEYS.stream() 301 .anyMatch(ignoredKey -> ignoredKey.matcher(key).matches()); 310 302 } 311 303 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r15784 r16438 179 179 if (active instanceof GpxLayer && (merge || ((GpxLayer) active).data.fromServer)) 180 180 return (GpxLayer) active; 181 for (GpxLayer l : MainApplication.getLayerManager().getLayersOfType(GpxLayer.class)) { 182 if (merge || l.data.fromServer) 183 return l; 184 } 185 return null; 181 return MainApplication.getLayerManager().getLayersOfType(GpxLayer.class).stream() 182 .filter(l -> merge || l.data.fromServer) 183 .findFirst().orElse(null); 186 184 } 187 185 188 186 private MarkerLayer findMarkerMergeLayer(GpxLayer fromLayer) { 189 for (MarkerLayer l : MainApplication.getLayerManager().getLayersOfType(MarkerLayer.class)) { 190 if (fromLayer != null && l.fromLayer == fromLayer) 191 return l; 192 } 193 return null; 187 return MainApplication.getLayerManager().getLayersOfType(MarkerLayer.class).stream() 188 .filter(l -> fromLayer != null && l.fromLayer == fromLayer) 189 .findFirst().orElse(null); 194 190 } 195 191 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r16123 r16438 16 16 17 17 import org.openstreetmap.josm.data.Bounds; 18 import org.openstreetmap.josm.data.osm.AbstractPrimitive; 18 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.data.osm.Node; … … 114 115 for (OsmPrimitive p : downloadedData.allNonDeletedPrimitives()) { 115 116 if (p.isIncomplete()) { 116 Date timestamp = null; 117 for (OsmPrimitive ref : p.getReferrers()) { 118 if (!ref.isTimestampEmpty()) { 119 timestamp = ref.getTimestamp(); 120 break; 121 } 122 } 117 Date timestamp = p.getReferrers().stream() 118 .filter(ref -> !ref.isTimestampEmpty()) 119 .map(AbstractPrimitive::getTimestamp) 120 .findFirst().orElse(null); 123 121 toLoad.put(p, timestamp); 124 122 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java
r15586 r16438 151 151 */ 152 152 protected void updatePotentiallyDeletedPrimitives(Set<OsmPrimitive> potentiallyDeleted) { 153 final List<OsmPrimitive> toSelect = new ArrayList<>(); 154 for (OsmPrimitive primitive : potentiallyDeleted) { 155 if (primitive != null) { 156 toSelect.add(primitive); 157 } 158 } 153 final List<OsmPrimitive> toSelect = potentiallyDeleted.stream().filter(Objects::nonNull).collect(Collectors.toList()); 159 154 EventQueue.invokeLater(() -> UpdateSelectionAction.updatePrimitives(toSelect)); 160 155 } … … 279 274 // FIXME: this is a hack. We assume that the user canceled the whole download if at 280 275 // least one task was canceled or if it failed 281 // 282 for (DownloadTask task : tasks) { 283 if (task instanceof AbstractDownloadTask) { 284 AbstractDownloadTask<?> absTask = (AbstractDownloadTask<?>) task; 285 if (absTask.isCanceled() || absTask.isFailed()) 286 return; 287 } 276 if (Utils.filteredCollection(tasks, AbstractDownloadTask.class).stream() 277 .anyMatch(absTask -> absTask.isCanceled() || absTask.isFailed())) { 278 return; 288 279 } 289 280 final DataSet editDataSet = MainApplication.getLayerManager().getEditDataSet(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r16187 r16438 604 604 // Don't allow creation of self-overlapping ways 605 605 if (way != null) { 606 int nodeCount = 0; 607 for (Node p : way.getNodes()) { 608 if (p.equals(n0)) { 609 nodeCount++; 610 } 611 } 606 long nodeCount = way.getNodes().stream().filter(p -> p.equals(n0)).count(); 612 607 if (nodeCount > 1) { 613 608 way = null; … … 1320 1315 if (ds != null && !ds.getSelectedWays().isEmpty() && !wayIsFinished && !alt) { 1321 1316 Way w = ds.getSelectedWays().iterator().next(); 1322 for (Node m : w.getNodes()) { 1323 if (m.equals(mouseOnExistingNode) || mouseOnExistingWays.contains(w)) { 1324 rv.append(' ').append(tr("Finish drawing.")); 1325 break; 1326 } 1317 if (w.getNodes().stream().anyMatch(m -> m.equals(mouseOnExistingNode) || mouseOnExistingWays.contains(w))) { 1318 rv.append(' ').append(tr("Finish drawing.")); 1327 1319 } 1328 1320 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r15657 r16438 736 736 */ 737 737 private static boolean hasNodeOtherWays(Node node, Way myWay) { 738 for (OsmPrimitive p : node.getReferrers()) { 739 if (p instanceof Way && p.isUsable() && p != myWay) 740 return true; 741 } 742 return false; 738 return node.getReferrers().stream() 739 .anyMatch(p -> p instanceof Way && p.isUsable() && p != myWay); 743 740 } 744 741 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyHelper.java
r12630 r16438 3 3 4 4 import java.awt.Point; 5 import java.util.Collection;6 5 import java.util.List; 6 import java.util.Optional; 7 7 8 8 import org.openstreetmap.josm.data.coor.EastNorth; … … 42 42 43 43 Node node = mv.getNearestNode(p, OsmPrimitive::isSelectable); 44 Way candidate = null;45 44 46 45 if (node != null) { 47 final Collection<OsmPrimitive> candidates = node.getReferrers(); 48 for (OsmPrimitive refferer : candidates) { 49 if (refferer instanceof Way) { 50 candidate = (Way) refferer; 51 break; 52 } 53 } 54 if (candidate != null) { 55 return candidate; 46 Optional<Way> candidate = node.referrers(Way.class).findFirst(); 47 if (candidate.isPresent()) { 48 return candidate.get(); 56 49 } 57 50 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java
r15906 r16438 10 10 import java.util.Map; 11 11 import java.util.Set; 12 import java.util.stream.IntStream; 12 13 13 14 import org.openstreetmap.josm.command.AddCommand; … … 93 94 // Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way 94 95 Way refWay = ways.get(refWayIndex); 95 boolean refWayReversed = true; 96 for (int i = 0; i < sortedNodes.size() - 1; i++) { 97 if (sortedNodes.get(i) == refWay.firstNode() && sortedNodes.get(i + 1) == refWay.getNode(1)) { 98 refWayReversed = false; 99 break; 100 } 101 } 96 boolean refWayReversed = IntStream.range(0, sortedNodes.size() - 1) 97 .noneMatch(i -> sortedNodes.get(i) == refWay.firstNode() && sortedNodes.get(i + 1) == refWay.getNode(1)); 102 98 if (refWayReversed) { 103 99 Collections.reverse(sortedNodes); // need to keep the orientation of the reference way. -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r16187 r16438 772 772 773 773 private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays) { 774 for (Way w : selectedWays) { 775 for (Node n : w.getNodes()) { 776 if (affectedNodes.contains(n)) { 777 return true; 778 } 779 } 780 } 781 return false; 774 return selectedWays.stream() 775 .flatMap(w -> w.getNodes().stream()) 776 .anyMatch(affectedNodes::contains); 782 777 } 783 778 -
trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java
r14134 r16438 7 7 import java.awt.event.ActionEvent; 8 8 import java.util.Collection; 9 import java.util. LinkedList;9 import java.util.Objects; 10 10 11 11 import javax.swing.JOptionPane; … … 24 24 import org.openstreetmap.josm.gui.util.GuiHelper; 25 25 import org.openstreetmap.josm.tools.ImageProvider; 26 import org.openstreetmap.josm.tools.StreamUtils; 26 27 import org.openstreetmap.josm.tools.Utils; 27 28 … … 41 42 @Override 42 43 public void actionPerformed(ActionEvent e) { 43 Collection<Command> cmds = new LinkedList<>(); 44 for (Relation orig : Utils.filteredCollection(relations, Relation.class)) { 45 Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getActiveDataSet().getSelected()); 46 if (c != null) { 47 cmds.add(c); 48 } 49 } 44 Collection<Command> cmds = Utils.filteredCollection(relations, Relation.class).stream() 45 .map(orig -> GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getActiveDataSet().getSelected())) 46 .filter(Objects::nonNull) 47 .collect(StreamUtils.toUnmodifiableList()); 50 48 if (!cmds.isEmpty()) { 51 49 UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Add selection to relation"), cmds)); -
trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
r14471 r16438 75 75 if (recentRelations == null || recentRelations.isEmpty()) 76 76 return null; 77 for (Relation relation: recentRelations) { 78 if (!isRelationListable(relation)) 79 continue; 80 return relation; 81 } 82 return null; 77 return recentRelations.stream().filter(RecentRelationsAction::isRelationListable) 78 .findFirst().orElse(null); 83 79 } 84 80 -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r15586 r16438 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.KeyEvent; 12 import java.util.ArrayList;13 12 import java.util.Arrays; 14 13 import java.util.Collection; 15 14 import java.util.Collections; 16 15 import java.util.HashSet; 17 import java.util.LinkedHashSet;18 16 import java.util.LinkedList; 19 17 import java.util.List; 20 18 import java.util.Map; 21 import java.util.Set;22 19 import java.util.function.Predicate; 20 import java.util.stream.Collectors; 23 21 24 22 import javax.swing.JOptionPane; … … 122 120 searchHistory.removeLast(); 123 121 } 124 Set<String> savedHistory = new LinkedHashSet<>(searchHistory.size());125 for (SearchSetting item: searchHistory) {126 savedHistory.add(item.writeToString());127 }128 Config.getPref().putList("search.history", new ArrayList<>(savedHistory));122 List<String> savedHistory = searchHistory.stream() 123 .map(SearchSetting::writeToString) 124 .distinct() 125 .collect(Collectors.toList()); 126 Config.getPref().putList("search.history", savedHistory); 129 127 } 130 128 … … 134 132 */ 135 133 public static List<String> getSearchExpressionHistory() { 136 List<String> ret = new ArrayList<>(getSearchHistory().size()); 137 for (SearchSetting ss: getSearchHistory()) { 138 ret.add(ss.text); 139 } 140 return ret; 134 return getSearchHistory().stream() 135 .map(ss -> ss.text) 136 .collect(Collectors.toList()); 141 137 } 142 138 -
trunk/src/org/openstreetmap/josm/actions/upload/DiscardTagsHook.java
r14134 r16438 27 27 Collection<String> discardableKeys = new HashSet<>(AbstractPrimitive.getDiscardableKeys()); 28 28 29 boolean needsChange = false; 30 OUTER: for (OsmPrimitive osm : objectsToUpload) { 31 for (String key : osm.keySet()) { 32 if (discardableKeys.contains(key)) { 33 needsChange = true; 34 break OUTER; 35 } 36 } 37 } 29 boolean needsChange = objectsToUpload.stream().flatMap(osm -> osm.keySet().stream()) 30 .anyMatch(discardableKeys::contains); 38 31 39 32 if (needsChange) { -
trunk/src/org/openstreetmap/josm/actions/upload/UploadNotesTask.java
r14170 r16438 7 7 import java.util.HashMap; 8 8 import java.util.Map; 9 import java.util.stream.Collectors; 9 10 10 11 import javax.swing.JOptionPane; … … 124 125 noteData.updateNotes(updatedNotes); 125 126 if (!failedNotes.isEmpty()) { 126 StringBuilder sb = new StringBuilder(); 127 for (Map.Entry<Note, Exception> entry : failedNotes.entrySet()) { 128 sb.append(tr("Note {0} failed: {1}", entry.getKey().getId(), entry.getValue().getMessage())) 129 .append('\n'); 130 } 131 Logging.error("Notes failed to upload: " + sb.toString()); 132 JOptionPane.showMessageDialog(MainApplication.getMap(), sb.toString(), 127 String message = failedNotes.entrySet().stream() 128 .map(entry -> tr("Note {0} failed: {1}", entry.getKey().getId(), entry.getValue().getMessage())) 129 .collect(Collectors.joining("\n")); 130 Logging.error("Notes failed to upload: " + message); 131 JOptionPane.showMessageDialog(MainApplication.getMap(), message, 133 132 tr("Notes failed to upload"), JOptionPane.ERROR_MESSAGE); 134 133 ExceptionDialogUtil.explainException(failedNotes.values().iterator().next()); -
trunk/src/org/openstreetmap/josm/data/coor/conversion/ICoordinateFormat.java
r12735 r16438 35 35 */ 36 36 String lonToString(ILatLon ll); 37 38 /** 39 * Convert the coordinate to string: latitude + separator + longitude 40 * @param ll the coordinate 41 * @param separator the separator 42 * @return formatted coordinate 43 */ 44 default String toString(ILatLon ll, String separator) { 45 return latToString(ll) + separator + lonToString(ll); 46 } 37 47 } -
trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java
r14680 r16438 212 212 } 213 213 if (node.isLatLonKnown() && Config.getPref().getBoolean("osm-primitives.showcoor")) { 214 name.append(" \u200E(") 215 .append(CoordinateFormatManager.getDefaultFormat().latToString(node)).append(", ")216 .append(CoordinateFormatManager.getDefaultFormat().lonToString(node)).append(')');214 name.append(" \u200E("); 215 name.append(CoordinateFormatManager.getDefaultFormat().toString(node, ", ")); 216 name.append(')'); 217 217 } 218 218 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r16430 r16438 1359 1359 boolean condition = !networkErrors.isEmpty(); 1360 1360 if (condition) { 1361 Set<String> errors = new TreeSet<>(); 1362 for (Throwable t : networkErrors.values()) { 1363 errors.add(t.toString()); 1364 } 1361 Set<String> errors = networkErrors.values().stream() 1362 .map(Throwable::toString) 1363 .collect(Collectors.toCollection(TreeSet::new)); 1365 1364 return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"), 1366 1365 tr("JOSM tried to access the following resources:<br>" + -
trunk/src/org/openstreetmap/josm/gui/MainFrame.java
r15725 r16438 14 14 import java.awt.event.WindowEvent; 15 15 import java.beans.PropertyChangeListener; 16 import java.util.LinkedList;17 16 import java.util.List; 17 import java.util.Objects; 18 import java.util.stream.Collectors; 19 import java.util.stream.Stream; 18 20 19 21 import javax.swing.ImageIcon; … … 83 85 setJMenuBar(menu); 84 86 geometry.applySafe(this); 85 List<Image> l = new LinkedList<>(); 86 for (String file : new String[] { 87 List<Image> l = Stream.of( 87 88 /* ICON */ "logo_16x16x32", 88 89 /* ICON */ "logo_16x16x8", … … 91 92 /* ICON */ "logo_48x48x32", 92 93 /* ICON */ "logo_48x48x8", 93 /* ICON */ "logo"}) { 94 ImageIcon img = ImageProvider.getIfAvailable(file); 95 if (img != null) { 96 l.add(img.getImage()); 97 } 98 } 94 /* ICON */ "logo") 95 .map(ImageProvider::getIfAvailable) 96 .filter(Objects::nonNull) 97 .map(ImageIcon::getImage) 98 .collect(Collectors.toList()); 99 99 setIconImages(l); 100 100 addWindowListener(new ExitWindowAdapter()); -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r16132 r16438 14 14 import java.awt.event.KeyEvent; 15 15 import java.util.ArrayList; 16 import java.util.Arrays; 16 17 import java.util.Collection; 17 18 import java.util.HashMap; … … 720 721 * 721 722 */ 722 public <T > T getToggleDialog(Class<T> type) {723 public <T extends ToggleDialog> T getToggleDialog(Class<T> type) { 723 724 return dialogsPanel.getToggleDialog(type); 724 725 } … … 767 768 */ 768 769 public <T> T getTopPanel(Class<T> type) { 769 int n = leftPanel.getComponentCount(); 770 for (int i = 0; i < n; i++) { 771 Component c = leftPanel.getComponent(i); 772 if (type.isInstance(c)) 773 return type.cast(c); 774 } 775 return null; 770 return Arrays.stream(leftPanel.getComponents()) 771 .filter(type::isInstance) 772 .findFirst().map(type::cast).orElse(null); 776 773 } 777 774 -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r15185 r16438 1110 1110 int maxWays = Math.max(1, Config.getPref().getInt("selection.max-ways-for-statusline", 250)); 1111 1111 if (!ways.isEmpty() && ways.size() <= maxWays) { 1112 dist = 0.0; 1113 for (Way w : ways) { 1114 dist += w.getLength(); 1115 } 1112 dist = ways.stream().mapToDouble(Way::getLength).sum(); 1116 1113 } 1117 1114 setDist(dist); -
trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
r14173 r16438 306 306 if (menuItems != null && menuItems.length > 0) { 307 307 308 int allItemsHeight = 0; 309 for (Component item : menuItems) { 310 allItemsHeight += item.getPreferredSize().height; 311 } 312 308 int allItemsHeight = Arrays.stream(menuItems).mapToInt(item -> item.getPreferredSize().height).sum(); 313 309 int allowedHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - MainApplication.getMainFrame().getInsets().top; 314 315 boolean mustSCroll = allItemsHeight > allowedHeight; 316 317 if (mustSCroll) { 310 boolean mustScroll = allItemsHeight > allowedHeight; 311 if (mustScroll) { 318 312 firstIndex = Math.min(menuItems.length-1, Math.max(topFixedCount, firstIndex)); 319 313 int scrollCount = computeScrollCount(firstIndex); -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r15767 r16438 27 27 import java.util.concurrent.CopyOnWriteArrayList; 28 28 import java.util.function.Predicate; 29 import java.util.stream.Collectors; 29 30 import java.util.zip.CRC32; 30 31 … … 1138 1139 if (ntref == null && preferredRefs != null && Utils.equalsEpsilon(distSq, minDistSq)) { 1139 1140 List<OsmPrimitive> ndRefs = nd.getReferrers(); 1140 for (OsmPrimitive ref: preferredRefs) { 1141 if (ndRefs.contains(ref)) { 1142 ntref = nd; 1143 break; 1144 } 1141 if (preferredRefs.stream().anyMatch(ndRefs::contains)) { 1142 ntref = nd; 1145 1143 } 1146 1144 } … … 1386 1384 public final List<Way> getNearestWays(Point p, 1387 1385 Collection<Way> ignore, Predicate<OsmPrimitive> predicate) { 1388 List<Way> nearestList = new ArrayList<>();1389 1386 Set<Way> wset = new HashSet<>(); 1390 1387 1391 for (List<WaySegment> wss : getNearestWaySegmentsImpl(p, predicate).values()) { 1392 for (WaySegment ws : wss) { 1393 if (wset.add(ws.way)) { 1394 nearestList.add(ws.way); 1395 } 1396 } 1397 } 1388 List<Way> nearestList = getNearestWaySegmentsImpl(p, predicate).values().stream() 1389 .flatMap(Collection::stream) 1390 .filter(ws -> wset.add(ws.way)) 1391 .map(ws -> ws.way) 1392 .collect(Collectors.toList()); 1398 1393 if (ignore != null) { 1399 1394 nearestList.removeAll(ignore); … … 1599 1594 public final List<OsmPrimitive> getAllNearest(Point p, 1600 1595 Collection<OsmPrimitive> ignore, Predicate<OsmPrimitive> predicate) { 1601 List<OsmPrimitive> nearestList = new ArrayList<>();1602 1596 Set<Way> wset = new HashSet<>(); 1603 1597 1604 1598 // add nearby ways 1605 for (List<WaySegment> wss : getNearestWaySegmentsImpl(p, predicate).values()) { 1606 for (WaySegment ws : wss) { 1607 if (wset.add(ws.way)) { 1608 nearestList.add(ws.way); 1609 } 1610 } 1611 } 1599 List<OsmPrimitive> nearestList = getNearestWaySegmentsImpl(p, predicate).values().stream() 1600 .flatMap(Collection::stream) 1601 .filter(ws -> wset.add(ws.way)) 1602 .map(ws -> ws.way) 1603 .collect(Collectors.toList()); 1612 1604 1613 1605 // add nearby nodes 1614 for (List<Node> nlist : getNearestNodesImpl(p, predicate).values()) { 1615 nearestList.addAll(nlist); 1616 } 1606 getNearestNodesImpl(p, predicate).values() 1607 .forEach(nearestList::addAll); 1617 1608 1618 1609 // add parent relations of nearby nodes and ways 1619 Set<OsmPrimitive> parentRelations = new HashSet<>(); 1620 for (OsmPrimitive o : nearestList) { 1621 for (OsmPrimitive r : o.getReferrers()) { 1622 if (r instanceof Relation && predicate.test(r)) { 1623 parentRelations.add(r); 1624 } 1625 } 1626 } 1627 nearestList.addAll(parentRelations); 1610 nearestList.stream() 1611 .flatMap(o -> o.getReferrers().stream()) 1612 .filter(r -> r instanceof Relation && predicate.test(r)) 1613 .forEach(nearestList::add); 1628 1614 1629 1615 if (ignore != null) { -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r16252 r16438 395 395 } 396 396 if (alt) { 397 for (Node n : w.getNodes()) { 398 if (!n.isIncomplete() && selectionResult.contains(nc.getPoint2D(n))) { 399 selection.add(w); 400 break; 401 } 397 if (w.getNodes().stream().anyMatch(n -> !n.isIncomplete() && selectionResult.contains(nc.getPoint2D(n)))) { 398 selection.add(w); 402 399 } 403 400 } else { 404 boolean allIn = true; 405 for (Node n : w.getNodes()) { 406 if (!n.isIncomplete() && !selectionResult.contains(nc.getPoint(n))) { 407 allIn = false; 408 break; 409 } 410 } 401 boolean allIn = w.getNodes().stream().allMatch(n -> n.isIncomplete() || selectionResult.contains(nc.getPoint(n))); 411 402 if (allIn) { 412 403 selection.add(w); -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/ComparePairType.java
r14214 r16438 5 5 import static org.openstreetmap.josm.gui.conflict.pair.ListRole.THEIR_ENTRIES; 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 8 import java.util.Arrays; 7 9 8 10 import org.openstreetmap.josm.tools.Utils; … … 54 56 */ 55 57 public boolean isParticipatingIn(ListRole role) { 56 for (ListRole r: participatingRoles) { 57 if (r == role) return true; 58 } 59 return false; 58 return Arrays.stream(participatingRoles).anyMatch(r -> r == role); 60 59 } 61 60 -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java
r13130 r16438 8 8 import java.util.Arrays; 9 9 import java.util.List; 10 import java.util.stream.Collectors; 10 11 11 12 import javax.swing.AbstractAction; … … 108 109 if (referrers.isEmpty()) 109 110 return tr("(none)"); 110 StringBuilder str = new StringBuilder("<html>"); 111 for (OsmPrimitive r: referrers) { 112 str.append(Utils.escapeReservedCharactersHTML(r.getDisplayName(DefaultNameFormatter.getInstance()))).append("<br>"); 113 } 114 str.append("</html>"); 115 return str.toString(); 111 return referrers.stream() 112 .map(r -> Utils.escapeReservedCharactersHTML(r.getDisplayName(DefaultNameFormatter.getInstance())) + "<br>") 113 .collect(Collectors.joining("", "<html>", "</html>")); 116 114 } 117 115 -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMergeModel.java
r14214 r16438 8 8 import java.util.List; 9 9 import java.util.Set; 10 import java.util.stream.IntStream; 10 11 11 12 import javax.swing.table.DefaultTableModel; … … 85 86 */ 86 87 protected void refreshNumUndecidedTags() { 87 int newValue = 0;88 for (TagMergeItem item: tagMergeItems) {89 if (MergeDecisionType.UNDECIDED == item.getMergeDecision()) {90 newValue++;91 }92 }93 88 int oldValue = numUndecidedTags; 94 numUndecidedTags = newValue;89 numUndecidedTags = getNumUnresolvedConflicts(); 95 90 fireNumUndecidedTagsChanged(oldValue, numUndecidedTags); 96 91 } … … 194 189 195 190 public boolean isResolvedCompletely() { 196 for (TagMergeItem item: tagMergeItems) { 197 if (item.getMergeDecision() == MergeDecisionType.UNDECIDED) 198 return false; 199 } 200 return true; 191 return tagMergeItems.stream() 192 .noneMatch(item -> item.getMergeDecision() == MergeDecisionType.UNDECIDED); 201 193 } 202 194 … … 209 201 210 202 public int getNumResolvedConflicts() { 211 int n = 0; 212 for (TagMergeItem item: tagMergeItems) { 213 if (item.getMergeDecision() != MergeDecisionType.UNDECIDED) { 214 n++; 215 } 216 } 217 return n; 218 203 return (int) tagMergeItems.stream() 204 .filter(item -> item.getMergeDecision() != MergeDecisionType.UNDECIDED) 205 .count(); 206 } 207 208 public int getNumUnresolvedConflicts() { 209 return (int) tagMergeItems.stream() 210 .filter(item -> item.getMergeDecision() == MergeDecisionType.UNDECIDED) 211 .count(); 219 212 } 220 213 221 214 public int getFirstUndecided(int startIndex) { 222 for (int i = startIndex; i < tagMergeItems.size(); i++) { 223 if (tagMergeItems.get(i).getMergeDecision() == MergeDecisionType.UNDECIDED) 224 return i; 225 } 226 return -1; 215 return IntStream.range(startIndex, tagMergeItems.size()) 216 .filter(i -> tagMergeItems.get(i).getMergeDecision() == MergeDecisionType.UNDECIDED) 217 .findFirst().orElse(-1); 227 218 } 228 219 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/MultiValueResolutionDecision.java
r15586 r16438 6 6 import java.text.MessageFormat; 7 7 import java.util.ArrayList; 8 import java.util.Arrays; 8 9 import java.util.Collection; 9 10 import java.util.Collections; … … 199 200 */ 200 201 public boolean canSumAllNumeric() { 201 if (!canKeepAll()) { 202 return false; 203 } 204 for (String key : SUMMABLE_KEYS) { 205 if (getKey().matches(key)) { 206 return true; 207 } 208 } 209 return false; 202 return canKeepAll() && Arrays.stream(SUMMABLE_KEYS).anyMatch(key -> getKey().matches(key)); 210 203 } 211 204 -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/PasteTagsConflictResolverDialog.java
r15586 r16438 22 22 import java.util.Map; 23 23 import java.util.Map.Entry; 24 import java.util.StringJoiner; 25 import java.util.stream.IntStream; 24 26 25 27 import javax.swing.AbstractAction; … … 251 253 } 252 254 253 for (int i = 0; i < getNumResolverTabs(); i++) { 254 if (!getResolver(i).getModel().isResolvedCompletely()) { 255 tpResolvers.setSelectedIndex(i); 256 break; 257 } 258 } 255 IntStream.range(0, getNumResolverTabs()) 256 .filter(i -> !getResolver(i).getModel().isResolvedCompletely()) 257 .findFirst() 258 .ifPresent(tpResolvers::setSelectedIndex); 259 259 } 260 260 … … 421 421 setIcon(ImageProvider.get("data", "object")); 422 422 } 423 String Builder text = new StringBuilder();423 StringJoiner text = new StringJoiner(", "); 424 424 for (Entry<OsmPrimitiveType, Integer> entry: stat.entrySet()) { 425 425 OsmPrimitiveType type = entry.getKey(); … … 435 435 default: throw new AssertionError(); 436 436 } 437 if (text.length() > 0) { 438 text.append(", "); 439 } 440 text.append(msg); 437 text.add(msg); 441 438 } 442 439 setText(text.toString()); -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
r15729 r16438 13 13 import java.util.List; 14 14 import java.util.Map; 15 import java.util.Objects; 15 16 import java.util.Set; 16 17 import java.util.TreeSet; 18 import java.util.stream.Collectors; 17 19 18 20 import javax.swing.table.DefaultTableModel; … … 70 72 */ 71 73 protected void updateNumConflicts() { 72 int count = 0;73 for (RelationMemberConflictDecision decision: decisions) {74 if (!decision.isDecided()) {75 count++;76 }77 }78 74 int oldValue = numConflicts; 79 numConflicts = count;75 numConflicts = (int) decisions.stream().filter(decision -> !decision.isDecided()).count(); 80 76 if (numConflicts != oldValue) { 81 77 support.firePropertyChange(getProperty(), oldValue, numConflicts); … … 235 231 void prepareDefaultRelationDecisions(boolean fireEvent) { 236 232 if (primitives.stream().allMatch(Node.class::isInstance)) { 237 final Collection<OsmPrimitive> primitivesInDecisions = new HashSet<>(); 238 for (final RelationMemberConflictDecision i : decisions) { 239 primitivesInDecisions.add(i.getOriginalPrimitive()); 240 } 233 final Collection<OsmPrimitive> primitivesInDecisions = decisions.stream() 234 .map(RelationMemberConflictDecision::getOriginalPrimitive) 235 .collect(Collectors.toSet()); 241 236 if (primitivesInDecisions.size() == 1) { 242 237 for (final RelationMemberConflictDecision i : decisions) { … … 264 259 // some primitives are not part of the relation, leave undecided 265 260 } else { 266 final Collection<Iterator<RelationMemberConflictDecision>> iterators = new ArrayList<>(primitives.size()); 267 for (final Collection<RelationMemberConflictDecision> i : decisionsByPrimitive.values()) { 268 iterators.add(i.iterator()); 269 } 261 final Collection<Iterator<RelationMemberConflictDecision>> iterators = decisionsByPrimitive.values().stream() 262 .map(List::iterator) 263 .collect(Collectors.toList()); 270 264 while (iterators.stream().allMatch(Iterator::hasNext)) { 271 265 final List<RelationMemberConflictDecision> decisions = new ArrayList<>(); … … 364 358 365 359 protected RelationMemberConflictDecision getDecision(Relation relation, int pos) { 366 for (RelationMemberConflictDecision decision: decisions) { 367 if (decision.matches(relation, pos)) return decision; 368 } 369 return null; 360 return decisions.stream() 361 .filter(decision -> decision.matches(relation, pos)) 362 .findFirst().orElse(null); 370 363 } 371 364 … … 408 401 */ 409 402 public List<Command> buildResolutionCommands(OsmPrimitive newPrimitive) { 410 List<Command> command = new LinkedList<>(); 411 for (Relation relation : relations) { 412 Command cmd = buildResolveCommand(relation, newPrimitive); 413 if (cmd != null) { 414 command.add(cmd); 415 } 416 } 417 return command; 403 return relations.stream() 404 .map(relation -> buildResolveCommand(relation, newPrimitive)) 405 .filter(Objects::nonNull) 406 .collect(Collectors.toList()); 418 407 } 419 408 … … 449 438 */ 450 439 public Set<Relation> getModifiedRelations(OsmPrimitive newPrimitive) { 451 Set<Relation> ret = new HashSet<>(); 452 for (Relation relation: relations) { 453 if (isChanged(relation, newPrimitive)) { 454 ret.add(relation); 455 } 456 } 457 return ret; 440 return relations.stream() 441 .filter(relation -> isChanged(relation, newPrimitive)) 442 .collect(Collectors.toSet()); 458 443 } 459 444 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtil.java
r13809 r16438 106 106 } 107 107 108 Collection<OsmPrimitive> taggedPrimitives = new ArrayList<>(); 109 for (OsmPrimitive p: merged) { 110 if (p.isTagged()) { 111 taggedPrimitives.add(p); 112 } 113 } 108 Collection<OsmPrimitive> taggedPrimitives = merged.stream() 109 .filter(OsmPrimitive::isTagged) 110 .collect(Collectors.toList()); 114 111 if (taggedPrimitives.size() <= 1) 115 112 return; -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java
r16333 r16438 95 95 keys.retainAll(keysWithConflicts); 96 96 if (showTagsWithMultiValuesOnly) { 97 Set<String> keysWithMultiValues = new HashSet<>(); 98 for (String key: keys) { 99 if (decisions.get(key).canKeepAll()) { 100 keysWithMultiValues.add(key); 101 } 102 } 103 keys.retainAll(keysWithMultiValues); 97 keys.removeIf(key -> !decisions.get(key).canKeepAll()); 104 98 } 105 99 for (String key: tags.getKeys()) { -
trunk/src/org/openstreetmap/josm/gui/datatransfer/RelationMemberTransferable.java
r15418 r16438 10 10 import java.util.Collection; 11 11 import java.util.Collections; 12 import java.util.HashSet;13 12 import java.util.stream.Collectors; 14 13 … … 95 94 96 95 private PrimitiveTransferData getPrimitiveData() { 97 Collection<OsmPrimitive> primitives = new HashSet<>(); 98 for (RelationMember member : members) { 99 primitives.add(member.getMember()); 100 } 96 Collection<OsmPrimitive> primitives = members.stream().map(RelationMember::getMember).collect(Collectors.toSet()); 101 97 return PrimitiveTransferData.getData(primitives); 102 98 } -
trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java
r14493 r16438 11 11 import java.util.List; 12 12 import java.util.Map; 13 import java.util.Objects; 14 import java.util.stream.Collectors; 13 15 14 16 import javax.swing.TransferHandler.TransferSupport; … … 126 128 127 129 private static void updateNodes(Map<Long, Long> newNodeIds, PrimitiveData data) { 128 List<Long> newNodes = new ArrayList<>(); 129 for (Long oldNodeId : ((WayData) data).getNodeIds()) { 130 Long newNodeId = newNodeIds.get(oldNodeId); 131 if (newNodeId != null) { 132 newNodes.add(newNodeId); 133 } 134 } 130 List<Long> newNodes = ((WayData) data).getNodeIds().stream() 131 .map(newNodeIds::get) 132 .filter(Objects::nonNull) 133 .collect(Collectors.toList()); 135 134 ((WayData) data).setNodeIds(newNodes); 136 135 } -
trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveTagTransferPaster.java
r15905 r16438 27 27 import org.openstreetmap.josm.gui.conflict.tags.PasteTagsConflictResolverDialog; 28 28 import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTagTransferData; 29 import org.openstreetmap.josm.tools.StreamUtils; 29 30 30 31 /** … … 50 51 51 52 TagPasteSupport tagPaster = new TagPasteSupport(data, selection); 52 List<Command> commands = new ArrayList<>(); 53 for (Tag tag : tagPaster.execute()) { 54 Map<String, String> tags = Collections.singletonMap(tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue()); 55 ChangePropertyCommand cmd = new ChangePropertyCommand(OsmDataManager.getInstance().getEditDataSet(), selection, tags); 56 if (cmd.getObjectsNumber() > 0) { 57 commands.add(cmd); 58 } 59 } 53 List<Command> commands = tagPaster.execute().stream() 54 .map(tag -> Collections.singletonMap(tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue())) 55 .map(tags -> new ChangePropertyCommand(OsmDataManager.getInstance().getEditDataSet(), selection, tags)) 56 .filter(cmd -> cmd.getObjectsNumber() > 0) 57 .collect(StreamUtils.toUnmodifiableList()); 60 58 commitCommands(selection, commands); 61 59 return true; … … 124 122 */ 125 123 protected boolean canPasteFromHeterogeneousSourceWithoutConflict() { 126 for (OsmPrimitiveType type : OsmPrimitiveType.dataValues()) { 127 if (hasTargetPrimitives(type)) { 128 TagCollection tc = data.getForPrimitives(type); 129 if (!tc.isEmpty() && !tc.isApplicableToPrimitive()) 130 return false; 131 } 132 } 133 return true; 124 return OsmPrimitiveType.dataValues().stream() 125 .filter(this::hasTargetPrimitives) 126 .map(data::getForPrimitives) 127 .allMatch(tc -> tc.isEmpty() || tc.isApplicableToPrimitive()); 134 128 } 135 129 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r15586 r16438 21 21 import java.util.Set; 22 22 import java.util.concurrent.CopyOnWriteArrayList; 23 import java.util.stream.IntStream; 23 24 24 25 import javax.swing.AbstractAction; … … 441 442 public synchronized int indexOf(OsmPrimitive my) { 442 443 if (conflicts != null) { 443 for (int i = 0; i < conflicts.size(); i++) { 444 if (conflicts.get(i).isMatchingMy(my)) 445 return i; 446 } 444 return IntStream.range(0, conflicts.size()) 445 .filter(i -> conflicts.get(i).isMatchingMy(my)) 446 .findFirst().orElse(-1); 447 447 } 448 448 return -1; -
trunk/src/org/openstreetmap/josm/gui/dialogs/DeleteFromRelationConfirmationDialog.java
r15231 r16438 16 16 import java.util.Collection; 17 17 import java.util.Comparator; 18 import java.util.HashSet;19 18 import java.util.List; 20 19 import java.util.Set; 20 import java.util.stream.Collectors; 21 21 22 22 import javax.swing.AbstractAction; … … 231 231 */ 232 232 public Set<OsmPrimitive> getObjectsToDelete() { 233 Set<OsmPrimitive> ret = new HashSet<>(); 234 for (RelationToChildReference ref: data) { 235 ret.add(ref.getChild()); 236 } 237 return ret; 233 return data.stream().map(RelationToChildReference::getChild).collect(Collectors.toSet()); 238 234 } 239 235 … … 251 247 */ 252 248 public Set<OsmPrimitive> getParentRelations() { 253 Set<OsmPrimitive> ret = new HashSet<>(); 254 for (RelationToChildReference ref: data) { 255 ret.add(ref.getParent()); 256 } 257 return ret; 249 return data.stream().map(RelationToChildReference::getParent).collect(Collectors.toSet()); 258 250 } 259 251 -
trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
r14766 r16438 18 18 import org.openstreetmap.josm.tools.Destroyable; 19 19 import org.openstreetmap.josm.tools.JosmRuntimeException; 20 import org.openstreetmap.josm.tools.Utils; 20 21 import org.openstreetmap.josm.tools.bugreport.BugReport; 21 22 … … 350 351 * 351 352 */ 352 public <T> T getToggleDialog(Class<T> type) { 353 for (ToggleDialog td : allDialogs) { 354 if (type.isInstance(td)) 355 return type.cast(td); 356 } 357 return null; 353 public <T extends ToggleDialog> T getToggleDialog(Class<T> type) { 354 return Utils.filteredCollection(allDialogs, type).stream() 355 .findFirst().orElse(null); 358 356 } 359 357 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/FilterDialog.java
r15477 r16438 9 9 import java.awt.event.KeyEvent; 10 10 import java.awt.event.MouseEvent; 11 import java.util.ArrayList;12 11 import java.util.Arrays; 13 12 import java.util.List; 14 13 import java.util.stream.Collectors; 14 import java.util.stream.IntStream; 15 15 16 16 import javax.swing.AbstractAction; … … 445 445 @Override 446 446 public List<MultikeyInfo> getMultikeyCombinations() { 447 List<MultikeyInfo> result = new ArrayList<>(); 448 449 for (int i = 0; i < filterModel.getRowCount(); i++) { 450 result.add(new MultikeyInfo(i, filterModel.getValue(i).text)); 451 } 452 453 return result; 447 return IntStream.range(0, filterModel.getRowCount()) 448 .mapToObj(i -> new MultikeyInfo(i, filterModel.getValue(i).text)) 449 .collect(Collectors.toList()); 454 450 } 455 451 -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r15929 r16438 23 23 import java.util.Locale; 24 24 import java.util.concurrent.CopyOnWriteArrayList; 25 import java.util.stream.Collectors; 26 import java.util.stream.IntStream; 25 27 26 28 import javax.swing.AbstractAction; … … 870 872 */ 871 873 public List<Layer> getSelectedLayers() { 872 List<Layer> selected = new ArrayList<>();873 874 List<Layer> layers = getLayers(); 874 for (int i = 0; i < layers.size(); i++) { 875 if (selectionModel.isSelectedIndex(i)) { 876 selected.add(layers.get(i)); 877 } 878 } 879 return selected; 875 return IntStream.range(0, layers.size()) 876 .filter(selectionModel::isSelectedIndex) 877 .mapToObj(layers::get) 878 .collect(Collectors.toList()); 880 879 } 881 880 … … 1019 1018 */ 1020 1019 public List<Layer> getPossibleMergeTargets(Layer source) { 1021 List<Layer> targets = new ArrayList<>();1022 1020 if (source == null) { 1023 return targets; 1024 } 1025 for (Layer target : getLayers()) { 1026 if (source == target) { 1027 continue; 1028 } 1029 if (target.isMergable(source) && source.isMergable(target)) { 1030 targets.add(target); 1031 } 1032 } 1033 return targets; 1021 return new ArrayList<>(); 1022 } 1023 return getLayers().stream() 1024 .filter(target -> source != target && target.isMergable(source) && source.isMergable(target)) 1025 .collect(Collectors.toList()); 1034 1026 } 1035 1027 -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r16252 r16438 402 402 return false; 403 403 int[] pos = tblStyles.getSelectedRows(); 404 if (pos.length == 0) 405 return false; 406 for (int i : pos) { 407 if (!model.getRow(i).isLocal()) 408 return false; 409 } 410 return true; 404 return pos.length > 0 && Arrays.stream(pos).allMatch(i -> model.getRow(i).isLocal()); 411 405 } 412 406 -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r15707 r16438 14 14 import java.util.Collections; 15 15 import java.util.EnumSet; 16 import java.util.HashSet;17 16 import java.util.List; 18 17 import java.util.Set; 18 import java.util.stream.Collectors; 19 import java.util.stream.IntStream; 19 20 20 21 import javax.swing.AbstractAction; … … 503 504 if (removedPrimitives == null) return; 504 505 // extract the removed relations 505 // 506 Set<Relation> removedRelations = new HashSet<>(); 507 for (OsmPrimitive p: removedPrimitives) { 508 if (!(p instanceof Relation)) { 509 continue; 510 } 511 removedRelations.add((Relation) p); 512 } 506 Set<Relation> removedRelations = removedPrimitives.stream() 507 .filter(p -> p instanceof Relation).map(p -> (Relation) p) 508 .collect(Collectors.toSet()); 513 509 if (removedRelations.isEmpty()) 514 510 return; … … 570 566 */ 571 567 public List<IRelation<?>> getSelectedRelations() { 572 List<IRelation<?>> ret = new ArrayList<>(); 573 for (int i = 0; i < getSize(); i++) { 574 if (!selectionModel.isSelectedIndex(i)) { 575 continue; 576 } 577 ret.add(getVisibleRelation(i)); 578 } 579 return ret; 568 return IntStream.range(0, getSize()) 569 .filter(selectionModel::isSelectedIndex) 570 .mapToObj(this::getVisibleRelation) 571 .collect(Collectors.toList()); 580 572 } 581 573 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r16072 r16438 18 18 import java.util.Collections; 19 19 import java.util.Comparator; 20 import java.util.HashSet;21 20 import java.util.LinkedList; 22 21 import java.util.List; 23 import java.util.Set; 22 import java.util.stream.Collectors; 23 import java.util.stream.IntStream; 24 24 25 25 import javax.swing.AbstractAction; … … 523 523 if (history.getFirst().equals(selection)) return; 524 524 history.addFirst(selection); 525 for (int i = 1; i < history.size(); ++i) { 526 if (history.get(i).equals(selection)) { 527 history.remove(i); 528 break; 529 } 530 } 525 IntStream.range(1, history.size()) 526 .filter(i -> history.get(i).equals(selection)) 527 .findFirst() 528 .ifPresent(i -> history.remove(i)); 531 529 int maxsize = Config.getPref().getInt("select.history-size", SELECTION_HISTORY_SIZE); 532 530 while (history.size() > maxsize) { … … 569 567 */ 570 568 public synchronized Collection<OsmPrimitive> getSelected() { 571 Set<OsmPrimitive> sel = new HashSet<>(); 572 for (int i = 0; i < getSize(); i++) { 573 if (selectionModel.isSelectedIndex(i)) { 574 sel.add(selection.get(i)); 575 } 576 } 577 return sel; 569 return IntStream.range(0, getSize()) 570 .filter(selectionModel::isSelectedIndex) 571 .mapToObj(selection::get) 572 .collect(Collectors.toSet()); 578 573 } 579 574 -
trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r14119 r16438 15 15 import java.util.Collections; 16 16 import java.util.HashMap; 17 import java.util.HashSet;18 17 import java.util.Iterator; 19 import java.util.LinkedList;20 18 import java.util.List; 21 19 import java.util.Map; … … 163 161 private List<User> getSelectedUsers() { 164 162 int[] rows = userTable.getSelectedRows(); 165 return rows.length == 0 ? Collections.emptyList() :model.getSelectedUsers(rows);163 return model.getSelectedUsers(rows); 166 164 } 167 165 … … 361 359 362 360 public void selectPrimitivesOwnedBy(int... rows) { 363 Set<User> users = new HashSet<>(); 364 for (int index: rows) { 365 users.add(data.get(index).user); 366 } 361 Set<User> users = Arrays.stream(rows) 362 .mapToObj(index -> data.get(index).user) 363 .collect(Collectors.toSet()); 367 364 OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData(); 368 365 Collection<? extends IPrimitive> selected = ds.getAllSelected(); 369 Collection<IPrimitive> byUser = new LinkedList<>(); 370 for (IPrimitive p : selected) { 371 if (users.contains(p.getUser())) { 372 byUser.add(p); 373 } 374 } 366 Collection<IPrimitive> byUser = selected.stream() 367 .filter(p -> users.contains(p.getUser())) 368 .collect(Collectors.toList()); 375 369 ds.setSelected(byUser); 376 370 } 377 371 378 372 public List<User> getSelectedUsers(int... rows) { 379 List<User> ret = new LinkedList<>();380 373 if (rows == null || rows.length == 0) 381 return ret; 382 for (int row: rows) { 383 if (data.get(row).user == null) { 384 continue; 385 } 386 ret.add(data.get(row).user); 387 } 388 return ret; 374 return Collections.emptyList(); 375 return Arrays.stream(rows) 376 .filter(row -> data.get(row).user != null) 377 .mapToObj(row -> data.get(row).user) 378 .collect(Collectors.toList()); 389 379 } 390 380 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r16296 r16438 237 237 238 238 void updateEnabledState() { 239 boolean found = false;240 239 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 241 if (ds != null && !ds.selectionEmpty()) { 242 for (TestError e : tree.getErrors()) { 243 for (OsmPrimitive p : e.getPrimitives()) { 244 if (p.isSelected()) { 245 found = true; 246 break; 247 } 248 } 249 } 250 } 251 setEnabled(found); 240 if (ds == null || ds.selectionEmpty()) { 241 setEnabled(false); 242 } else { 243 boolean found = tree.getErrors().stream() 244 .anyMatch(e -> e.getPrimitives().stream().anyMatch(OsmPrimitive::isSelected)); 245 setEnabled(found); 246 } 252 247 } 253 248 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerListTransferHandler.java
r13654 r16438 10 10 import java.util.Collection; 11 11 import java.util.List; 12 import java.util.stream.Collectors; 12 13 13 14 import javax.swing.JComponent; … … 47 48 48 49 private static boolean onlyDataLayersSelected(LayerListModel tableModel) { 49 for (Layer l : tableModel.getSelectedLayers()) { 50 if (!(l instanceof OsmDataLayer)) { 51 return false; 52 } 53 } 54 return true; 50 return tableModel.getSelectedLayers().stream().allMatch(l -> l instanceof OsmDataLayer); 55 51 } 56 52 … … 159 155 160 156 private static List<String> getNames(List<Layer> namesToAvoid) { 161 List<String> layerNames = new ArrayList<>(); 162 for (Layer l: namesToAvoid) { 163 layerNames.add(l.getName()); 164 } 165 return layerNames; 157 return namesToAvoid.stream().map(Layer::getName).collect(Collectors.toList()); 166 158 } 167 159 -
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityAction.java
r15660 r16438 399 399 @Override 400 400 protected void updateSliderWhileEnabled(Collection<? extends Layer> usedLayers, boolean allHidden) { 401 double opacity = 0; 402 for (Layer l : usedLayers) { 403 opacity += l.getOpacity(); 404 } 401 double opacity = usedLayers.stream() 402 .mapToDouble(Layer::getOpacity) 403 .sum(); 405 404 opacity /= usedLayers.size(); 406 405 if (opacity == 0) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/CopyAllKeyValueAction.java
r13849 r16438 6 6 import java.awt.event.KeyEvent; 7 7 import java.util.Collection; 8 import java.util.LinkedList;9 import java.util.List;10 import java.util.Map.Entry;11 8 import java.util.function.IntFunction; 12 9 import java.util.function.Supplier; 10 import java.util.stream.Collectors; 13 11 14 12 import javax.swing.JTable; … … 42 40 @Override 43 41 protected Collection<String> getString(Tagged p, String key) { 44 List<String> r = new LinkedList<>(); 45 for (Entry<String, String> kv : p.getKeys().entrySet()) { 46 r.add(new Tag(kv.getKey(), kv.getValue()).toString()); 47 } 48 return r; 42 return p.getKeys().entrySet().stream() 43 .map(kv -> new Tag(kv.getKey(), kv.getValue()).toString()) 44 .collect(Collectors.toList()); 49 45 } 50 46 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r16275 r16438 411 411 protected int checkTableSelection(JTable table, Point p) { 412 412 int row = super.checkTableSelection(table, p); 413 List<IRelation<?>> rels = new ArrayList<>(); 414 for (int i: table.getSelectedRows()) { 415 rels.add((IRelation<?>) table.getValueAt(i, 0)); 416 } 413 List<IRelation<?>> rels = Arrays.stream(table.getSelectedRows()).mapToObj(i -> (IRelation<?>) table.getValueAt(i, 0)).collect(Collectors.toList()); 417 414 membershipMenuHandler.setPrimitives(rels); 418 415 return row; … … 546 543 OsmDataLayer layer = MainApplication.getLayerManager().getActiveDataLayer(); 547 544 if (!layer.isLocked()) { 548 List<RelationMember> members = new ArrayList<>(); 549 for (IRelationMember<?> rm : ((MemberInfo) membershipData.getValueAt(row, 1)).role) { 550 if (rm instanceof RelationMember) { 551 members.add((RelationMember) rm); 552 } 553 } 545 List<RelationMember> members = ((MemberInfo) membershipData.getValueAt(row, 1)).role.stream() 546 .filter(rm -> rm instanceof RelationMember) 547 .map(rm -> (RelationMember) rm) 548 .collect(Collectors.toList()); 554 549 RelationEditor.getEditor(layer, relation, members).setVisible(true); 555 550 } … … 660 655 } 661 656 for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) { 662 int count = 0; 663 for (Entry<String, Integer> e1 : e.getValue().entrySet()) { 664 count += e1.getValue(); 665 } 657 int count = e.getValue().values().stream().mapToInt(i -> i).sum(); 666 658 if (count < newSelSize) { 667 659 e.getValue().put("", newSelSize - count); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r15770 r16438 27 27 import java.util.Collections; 28 28 import java.util.EnumSet; 29 import java.util.HashSet;30 29 import java.util.List; 31 30 import java.util.Set; 31 import java.util.stream.Collectors; 32 32 33 33 import javax.swing.AbstractAction; … … 931 931 932 932 protected static Set<String> findSuggestedRoles(final Collection<TaggingPreset> presets, OsmPrimitive p) { 933 final Set<String> roles = new HashSet<>(); 934 for (TaggingPreset preset : presets) { 935 String role = preset.suggestRoleForOsmPrimitive(p); 936 if (role != null && !role.isEmpty()) { 937 roles.add(role); 938 } 939 } 940 return roles; 933 return presets.stream() 934 .map(preset -> preset.suggestRoleForOsmPrimitive(p)) 935 .filter(role -> role != null && !role.isEmpty()) 936 .collect(Collectors.toSet()); 941 937 } 942 938 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
r15748 r16438 9 9 import java.util.Collection; 10 10 import java.util.EnumSet; 11 import java.util.HashSet;12 11 import java.util.Set; 12 import java.util.stream.Collectors; 13 13 14 14 import javax.swing.AbstractAction; … … 116 116 if (MainApplication.isDisplayingMapView()) { 117 117 Collection<RelationMember> sel = getMemberTableModel().getSelectedMembers(); 118 final Set<OsmPrimitive> toHighlight = new HashSet<>(); 119 for (RelationMember r: sel) { 120 if (r.getMember().isUsable()) { 121 toHighlight.add(r.getMember()); 122 } 123 } 118 final Set<OsmPrimitive> toHighlight = sel.stream() 119 .filter(r -> r.getMember().isUsable()) 120 .map(RelationMember::getMember) 121 .collect(Collectors.toSet()); 124 122 SwingUtilities.invokeLater(() -> { 125 123 if (MainApplication.isDisplayingMapView() && highlightHelper.highlightOnly(toHighlight)) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r16436 r16438 3 3 4 4 import java.util.ArrayList; 5 import java.util.Arrays; 5 6 import java.util.BitSet; 6 7 import java.util.Collection; … … 9 10 import java.util.HashSet; 10 11 import java.util.List; 12 import java.util.Objects; 11 13 import java.util.Set; 12 14 import java.util.TreeSet; … … 372 374 */ 373 375 public boolean hasSameMembersAs(Relation relation) { 374 if (relation == null || relation.getMembersCount() != members.size()) 375 return false; 376 for (int i = 0; i < relation.getMembersCount(); i++) { 377 if (!relation.getMember(i).equals(members.get(i))) 378 return false; 379 } 380 return true; 376 return relation != null 377 && relation.getMembersCount() == members.size() 378 && IntStream.range(0, relation.getMembersCount()) 379 .allMatch(i -> relation.getMember(i).equals(members.get(i))); 381 380 } 382 381 … … 435 434 EnumSet.of(relation != null ? TaggingPresetType.forPrimitive(relation) : TaggingPresetType.RELATION), 436 435 presetHandler.getSelection().iterator().next().getKeys(), false); 437 Collection<String> potentialRoles = new TreeSet<>(); 438 for (TaggingPreset tp : presets) { 439 String suggestedRole = tp.suggestRoleForOsmPrimitive(primitive); 440 if (suggestedRole != null) { 441 potentialRoles.add(suggestedRole); 442 } 443 } 436 Collection<String> potentialRoles = presets.stream() 437 .map(tp -> tp.suggestRoleForOsmPrimitive(primitive)) 438 .filter(Objects::nonNull) 439 .collect(Collectors.toCollection(TreeSet::new)); 444 440 // TODO: propose user to choose role among potential ones instead of picking first one 445 441 final String role = potentialRoles.isEmpty() ? "" : potentialRoles.iterator().next(); … … 515 511 */ 516 512 public Collection<RelationMember> getSelectedMembers() { 517 List<RelationMember> selectedMembers = new ArrayList<>(); 518 for (int i : getSelectedIndices()) { 519 selectedMembers.add(members.get(i)); 520 } 521 return selectedMembers; 522 } 523 524 /** 525 * Replies the set of selected referers. Never null, but may be empty. 526 * 527 * @return the set of selected referers 513 return Arrays.stream(getSelectedIndices()) 514 .mapToObj(members::get) 515 .collect(Collectors.toList()); 516 } 517 518 /** 519 * Replies the set of selected referrers. Never null, but may be empty. 520 * 521 * @return the set of selected referrers 528 522 */ 529 523 public Collection<OsmPrimitive> getSelectedChildPrimitives() { 530 Collection<OsmPrimitive> ret = new ArrayList<>(); 531 for (RelationMember m: getSelectedMembers()) { 532 ret.add(m.getMember()); 533 } 534 return ret; 535 } 536 537 /** 538 * Replies the set of selected referers. Never null, but may be empty. 524 return getSelectedMembers().stream() 525 .map(RelationMember::getMember) 526 .collect(Collectors.toList()); 527 } 528 529 /** 530 * Replies the set of selected referrers. Never null, but may be empty. 539 531 * @param referenceSet reference set 540 532 * 541 * @return the set of selected refer ers533 * @return the set of selected referrers 542 534 */ 543 535 public Set<OsmPrimitive> getChildPrimitives(Collection<? extends OsmPrimitive> referenceSet) { 544 Set<OsmPrimitive> ret = new HashSet<>();545 536 if (referenceSet == null) return null; 546 for (RelationMember m: members) { 547 if (referenceSet.contains(m.getMember())) { 548 ret.add(m.getMember()); 549 } 550 } 551 return ret; 537 return members.stream() 538 .filter(m -> referenceSet.contains(m.getMember())) 539 .map(RelationMember::getMember) 540 .collect(Collectors.toSet()); 552 541 } 553 542 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTransferHandler.java
r12620 r16438 7 7 import java.awt.datatransfer.UnsupportedFlavorException; 8 8 import java.io.IOException; 9 import java.util.ArrayList;10 9 import java.util.Collection; 10 import java.util.Objects; 11 import java.util.stream.Collectors; 11 12 12 13 import javax.swing.JComponent; … … 122 123 protected <T extends PrimitiveId> void importData(MemberTable destination, int insertRow, 123 124 Collection<T> memberData, AbstractRelationMemberConverter<T> toMemberFunction) { 124 final Collection<RelationMember> membersToAdd = new ArrayList<>(memberData.size()); 125 for (T data : memberData) { 126 final RelationMember member = toMemberFunction.importPrimitive(destination, data); 127 if (member != null) { 128 membersToAdd.add(member); 129 } 130 } 125 final Collection<RelationMember> membersToAdd = memberData.stream() 126 .map(data -> toMemberFunction.importPrimitive(destination, data)) 127 .filter(Objects::nonNull) 128 .collect(Collectors.toList()); 131 129 destination.getMemberTableModel().addMembersAtIndexKeepingOldSelection(membersToAdd, insertRow); 132 130 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java
r14214 r16438 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import java.util.Objects; 6 7 7 8 import javax.swing.AbstractListModel; … … 57 58 58 59 protected boolean isReferringRelation(Relation parent) { 59 if (parent == null) return false; 60 for (RelationMember m: parent.getMembers()) { 61 if (m.isRelation()) { 62 Relation child = m.getRelation(); 63 if (child.equals(relation)) return true; 64 } 65 } 66 return false; 60 return parent != null && parent.getMembers().stream() 61 .filter(RelationMember::isRelation) 62 .map(RelationMember::getRelation) 63 .anyMatch(child -> Objects.equals(child, relation)); 67 64 } 68 65 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
r12636 r16438 2 2 package org.openstreetmap.josm.gui.dialogs.relation; 3 3 4 import java.awt.Component; 4 5 import java.awt.Point; 5 6 import java.awt.Window; … … 217 218 */ 218 219 protected boolean hasEditorWithCloseUpperLeftCorner(Point p, RelationEditor thisEditor) { 219 for (RelationEditor editor: openDialogs.values()) { 220 if (editor == thisEditor) { 221 continue; 222 } 223 Point corner = editor.getLocation(); 224 if (p.x >= corner.x -5 && corner.x + 5 >= p.x 225 && p.y >= corner.y -5 && corner.y + 5 >= p.y) 226 return true; 227 } 228 return false; 220 return openDialogs.values().stream() 221 .filter(editor -> editor != thisEditor) 222 .map(Component::getLocation) 223 .anyMatch(corner -> p.x >= corner.x - 5 && corner.x + 5 >= p.x && p.y >= corner.y - 5 && corner.y + 5 >= p.y); 229 224 } 230 225 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTreeModel.java
r10306 r16438 46 46 protected int getNumRelationChildren(Relation parent) { 47 47 if (parent == null) return 0; 48 int count = 0; 49 for (RelationMember member : parent.getMembers()) { 50 if (member.isRelation()) { 51 count++; 52 } 53 } 54 return count; 48 return (int) parent.getMembers().stream().filter(RelationMember::isRelation).count(); 55 49 } 56 50 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/EditAction.java
r14030 r16438 6 6 import java.awt.event.ActionEvent; 7 7 import java.util.Collection; 8 import java.util. HashSet;8 import java.util.stream.Collectors; 9 9 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 40 40 41 41 protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 42 Collection<RelationMember> members = new HashSet<>();43 42 Collection<OsmPrimitive> selection = getLayer().data.getSelected(); 44 for (RelationMember member: r.getMembers()) { 45 if (selection.contains(member.getMember())) { 46 members.add(member); 47 } 48 } 49 return members; 43 return r.getMembers().stream() 44 .filter(member -> selection.contains(member.getMember())) 45 .collect(Collectors.toSet()); 50 46 } 51 47 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
r16119 r16438 5 5 6 6 import java.awt.Component; 7 import java.util.ArrayList;8 7 import java.util.List; 8 import java.util.stream.Collectors; 9 9 10 10 import javax.swing.JOptionPane; … … 51 51 tagEditorModel.applyToPrimitive(newRelation); 52 52 getMemberTableModel().applyToRelation(newRelation); 53 List<RelationMember> newMembers = new ArrayList<>(); 54 for (RelationMember rm: newRelation.getMembers()) { 55 if (!rm.getMember().isDeleted()) { 56 newMembers.add(rm); 57 } 58 } 53 List<RelationMember> newMembers = newRelation.getMembers().stream() 54 .filter(rm -> !rm.getMember().isDeleted()) 55 .collect(Collectors.toList()); 59 56 if (newRelation.getMembersCount() != newMembers.size()) { 60 57 newRelation.setMembers(newMembers); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java
r15418 r16438 12 12 import java.util.Map; 13 13 import java.util.Map.Entry; 14 import java.util.Objects; 14 15 import java.util.stream.Collectors; 15 16 … … 110 111 public List<RelationMember> sortMembers(List<RelationMember> list) { 111 112 final Map<String, RelationMember> platformByName = new HashMap<>(); 112 for (RelationMember i : list) { 113 if (i.getRole().startsWith("platform")) { 114 final RelationMember old = platformByName.put(getStopName(i.getMember()), i); 115 if (old != null) { 116 // Platform with same name present. Stop to avoid damaging complicated relations. 117 // This case can happily be handled differently. 118 return list; 119 } 120 } 113 if (list.stream() 114 .filter(i -> i.getRole().startsWith("platform")) 115 .map(i -> platformByName.put(getStopName(i.getMember()), i)) 116 .anyMatch(Objects::nonNull)) { 117 // Platform with same name present. Stop to avoid damaging complicated relations. 118 // This case can happily be handled differently. 119 return list; 121 120 } 122 121 final List<RelationMember> sorted = new ArrayList<>(list.size()); … … 199 198 public static List<RelationMember> sortMembersByConnectivity(List<RelationMember> defaultMembers) { 200 199 201 List<RelationMember> newMembers = new ArrayList<>();200 List<RelationMember> newMembers; 202 201 203 202 RelationNodeMap map = new RelationNodeMap(defaultMembers); … … 232 231 } 233 232 234 for (List<Integer> tmpGroup : allGroups) { 235 for (Integer p : tmpGroup) { 236 newMembers.add(defaultMembers.get(p)); 237 } 238 } 233 newMembers = allGroups.stream().flatMap(Collection::stream).map(defaultMembers::get).collect(Collectors.toList()); 239 234 240 235 // Finally, add members that have not been sorted at all -
trunk/src/org/openstreetmap/josm/gui/history/DiffTableModel.java
r8840 r16438 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import java.util.stream.IntStream; 6 7 7 8 import javax.swing.table.AbstractTableModel; … … 43 44 44 45 public int getFirstChange() { 45 for (int i = 0; i < rows.size(); i++) { 46 if (rows.get(i).state != DiffItemType.SAME) 47 return i; 48 } 49 return -1; 46 return IntStream.range(0, rows.size()) 47 .filter(i -> rows.get(i).state != DiffItemType.SAME) 48 .findFirst().orElse(-1); 50 49 } 51 50 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r16394 r16438 110 110 111 111 private boolean hasDialogWithCloseUpperLeftCorner(Point p) { 112 for (HistoryBrowserDialog dialog: dialogs.values()) { 113 Point corner = dialog.getLocation(); 114 if (p.x >= corner.x -5 && corner.x + 5 >= p.x 115 && p.y >= corner.y -5 && corner.y + 5 >= p.y) 116 return true; 117 } 118 return false; 112 return dialogs.values().stream() 113 .map(Component::getLocation) 114 .anyMatch(corner -> p.x >= corner.x - 5 && corner.x + 5 >= p.x && p.y >= corner.y - 5 && corner.y + 5 >= p.y); 119 115 } 120 116 -
trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
r16337 r16438 24 24 import java.util.regex.Matcher; 25 25 import java.util.regex.Pattern; 26 import java.util.stream.Collectors; 26 27 27 28 import javax.swing.JOptionPane; … … 203 204 */ 204 205 public static void exportPreferencesKeysByPatternToFile(String fileName, boolean append, String pattern) { 205 List<String> keySet = new ArrayList<>();206 206 Map<String, Setting<?>> allSettings = Preferences.main().getAllSettings(); 207 for (String key: allSettings.keySet()) { 208 if (key.matches(pattern)) 209 keySet.add(key); 210 } 207 List<String> keySet = allSettings.keySet().stream().filter(key -> key.matches(pattern)).collect(Collectors.toList()); 211 208 exportPreferencesKeysToFile(fileName, append, keySet); 212 209 } -
trunk/src/org/openstreetmap/josm/gui/io/OpenChangesetComboBoxModel.java
r12767 r16438 23 23 24 24 protected Changeset getChangesetById(long id) { 25 for (Changeset cs : changesets) { 26 if (cs.getId() == id) return cs; 27 } 28 return null; 25 return changesets.stream().filter(cs -> cs.getId() == id) 26 .findFirst().orElse(null); 29 27 } 30 28 -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersModel.java
r14214 r16438 6 6 import java.io.File; 7 7 import java.util.ArrayList; 8 import java.util.Collections; 8 9 import java.util.Comparator; 9 10 import java.util.List; 11 import java.util.stream.Collectors; 10 12 11 13 import javax.swing.table.DefaultTableModel; … … 120 122 121 123 public List<SaveLayerInfo> getLayersWithoutFilesAndSaveRequest() { 122 List<SaveLayerInfo> ret = new ArrayList<>(); 123 if (layerInfo != null) { 124 for (SaveLayerInfo info: layerInfo) { 125 if (info.isDoSaveToFile() && info.getFile() == null) { 126 ret.add(info); 127 } 128 } 129 } 130 return ret; 124 if (layerInfo == null) { 125 return Collections.emptyList(); 126 } 127 return layerInfo.stream().filter(info -> info.isDoSaveToFile() && info.getFile() == null).collect(Collectors.toList()); 131 128 } 132 129 133 130 public List<SaveLayerInfo> getLayersWithIllegalFilesAndSaveRequest() { 134 List<SaveLayerInfo> ret = new ArrayList<>(); 135 if (layerInfo != null) { 136 for (SaveLayerInfo info: layerInfo) { 137 if (info.isDoSaveToFile() && info.getFile() != null && info.getFile().exists() && !info.getFile().canWrite()) { 138 ret.add(info); 139 } 140 } 141 } 142 return ret; 131 if (layerInfo == null) { 132 return Collections.emptyList(); 133 } 134 return layerInfo.stream() 135 .filter(info -> info.isDoSaveToFile() && info.getFile() != null && info.getFile().exists() && !info.getFile().canWrite()) 136 .collect(Collectors.toList()); 143 137 } 144 138 … … 157 151 158 152 public List<SaveLayerInfo> getLayersToUpload() { 159 List<SaveLayerInfo> ret = new ArrayList<>(); 160 if (layerInfo != null) { 161 for (SaveLayerInfo info: layerInfo) { 162 if (info.isDoUploadToServer()) { 163 ret.add(info); 164 } 165 } 166 } 167 return ret; 153 if (layerInfo == null) { 154 return Collections.emptyList(); 155 } 156 return layerInfo.stream().filter(SaveLayerInfo::isDoUploadToServer).collect(Collectors.toList()); 168 157 } 169 158 170 159 public List<SaveLayerInfo> getLayersToSave() { 171 List<SaveLayerInfo> ret = new ArrayList<>(); 172 if (layerInfo != null) { 173 for (SaveLayerInfo info: layerInfo) { 174 if (info.isDoSaveToFile()) { 175 ret.add(info); 176 } 177 } 178 } 179 return ret; 160 if (layerInfo == null) { 161 return Collections.emptyList(); 162 } 163 return layerInfo.stream().filter(SaveLayerInfo::isDoSaveToFile).collect(Collectors.toList()); 180 164 } 181 165 … … 197 181 198 182 public SaveLayerInfo getSaveLayerInfo(AbstractModifiableLayer layer) { 199 for (SaveLayerInfo info: this.layerInfo) { 200 if (info.getLayer() == layer) 201 return info; 202 } 203 return null; 183 return this.layerInfo.stream() 184 .filter(info -> info.getLayer() == layer) 185 .findFirst().orElse(null); 204 186 } 205 187 … … 222 204 223 205 public int getNumCancel() { 224 int ret = 0; 225 for (SaveLayerInfo info: layerInfo) { 226 if (UploadOrSaveState.CANCELED == info.getSaveState() 227 || UploadOrSaveState.CANCELED == info.getUploadState()) { 228 ret++; 229 } 230 } 231 return ret; 206 return (int) layerInfo.stream() 207 .filter(info -> UploadOrSaveState.CANCELED == info.getSaveState() || UploadOrSaveState.CANCELED == info.getUploadState()) 208 .count(); 232 209 } 233 210 234 211 public int getNumFailed() { 235 int ret = 0; 236 for (SaveLayerInfo info: layerInfo) { 237 if (UploadOrSaveState.FAILED == info.getSaveState() 238 || UploadOrSaveState.FAILED == info.getUploadState()) { 239 ret++; 240 } 241 } 242 return ret; 212 return (int) layerInfo.stream() 213 .filter(info -> UploadOrSaveState.FAILED == info.getSaveState() || UploadOrSaveState.FAILED == info.getUploadState()) 214 .count(); 243 215 } 244 216 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r14214 r16438 72 72 73 73 protected OsmPrimitive getPrimitive(OsmPrimitiveType type, long id) { 74 for (OsmPrimitive p: toUpload) { 75 if (OsmPrimitiveType.from(p) == type && p.getId() == id) 76 return p; 77 } 78 return null; 74 return toUpload.stream() 75 .filter(p -> OsmPrimitiveType.from(p) == type && p.getId() == id) 76 .findFirst().orElse(null); 79 77 } 80 78 -
trunk/src/org/openstreetmap/josm/gui/io/UploadSelectionDialog.java
r15231 r16438 12 12 import java.io.Serializable; 13 13 import java.util.ArrayList; 14 import java.util.Arrays; 14 15 import java.util.Collection; 15 16 import java.util.Collections; 16 17 import java.util.Comparator; 17 18 import java.util.List; 19 import java.util.stream.Collectors; 18 20 19 21 import javax.swing.AbstractAction; … … 251 253 if (indices == null || indices.length == 0) 252 254 return Collections.emptyList(); 253 List<OsmPrimitive> ret = new ArrayList<>(indices.length); 254 for (int i: indices) { 255 if (i < 0) { 256 continue; 257 } 258 ret.add(data.get(i)); 259 } 260 return ret; 255 return Arrays.stream(indices).filter(i -> i >= 0) 256 .mapToObj(i -> data.get(i)) 257 .collect(Collectors.toList()); 261 258 } 262 259 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadStrategySelectionPanel.java
r14345 r16438 299 299 300 300 protected UploadStrategy getUploadStrategy() { 301 UploadStrategy strategy = null; 302 for (Entry<UploadStrategy, JRadioButton> e : rbStrategy.entrySet()) { 303 if (e.getValue().isSelected()) { 304 strategy = e.getKey(); 305 break; 306 } 307 } 308 return strategy; 301 return rbStrategy.entrySet().stream() 302 .filter(e -> e.getValue().isSelected()) 303 .map(Entry::getKey) 304 .findFirst().orElse(null); 309 305 } 310 306 -
trunk/src/org/openstreetmap/josm/gui/layer/NativeScaleLayer.java
r13852 r16438 6 6 import java.util.List; 7 7 import java.util.Locale; 8 import java.util.stream.Collectors; 8 9 9 10 import org.openstreetmap.josm.gui.NavigatableComponent; … … 233 234 @Override 234 235 public String toString() { 235 StringBuilder stringBuilder = new StringBuilder(); 236 for (Scale s: this.scales) { 237 stringBuilder.append(s.toString() + '\n'); 238 } 239 return stringBuilder.toString(); 236 return this.scales.stream().map(Scale::toString).collect(Collectors.joining("\n")); 240 237 } 241 238 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r16187 r16438 32 32 import java.util.Map; 33 33 import java.util.Map.Entry; 34 import java.util.Objects; 34 35 import java.util.Optional; 35 36 import java.util.Set; … … 38 39 import java.util.concurrent.atomic.AtomicInteger; 39 40 import java.util.regex.Pattern; 41 import java.util.stream.Collectors; 42 import java.util.stream.Stream; 40 43 41 44 import javax.swing.AbstractAction; … … 52 55 import org.openstreetmap.josm.data.APIDataSet; 53 56 import org.openstreetmap.josm.data.Bounds; 54 import org.openstreetmap.josm.data.DataSource;55 57 import org.openstreetmap.josm.data.ProjectionBounds; 56 58 import org.openstreetmap.josm.data.UndoRedoHandler; … … 826 828 827 829 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)); 834 832 } 835 833 … … 890 888 addStringIfPresent(wpt, n, GpxConstants.GPX_SRC, "source", "source:position"); 891 889 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()); 899 895 wpt.put(GpxConstants.META_LINKS, links); 900 896 … … 968 964 969 965 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)); 980 972 } 981 973 … … 1029 1021 return true; 1030 1022 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)); 1039 1025 } 1040 1026 … … 1229 1215 */ 1230 1216 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()); 1238 1219 } 1239 1220 -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r16398 r16438 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import java.util.ArrayList;5 4 import java.util.Collection; 6 5 import java.util.Collections; 6 import java.util.stream.Collectors; 7 import java.util.stream.IntStream; 7 8 8 9 import org.apache.commons.jcs3.access.CacheAccess; … … 151 152 152 153 private static ScaleList initNativeScaleList() { 153 Collection<Double> scales = new ArrayList<>(AbstractTileSourceLayer.MAX_ZOOM); 154 for (int zoom = AbstractTileSourceLayer.MIN_ZOOM; zoom <= AbstractTileSourceLayer.MAX_ZOOM; zoom++) { 155 double scale = OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, zoom) / OsmMercator.DEFAUL_TILE_SIZE; 156 scales.add(scale); 157 } 154 Collection<Double> scales = IntStream.rangeClosed(AbstractTileSourceLayer.MIN_ZOOM, AbstractTileSourceLayer.MAX_ZOOM) 155 .mapToDouble(zoom -> OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, zoom) / OsmMercator.DEFAUL_TILE_SIZE) 156 .boxed() 157 .collect(Collectors.toList()); 158 158 return new ScaleList(scales); 159 159 } -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r15857 r16438 6 6 import java.awt.Graphics2D; 7 7 import java.io.File; 8 import java.util.Arrays; 8 9 import java.util.Collections; 9 10 import java.util.List; 11 import java.util.stream.Collectors; 10 12 11 13 import javax.swing.Action; … … 94 96 } 95 97 96 StringBuilder b = new StringBuilder(); 97 for (Severity s : Severity.values()) { 98 if (errorTree.containsKey(s)) { 99 b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>"); 100 } 101 } 98 String b = Arrays.stream(Severity.values()) 99 .filter(errorTree::containsKey) 100 .map(s -> tr(s.toString()) + ": " + errorTree.get(s).size() + "<br>") 101 .collect(Collectors.joining()); 102 102 103 103 if (b.length() == 0) -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r15848 r16438 71 71 import org.openstreetmap.josm.data.gpx.GpxData; 72 72 import org.openstreetmap.josm.data.gpx.GpxImageCorrelation; 73 import org.openstreetmap.josm.data.gpx.GpxImageEntry; 73 74 import org.openstreetmap.josm.data.gpx.GpxTimeOffset; 74 75 import org.openstreetmap.josm.data.gpx.GpxTimezone; 75 import org.openstreetmap.josm.data.gpx.IGpxTrack;76 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment;77 76 import org.openstreetmap.josm.data.gpx.WayPoint; 78 77 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 1263 1262 long firstExifDate = imgs.get(0).getExifTime().getTime(); 1264 1263 1265 long firstGPXDate = -1;1266 1264 // Finds first GPX point 1267 outer: for (IGpxTrack trk : gpx.tracks) { 1268 for (IGpxTrackSegment segment : trk.getSegments()) { 1269 for (WayPoint curWp : segment.getWayPoints()) { 1270 if (curWp.hasDate()) { 1271 firstGPXDate = curWp.getTimeInMillis(); 1272 break outer; 1273 } 1274 } 1275 } 1276 } 1277 1278 if (firstGPXDate < 0) { 1279 throw new NoGpxTimestamps(); 1280 } 1265 long firstGPXDate = gpx.tracks.stream() 1266 .flatMap(trk -> trk.getSegments().stream()) 1267 .flatMap(segment -> segment.getWayPoints().stream()) 1268 .filter(WayPoint::hasDate) 1269 .map(WayPoint::getTimeInMillis) 1270 .findFirst() 1271 .orElseThrow(NoGpxTimestamps::new); 1281 1272 1282 1273 return GpxTimeOffset.milliseconds(firstExifDate - firstGPXDate).splitOutTimezone(); … … 1339 1330 */ 1340 1331 private List<ImageEntry> getSortedImgList(boolean exif, boolean tagged) { 1341 List<ImageEntry> dateImgLst = new ArrayList<>(yLayer.getImageData().getImages().size()); 1342 for (ImageEntry e : yLayer.getImageData().getImages()) { 1343 if (!e.hasExifTime()) { 1344 continue; 1345 } 1346 1347 if (e.getExifCoor() != null && !exif) { 1348 continue; 1349 } 1350 1351 if (!tagged && e.isTagged() && e.getExifCoor() == null) { 1352 continue; 1353 } 1354 1355 dateImgLst.add(e); 1356 } 1357 1358 dateImgLst.sort(Comparator.comparing(ImageEntry::getExifTime)); 1359 1360 return dateImgLst; 1332 return yLayer.getImageData().getImages().stream() 1333 .filter(GpxImageEntry::hasExifTime) 1334 .filter(e -> e.getExifCoor() == null || exif) 1335 .filter(e -> tagged || !e.isTagged() || e.getExifCoor() != null) 1336 .sorted(Comparator.comparing(ImageEntry::getExifTime)) 1337 .collect(Collectors.toList()); 1361 1338 } 1362 1339 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r15826 r16438 797 797 return true; 798 798 } 799 if (supportedMapModes != null) { 800 for (MapMode supmmode: supportedMapModes) { 801 if (mapMode == supmmode) { 802 return true; 803 } 804 } 805 } 806 return false; 799 return supportedMapModes != null && supportedMapModes.stream().anyMatch(supmmode -> mapMode == supmmode); 807 800 } 808 801 -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DownloadWmsAlongTrackAction.java
r15502 r16438 6 6 import java.awt.event.ActionEvent; 7 7 import java.io.IOException; 8 import java.util.ArrayList;9 8 import java.util.List; 9 import java.util.stream.Collectors; 10 10 11 11 import javax.swing.AbstractAction; … … 16 16 import org.openstreetmap.josm.data.coor.LatLon; 17 17 import org.openstreetmap.josm.data.gpx.GpxData; 18 import org.openstreetmap.josm.data.gpx.IGpxTrack;19 import org.openstreetmap.josm.data.gpx.IGpxTrackSegment;20 18 import org.openstreetmap.josm.data.gpx.WayPoint; 21 19 import org.openstreetmap.josm.gui.MainApplication; … … 91 89 92 90 PrecacheWmsTask createTask() { 93 List<LatLon> points = new ArrayList<>(); 94 for (IGpxTrack trk : data.tracks) { 95 for (IGpxTrackSegment segment : trk.getSegments()) { 96 for (WayPoint p : segment.getWayPoints()) { 97 points.add(p.getCoor()); 98 } 99 } 100 } 91 List<LatLon> points = data.tracks.stream() 92 .flatMap(trk -> trk.getSegments().stream()) 93 .flatMap(segment -> segment.getWayPoints().stream()) 94 .map(WayPoint::getCoor) 95 .collect(Collectors.toList()); 101 96 for (WayPoint p : data.waypoints) { 102 97 points.add(p.getCoor()); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java
r15502 r16438 12 12 import java.util.Collection; 13 13 import java.util.Comparator; 14 import java.util.stream.Collectors; 14 15 15 16 import javax.swing.AbstractAction; … … 93 94 if (fc != null) { 94 95 File[] sel = fc.getSelectedFiles(); 95 // sort files in increasing order of timestamp (this is the end time, but so 96 // long as they don't overlap, that's fine) 97 if (sel.length > 1) { 98 Arrays.sort(sel, Comparator.comparingLong(File::lastModified)); 99 } 100 StringBuilder names = new StringBuilder(); 101 for (File file : sel) { 102 if (names.length() == 0) { 103 names.append(" ("); 104 } else { 105 names.append(", "); 106 } 107 names.append(file.getName()); 108 } 109 if (names.length() > 0) { 110 names.append(')'); 111 } 96 String names = Arrays.stream(sel) 97 // sort files in increasing order of timestamp (this is the end time, but so long as they don't overlap, that's fine) 98 .sorted(Comparator.comparingLong(File::lastModified)) 99 .map(File::getName) 100 .collect(Collectors.joining(", ", " (", ")")); 112 101 MarkerLayer ml = new MarkerLayer(new GpxData(), 113 102 tr("Audio markers from {0}", layer.getName()) + names, layer.getAssociatedFile(), layer); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r15497 r16438 16 16 import java.util.List; 17 17 import java.util.Map; 18 import java.util.Objects; 18 19 19 20 import javax.swing.ImageIcon; … … 117 118 */ 118 119 public static Collection<Marker> createMarkers(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) { 119 for (MarkerProducers maker : Marker.markerProducers) { 120 final Collection<Marker> markers = maker.createMarkers(wpt, relativePath, parentLayer, time, offset); 121 if (markers != null) 122 return markers; 123 } 124 return null; 120 return Marker.markerProducers.stream() 121 .map(maker -> maker.createMarkers(wpt, relativePath, parentLayer, time, offset)) 122 .filter(Objects::nonNull) 123 .findFirst().orElse(null); 125 124 } 126 125 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r15496 r16438 266 266 if (syncAudioMarker == null) { 267 267 // find the first audioMarker in this layer 268 for (Marker m : data) { 269 if (m instanceof AudioMarker) { 270 syncAudioMarker = (AudioMarker) m; 271 break; 272 } 273 } 268 syncAudioMarker = Utils.filteredCollection(data, AudioMarker.class).stream() 269 .findFirst().orElse(syncAudioMarker); 274 270 } 275 271 if (syncAudioMarker == null) … … 492 488 if (e.getButton() != MouseEvent.BUTTON1) 493 489 return; 494 boolean mousePressedInButton = false; 495 for (Marker mkr : data) { 496 if (mkr.containsPoint(e.getPoint())) { 497 mousePressedInButton = true; 498 break; 499 } 500 } 490 boolean mousePressedInButton = data.stream().anyMatch(mkr -> mkr.containsPoint(e.getPoint())); 501 491 if (!mousePressedInButton) 502 492 return; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java
r13926 r16438 16 16 import org.openstreetmap.josm.gui.dialogs.MapPaintDialog; 17 17 import org.openstreetmap.josm.gui.layer.GpxLayer; 18 import org.openstreetmap.josm.gui.layer.Layer;19 18 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 20 19 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; … … 67 66 public void updateEnabledState() { 68 67 setEnabled(MainApplication.isDisplayingMapView() 69 && (MainApplication.getLayerManager().getActiveData() != null || mapHasGpx orMarkerLayer()));68 && (MainApplication.getLayerManager().getActiveData() != null || mapHasGpxOrMarkerLayer())); 70 69 } 71 70 72 private static boolean mapHasGpxorMarkerLayer() { 73 for (Layer layer : MainApplication.getLayerManager().getLayers()) { 74 if (layer instanceof GpxLayer || layer instanceof MarkerLayer) { 75 return true; 76 } 77 } 78 return false; 71 private static boolean mapHasGpxOrMarkerLayer() { 72 return MainApplication.getLayerManager().getLayers().stream() 73 .anyMatch(layer -> layer instanceof GpxLayer || layer instanceof MarkerLayer); 79 74 } 80 75 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/loader/MapPaintStyleLoader.java
r12825 r16438 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Array List;6 import java.util.Arrays; 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 9 import java.util.List; 10 import java.util.stream.Collectors; 10 11 11 12 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; … … 62 63 */ 63 64 public static void reloadStyles(final int... sel) { 64 List<StyleSource> toReload = new ArrayList<>();65 65 List<StyleSource> data = MapPaintStyles.getStyles().getStyleSources(); 66 for (int i : sel) { 67 toReload.add(data.get(i)); 68 } 66 List<StyleSource> toReload = Arrays.stream(sel).mapToObj(data::get).collect(Collectors.toList()); 69 67 MainApplication.worker.submit(new MapPaintStyleLoader(toReload)); 70 68 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java
r16287 r16438 6 6 import java.util.Arrays; 7 7 import java.util.EnumSet; 8 import java.util.Map;9 8 import java.util.Objects; 10 9 import java.util.Set; … … 408 407 @Override 409 408 protected boolean matches(Environment env) { 410 for (Map.Entry<String, String> kv: env.osm.getKeys().entrySet()) { 411 if (keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()) { 412 return true; 413 } 414 } 415 return false; 409 return env.osm.getKeys().entrySet().stream() 410 .anyMatch(kv -> keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()); 416 411 } 417 412 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r15907 r16438 15 15 import java.util.Objects; 16 16 import java.util.function.Function; 17 import java.util.stream.Collectors; 17 18 18 19 import org.openstreetmap.josm.gui.mappaint.Cascade; … … 444 445 @Override 445 446 public String toString() { 446 StringBuilder b = new StringBuilder("ArrayFunction~"); 447 b.append(m.getName()).append('('); 448 for (int i = 0; i < args.size(); ++i) { 449 if (i > 0) b.append(','); 450 b.append(arrayComponentType).append(' ').append(args.get(i)); 451 } 452 b.append(')'); 453 return b.toString(); 447 return args.stream() 448 .map(arg -> arrayComponentType + " " + arg) 449 .collect(Collectors.joining(",", "ArrayFunction~" + m.getName() + '(', ")")); 454 450 } 455 451 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
r16252 r16438 24 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 25 import org.openstreetmap.josm.data.osm.Relation; 26 import org.openstreetmap.josm.data.osm.RelationMember;27 26 import org.openstreetmap.josm.data.osm.Way; 28 27 import org.openstreetmap.josm.data.osm.search.SearchCompiler; … … 455 454 if (env.osm != null) { 456 455 // we don't have a matched parent, so just search all referrers 457 for (IPrimitive parent : env.osm.getReferrers()) { 458 String value = parent.get(key); 459 if (value != null) { 460 return value; 461 } 462 } 456 return env.osm.getReferrers().stream() 457 .map(parent -> parent.get(key)) 458 .filter(Objects::nonNull) 459 .findFirst().orElse(null); 463 460 } 464 461 return null; … … 617 614 List<String> roleList = Arrays.asList(roles); 618 615 Relation rel = (Relation) env.osm; 619 for (RelationMember member : rel.getMembers()) {620 if (roleList.contains(member.getRole())) rValue++;621 }616 rValue = (int) rel.getMembers().stream() 617 .filter(member -> roleList.contains(member.getRole())) 618 .count(); 622 619 } 623 620 return rValue; … … 1162 1159 */ 1163 1160 public static boolean inside(Environment env, String codes) { // NO_UCD (unused code) 1164 for (String code : codes.toUpperCase(Locale.ENGLISH).split(",")) { 1165 if (Territories.isIso3166Code(code.trim(), center(env))) { 1166 return true; 1167 } 1168 } 1169 return false; 1161 return Arrays.stream(codes.toUpperCase(Locale.ENGLISH).split(",")) 1162 .anyMatch(code -> Territories.isIso3166Code(code.trim(), center(env))); 1170 1163 } 1171 1164 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r16199 r16438 235 235 236 236 private boolean firstAndLastOnly() { 237 for (Condition c : link.conds) { 238 if (!(c instanceof IndexCondition) || !((IndexCondition) c).isFirstOrLast) { 239 return false; 240 } 241 } 242 return true; 237 return link.conds.stream().allMatch(c -> c instanceof IndexCondition && ((IndexCondition) c).isFirstOrLast); 243 238 } 244 239 -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java
r16290 r16438 7 7 import java.util.List; 8 8 import java.util.Objects; 9 import java.util.stream.Collectors; 9 10 10 11 import org.openstreetmap.josm.data.osm.IPrimitive; … … 13 14 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener; 14 15 import org.openstreetmap.josm.tools.LanguageInfo; 16 import org.openstreetmap.josm.tools.Utils; 15 17 16 18 /** … … 175 177 176 178 private static List<String> buildNameTags(List<String> nameTags) { 177 List<String> result = new ArrayList<>(); 178 if (nameTags != null) { 179 for (String tag: nameTags) { 180 if (tag == null) { 181 continue; 182 } 183 tag = tag.trim(); 184 if (tag.isEmpty()) { 185 continue; 186 } 187 result.add(tag); 188 } 189 } 190 return result; 179 if (nameTags == null) { 180 return new ArrayList<>(); 181 } 182 return nameTags.stream() 183 .filter(tag -> !Utils.isStripEmpty(tag)) 184 .collect(Collectors.toList()); 191 185 } 192 186 … … 252 246 StringBuilder name = new StringBuilder(); 253 247 if (!n.hasKeys()) return null; 254 for (String rn : nameTags) { 255 String val = n.get(rn); 256 if (val != null) { 257 name.append(val); 258 break; 259 } 260 } 248 nameTags.stream().map(n::get).filter(Objects::nonNull).findFirst() 249 .ifPresent(name::append); 261 250 for (String rn : nameComplementTags) { 262 251 String comp = n.get(rn); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r15716 r16438 38 38 import java.util.regex.Matcher; 39 39 import java.util.regex.Pattern; 40 import java.util.stream.Collectors; 41 import java.util.stream.IntStream; 40 42 41 43 import javax.swing.AbstractAction; … … 615 617 */ 616 618 public List<ExtendedSourceEntry> getSelected() { 617 List<ExtendedSourceEntry> ret = new ArrayList<>(); 618 for (int i = 0; i < data.size(); i++) { 619 if (selectionModel.isSelectedIndex(i)) { 620 ret.add(data.get(i)); 621 } 622 } 623 return ret; 619 return IntStream.range(0, data.size()) 620 .filter(selectionModel::isSelectedIndex) 621 .mapToObj(data::get) 622 .collect(Collectors.toList()); 624 623 } 625 624 } … … 729 728 */ 730 729 public void removeIdxs(Collection<Integer> idxs) { 731 List<SourceEntry> newData = new ArrayList<>(); 732 for (int i = 0; i < data.size(); ++i) { 733 if (!idxs.contains(i)) { 734 newData.add(data.get(i)); 735 } 736 } 737 data = newData; 730 data = IntStream.range(0, data.size()) 731 .filter(i -> !idxs.contains(i)) 732 .mapToObj(i -> data.get(i)) 733 .collect(Collectors.toList()); 738 734 fireTableDataChanged(); 739 735 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r16416 r16438 27 27 import java.util.List; 28 28 import java.util.Map; 29 import java.util.Objects; 29 30 import java.util.Optional; 30 31 import java.util.concurrent.ConcurrentHashMap; … … 226 227 */ 227 228 public boolean hasParameters() { 228 if (!(getAction() instanceof ParameterizedAction)) return false; 229 for (Object o: parameters.values()) { 230 if (o != null) return true; 231 } 232 return false; 229 return getAction() instanceof ParameterizedAction && parameters.values().stream().anyMatch(Objects::nonNull); 233 230 } 234 231 } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileAction.java
r14153 r16438 7 7 import java.awt.event.ActionEvent; 8 8 import java.io.File; 9 import java.util.ArrayList;10 9 import java.util.List; 11 10 import java.util.Locale; 12 11 import java.util.Map; 12 import java.util.stream.Collectors; 13 13 14 14 import javax.swing.AbstractAction; … … 48 48 @Override 49 49 public void actionPerformed(ActionEvent ae) { 50 List<String> keys = new ArrayList<>();51 50 Map<String, Setting<?>> all = prefs.getAllSettings(); 52 for (String key: all.keySet()) { 53 if (key.matches(prefPattern)) { 54 keys.add(key); 55 } 56 } 51 List<String> keys = all.keySet().stream() 52 .filter(key -> key.matches(prefPattern)) 53 .collect(Collectors.toList()); 57 54 if (keys.isEmpty()) { 58 55 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTable.java
r14153 r16438 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.util.Array List;13 import java.util.Arrays; 14 14 import java.util.List; 15 15 import java.util.Map; 16 16 import java.util.Objects; 17 import java.util.stream.Collectors; 17 18 18 19 import javax.swing.ButtonGroup; … … 80 81 */ 81 82 public List<PrefEntry> getSelectedItems() { 82 List<PrefEntry> entries = new ArrayList<>(); 83 for (int row : getSelectedRows()) { 84 PrefEntry p = (PrefEntry) model.getValueAt(row, -1); 85 entries.add(p); 86 } 87 return entries; 83 return Arrays.stream(getSelectedRows()) 84 .mapToObj(row -> (PrefEntry) model.getValueAt(row, -1)) 85 .collect(Collectors.toList()); 88 86 } 89 87 -
trunk/src/org/openstreetmap/josm/gui/preferences/display/LanguagePreference.java
r14929 r16438 94 94 if (language != null) { 95 95 String lang = LanguageInfo.getJavaLocaleCode(language); 96 for (Locale locale: data) { 97 if (locale == null) { 98 continue; 99 } 100 if (locale.toString().equals(lang)) { 101 setSelectedItem(locale); 102 return; 103 } 104 } 96 data.stream() 97 .filter(locale -> locale != null && locale.toString().equals(lang)) 98 .findFirst() 99 .ifPresent(this::setSelectedItem); 105 100 } 106 101 } -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryProvidersPanel.java
r15357 r16438 21 21 import java.util.List; 22 22 import java.util.Map; 23 import java.util.Objects; 23 24 import java.util.Optional; 24 25 import java.util.Set; … … 127 128 GuiHelper.setBackgroundReadable(label, UIManager.getColor("Table.background")); 128 129 if (value != null) { // Fix #8159 129 String t = value.toString(); 130 for (ImageryInfo l : layers) { 131 if (l.getExtendedUrl().equals(t)) { 132 GuiHelper.setBackgroundReadable(label, IMAGERY_BACKGROUND_COLOR.get()); 133 break; 134 } 130 if (layers.stream().anyMatch(l -> Objects.equals(l.getExtendedUrl(), value.toString()))) { 131 GuiHelper.setBackgroundReadable(label, IMAGERY_BACKGROUND_COLOR.get()); 135 132 } 136 133 label.setToolTipText((String) value); -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginCheckBox.java
r14384 r16438 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.ActionListener; 10 import java.util.HashSet;11 10 import java.util.Set; 11 import java.util.stream.Collectors; 12 12 13 13 import javax.swing.JCheckBox; … … 59 59 } else if (!isSelected()) { 60 60 // If the plugin has been unselected, was it required by other plugins still selected ? 61 Set<String> otherPlugins = new HashSet<>(); 62 for (PluginInformation p : ppModel.getAvailablePlugins()) { 63 if (!p.equals(pi) && p.requires != null && ppModel.isSelectedPlugin(p.getName())) { 64 for (String s : p.getRequiredPlugins()) { 65 if (s.equals(pi.getName()) || s.equals(pi.provides)) { 66 otherPlugins.add(p.getName()); 67 break; 68 } 69 } 70 } 71 } 61 Set<String> otherPlugins = ppModel.getAvailablePlugins().stream() 62 .filter(p -> !p.equals(pi) && p.requires != null && ppModel.isSelectedPlugin(p.getName())) 63 .filter(p -> p.getRequiredPlugins().stream().anyMatch(s -> s.equals(pi.getName()) || s.equals(pi.provides))) 64 .map(PluginInformation::getName) 65 .collect(Collectors.toSet()); 72 66 if (!otherPlugins.isEmpty()) { 73 67 alertPluginStillRequired(panel, pi.getName(), otherPlugins); -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r15716 r16438 23 23 import java.util.Set; 24 24 import java.util.regex.Pattern; 25 import java.util.stream.Collectors; 26 import java.util.stream.IntStream; 25 27 26 28 import javax.swing.AbstractAction; … … 331 333 return requiresRestart; 332 334 } 333 for (PluginInformation pi : model.getNewlyActivatedPlugins()) { 334 if (!pi.canloadatruntime) 335 return true; 336 } 335 return model.getNewlyActivatedPlugins().stream().anyMatch(pi -> !pi.canloadatruntime); 337 336 } 338 337 return false; … … 436 435 if (pluginDownloadTask.isCanceled()) 437 436 return; 438 boolean restartRequired = false; 439 for (PluginInformation pi : pluginDownloadTask.getDownloadedPlugins()) { 440 if (!model.getNewlyActivatedPlugins().contains(pi) || !pi.canloadatruntime) { 441 restartRequired = true; 442 break; 443 } 444 } 437 boolean restartRequired = pluginDownloadTask.getDownloadedPlugins().stream() 438 .anyMatch(pi -> !(model.getNewlyActivatedPlugins().contains(pi) && pi.canloadatruntime)); 445 439 notifyDownloadResults(pnlPluginPreferences, pluginDownloadTask, restartRequired); 446 440 model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins()); … … 638 632 if (model.getSize() == 0) 639 633 return Collections.emptyList(); 640 List<String> ret = new ArrayList<>(model.getSize()); 641 for (int i = 0; i < model.getSize(); i++) { 642 ret.add(model.get(i)); 643 } 644 return ret; 634 return IntStream.range(0, model.getSize()) 635 .mapToObj(model::get) 636 .collect(Collectors.toList()); 645 637 } 646 638 } -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java
r15227 r16438 13 13 import java.util.Map; 14 14 import java.util.Map.Entry; 15 import java.util.Objects; 15 16 import java.util.Set; 17 import java.util.stream.Collectors; 16 18 17 19 import org.openstreetmap.josm.gui.util.ChangeNotifier; … … 137 139 */ 138 140 public List<PluginInformation> getSelectedPlugins() { 139 List<PluginInformation> ret = new LinkedList<>(); 140 for (PluginInformation pi: availablePlugins) { 141 if (selectedPluginsMap.get(pi) == null) { 142 continue; 143 } 144 if (selectedPluginsMap.get(pi)) { 145 ret.add(pi); 146 } 147 } 148 return ret; 141 return availablePlugins.stream() 142 .filter(pi -> selectedPluginsMap.get(pi) != null) 143 .filter(selectedPluginsMap::get) 144 .collect(Collectors.toList()); 149 145 } 150 146 … … 155 151 */ 156 152 public Set<String> getSelectedPluginNames() { 157 Set<String> ret = new HashSet<>(); 158 for (PluginInformation pi: getSelectedPlugins()) { 159 ret.add(pi.name); 160 } 161 return ret; 153 return getSelectedPlugins().stream().map(pi -> pi.name).collect(Collectors.toSet()); 162 154 } 163 155 … … 185 177 */ 186 178 public Set<PluginInformation> getPluginsScheduledForUpdateOrDownload() { 187 Set<PluginInformation> ret = new HashSet<>(); 188 for (String plugin: pendingDownloads) { 189 PluginInformation pi = getPluginInformation(plugin); 190 if (pi == null) { 191 continue; 192 } 193 ret.add(pi); 194 } 195 return ret; 179 return pendingDownloads.stream() 180 .map(this::getPluginInformation) 181 .filter(Objects::nonNull) 182 .collect(Collectors.toSet()); 196 183 } 197 184 … … 238 225 public PluginInformation getPluginInformation(String name) { 239 226 if (name != null) { 240 for (PluginInformation pi: availablePlugins) { 241 if (name.equals(pi.getName()) || name.equals(pi.provides)) 242 return pi; 243 } 227 return availablePlugins.stream() 228 .filter(pi -> name.equals(pi.getName()) || name.equals(pi.provides)) 229 .findFirst().orElse(null); 244 230 } 245 231 return null; … … 303 289 */ 304 290 public List<PluginInformation> getNewlyDeactivatedPlugins() { 305 List<PluginInformation> ret = new LinkedList<>(); 306 for (PluginInformation pi: availablePlugins) { 307 if (!currentActivePlugins.contains(pi.name)) { 308 continue; 309 } 310 if (selectedPluginsMap.get(pi) == null || !selectedPluginsMap.get(pi)) { 311 ret.add(pi); 312 } 313 } 314 return ret; 291 return availablePlugins.stream() 292 .filter(pi -> currentActivePlugins.contains(pi.name)) 293 .filter(pi -> selectedPluginsMap.get(pi) == null || !selectedPluginsMap.get(pi)) 294 .collect(Collectors.toList()); 315 295 } 316 296 … … 331 311 */ 332 312 public Set<String> getNewlyActivatedPluginNames() { 333 Set<String> ret = new HashSet<>(); 334 List<PluginInformation> plugins = getNewlyActivatedPlugins(); 335 for (PluginInformation pi: plugins) { 336 ret.add(pi.name); 337 } 338 return ret; 313 return getNewlyActivatedPlugins().stream().map(pi -> pi.name).collect(Collectors.toSet()); 339 314 } 340 315 -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginUpdatePolicyPanel.java
r13064 r16438 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.Insets; 10 import java.util.Arrays; 10 11 import java.util.EnumMap; 11 12 import java.util.Locale; … … 51 52 return null; 52 53 String prefValue = preferenceValue.trim().toLowerCase(Locale.ENGLISH); 53 for (Policy p: Policy.values()) { 54 if (p.getPreferencesValue().equals(prefValue)) 55 return p; 56 } 57 return null; 54 return Arrays.stream(Policy.values()) 55 .filter(p -> p.getPreferencesValue().equals(prefValue)) 56 .findFirst().orElse(null); 58 57 } 59 58 } … … 193 192 194 193 // remember policy for version based update 195 // 196 for (Policy p: Policy.values()) { 197 if (rbVersionBasedUpatePolicy.get(p).isSelected()) { 198 Config.getPref().put("pluginmanager.version-based-update.policy", p.getPreferencesValue()); 199 break; 200 } 201 } 194 Arrays.stream(Policy.values()) 195 .filter(p -> rbVersionBasedUpatePolicy.get(p).isSelected()).findFirst() 196 .ifPresent(p -> Config.getPref().put("pluginmanager.version-based-update.policy", p.getPreferencesValue())); 202 197 203 198 // remember policy for time based update 204 // 205 for (Policy p: Policy.values()) { 206 if (rbTimeBasedUpatePolicy.get(p).isSelected()) { 207 Config.getPref().put("pluginmanager.time-based-update.policy", p.getPreferencesValue()); 208 break; 209 } 210 } 199 Arrays.stream(Policy.values()) 200 .filter(p -> rbTimeBasedUpatePolicy.get(p).isSelected()).findFirst() 201 .ifPresent(p -> Config.getPref().put("pluginmanager.time-based-update.policy", p.getPreferencesValue())); 211 202 212 203 // remember update interval -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java
r12620 r16438 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 import java.util.stream.IntStream; 9 10 10 11 import javax.swing.JLabel; … … 66 67 @Override 67 68 public String[] allCodes() { 68 String[] codes = new String[9]; 69 for (int zone = 0; zone < 9; zone++) { 70 codes[zone] = "EPSG:" + (3942 + zone); 71 } 72 return codes; 69 return IntStream.range(0, 9).mapToObj(zone -> "EPSG:" + (3942 + zone)).toArray(String[]::new); 73 70 } 74 71 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java
r12620 r16438 7 7 import java.util.Collection; 8 8 import java.util.Collections; 9 import java.util.stream.IntStream; 9 10 10 11 import javax.swing.JLabel; … … 61 62 @Override 62 63 public String[] allCodes() { 63 String[] codes = new String[4]; 64 for (int zone = 0; zone < 4; zone++) { 65 codes[zone] = "EPSG:"+(27561+zone); 66 } 67 return codes; 64 return IntStream.range(0, 4).mapToObj(zone -> "EPSG:" + (27561 + zone)).toArray(String[]::new); 68 65 } 69 66 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r14153 r16438 14 14 import java.util.List; 15 15 import java.util.Map; 16 import java.util.stream.IntStream; 16 17 17 18 import javax.swing.BorderFactory; … … 354 355 final ProjectionChoice pc = setupProjectionCombo(); 355 356 356 for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) { 357 if (coordinatesCombo.getItemAt(i).getId().equals(PROP_COORDINATES.get())) { 358 coordinatesCombo.setSelectedIndex(i); 359 break; 360 } 361 } 362 363 for (int i = 0; i < unitsValues.length; ++i) { 364 if (unitsValues[i].equals(SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.get())) { 365 unitsCombo.setSelectedIndex(i); 366 break; 367 } 368 } 357 IntStream.range(0, coordinatesCombo.getItemCount()) 358 .filter(i -> coordinatesCombo.getItemAt(i).getId().equals(PROP_COORDINATES.get())).findFirst() 359 .ifPresent(coordinatesCombo::setSelectedIndex); 360 361 IntStream.range(0, unitsValues.length) 362 .filter(i -> unitsValues[i].equals(SystemOfMeasurement.PROP_SYSTEM_OF_MEASUREMENT.get())).findFirst() 363 .ifPresent(unitsCombo::setSelectedIndex); 369 364 370 365 projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java
r12231 r16438 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Arrays; 6 7 import java.util.Collection; 7 8 import java.util.Collections; 9 import java.util.stream.IntStream; 8 10 9 11 import org.openstreetmap.josm.tools.Utils; … … 57 59 @Override 58 60 public Collection<String> getPreferencesFromCode(String code) { 59 for (String code2 : CODES) { 60 if (code.equals(code2)) 61 return Collections.singleton(code2); 62 } 63 return null; 61 return Arrays.stream(CODES).filter(code::equals).findFirst().map(Collections::singleton).orElse(null); 64 62 } 65 63 … … 71 69 @Override 72 70 protected int zoneToIndex(String zone) { 73 for (int i = 0; i < CODES.length; i++) { 74 if (zone.equals(CODES[i])) { 75 return i; 76 } 77 } 78 return defaultIndex; 71 return IntStream.range(0, CODES.length) 72 .filter(i -> zone.equals(CODES[i])) 73 .findFirst().orElse(defaultIndex); 79 74 } 80 75 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMFranceDOMProjectionChoice.java
r12620 r16438 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Arrays; 6 7 import java.util.Collection; 7 8 import java.util.Collections; … … 64 65 @Override 65 66 public String[] allCodes() { 66 String[] res = new String[UTM_EPSGS.length]; 67 for (int i = 0; i < UTM_EPSGS.length; ++i) { 68 res[i] = "EPSG:" + UTM_EPSGS[i]; 69 } 70 return res; 67 return Arrays.stream(UTM_EPSGS).map(utmEpsg -> "EPSG:" + utmEpsg).toArray(String[]::new); 71 68 } 72 69 -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
r14214 r16438 15 15 import java.net.PasswordAuthentication; 16 16 import java.net.ProxySelector; 17 import java.util.Arrays; 17 18 import java.util.EnumMap; 18 19 import java.util.Map; … … 337 338 */ 338 339 public void saveToPreferences() { 339 ProxyPolicy policy = null; 340 for (ProxyPolicy pp: ProxyPolicy.values()) { 341 if (rbProxyPolicy.get(pp).isSelected()) { 342 policy = pp; 343 break; 344 } 345 } 340 ProxyPolicy policy = Arrays.stream(ProxyPolicy.values()) 341 .filter(pp -> rbProxyPolicy.get(pp).isSelected()) 342 .findFirst().orElse(null); 346 343 Config.getPref().put(DefaultProxySelector.PROXY_POLICY, Optional.ofNullable(policy).orElse(ProxyPolicy.NO_PROXY).getName()); 347 344 Config.getPref().put(DefaultProxySelector.PROXY_HTTP_HOST, tfProxyHttpHost.getText()); -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r14273 r16438 7 7 import java.beans.PropertyChangeSupport; 8 8 import java.util.ArrayList; 9 import java.util.Arrays; 9 10 import java.util.Collection; 10 11 import java.util.Comparator; 11 12 import java.util.EnumSet; 12 import java.util.HashMap;13 13 import java.util.Iterator; 14 14 import java.util.List; 15 15 import java.util.Map; 16 16 import java.util.Map.Entry; 17 import java.util.Objects; 18 import java.util.stream.Collectors; 19 import java.util.stream.IntStream; 17 20 18 21 import javax.swing.DefaultListSelectionModel; … … 253 256 public TagModel get(String name) { 254 257 String key = (name == null) ? "" : name; 255 for (TagModel tag : tags) { 256 if (tag.getName().equals(key)) 257 return tag; 258 } 259 return null; 258 return tags.stream().filter(tag -> tag.getName().equals(key)).findFirst().orElse(null); 260 259 } 261 260 … … 346 345 return; 347 346 commitPendingEdit(); 348 List<TagModel> toDelete = new ArrayList<>(); 349 for (int tagIdx : tagIndices) { 350 TagModel tag = tags.get(tagIdx); 351 if (tag != null) { 352 toDelete.add(tag); 353 } 354 } 355 for (TagModel tag : toDelete) { 356 tags.remove(tag); 357 } 347 List<TagModel> toDelete = Arrays.stream(tagIndices).mapToObj(tags::get).filter(Objects::nonNull).collect(Collectors.toList()); 348 toDelete.forEach(tags::remove); 358 349 fireTableDataChanged(); 359 350 setDirty(true); … … 506 497 */ 507 498 public boolean includesTag(String key) { 508 if (key != null) { 509 for (TagModel tag : tags) { 510 if (tag.getName().equals(key)) 511 return true; 512 } 513 } 514 return false; 499 return key != null && tags.stream().anyMatch(tag -> tag.getName().equals(key)); 515 500 } 516 501 … … 555 540 */ 556 541 public List<String> getKeys() { 557 List<String> keys = new ArrayList<>(); 558 for (TagModel tag: tags) { 559 if (!tag.getName().trim().isEmpty()) { 560 keys.add(tag.getName()); 561 } 562 } 563 return keys; 542 return tags.stream() 543 .filter(tag -> !tag.getName().trim().isEmpty()) 544 .map(TagModel::getName) 545 .collect(Collectors.toList()); 564 546 } 565 547 … … 616 598 617 599 commitPendingEdit(); 618 Map<String, TagModel> modelTags = new HashMap<>(); 619 for (int i = 0; i < getRowCount(); i++) { 620 TagModel tagModel = get(i); 621 modelTags.put(tagModel.getName(), tagModel); 622 } 600 Map<String, TagModel> modelTags = IntStream.range(0, getRowCount()) 601 .mapToObj(this::get) 602 .collect(Collectors.toMap(TagModel::getName, tagModel -> tagModel, (a, b) -> b)); 623 603 for (Tag tag: tags) { 624 604 TagModel existing = modelTags.get(tag.getKey()); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r16280 r16438 63 63 import org.openstreetmap.josm.gui.tagging.presets.items.PresetLink; 64 64 import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 65 import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role;66 65 import org.openstreetmap.josm.gui.tagging.presets.items.Space; 67 66 import org.openstreetmap.josm.gui.util.GuiHelper; … … 71 70 import org.openstreetmap.josm.tools.ImageResource; 72 71 import org.openstreetmap.josm.tools.Logging; 72 import org.openstreetmap.josm.tools.StreamUtils; 73 73 import org.openstreetmap.josm.tools.Utils; 74 74 import org.openstreetmap.josm.tools.template_engine.ParseError; … … 284 284 285 285 /** 286 * Returns the tags being directly applied (without UI element) by {@link Key} items287 *288 * @return a list of tags289 */290 private List<Tag> getDirectlyAppliedTags() {291 List<Tag> tags = new ArrayList<>();292 for (TaggingPresetItem item : data) {293 if (item instanceof Key) {294 tags.add(((Key) item).asTag());295 }296 }297 return tags;298 }299 300 /**301 286 * Creates a panel for this preset. This includes general information such as name and supported {@link TaggingPresetType types}. 302 287 * This includes the elements from the individual {@link TaggingPresetItem items}. … … 317 302 } 318 303 } 319 final List<Tag> directlyAppliedTags = getDirectlyAppliedTags(); 304 final List<Tag> directlyAppliedTags = Utils.filteredCollection(data, Key.class).stream() 305 .map(Key::asTag) 306 .collect(Collectors.toList()); 320 307 if (!directlyAppliedTags.isEmpty()) { 321 308 final JLabel label = new JLabel(ImageProvider.get("pastetags")); … … 377 364 */ 378 365 public boolean isShowable() { 379 for (TaggingPresetItem i : data) { 380 if (!(i instanceof Optional || i instanceof Space || i instanceof Key)) 381 return true; 382 } 383 return false; 366 return data.stream().anyMatch(i -> !(i instanceof Optional || i instanceof Space || i instanceof Key)); 384 367 } 385 368 386 369 public String suggestRoleForOsmPrimitive(OsmPrimitive osm) { 387 370 if (roles != null && osm != null) { 388 for (Role i : roles.roles) { 389 if (i.memberExpression != null && i.memberExpression.match(osm) 390 && (i.types == null || i.types.isEmpty() || i.types.contains(TaggingPresetType.forPrimitive(osm)))) { 391 return i.key; 392 } 393 } 371 return roles.roles.stream() 372 .filter(i -> i.memberExpression != null && i.memberExpression.match(osm)) 373 .filter(i -> i.types == null || i.types.isEmpty() || i.types.contains(TaggingPresetType.forPrimitive(osm))) 374 .map(i -> i.key) 375 .findFirst().orElse(null); 394 376 } 395 377 return null; … … 549 531 */ 550 532 public static Command createCommand(Collection<OsmPrimitive> sel, List<Tag> changedTags) { 551 List<Command> cmds = new ArrayList<>(); 552 for (Tag tag: changedTags) { 553 ChangePropertyCommand cmd = new ChangePropertyCommand(sel, tag.getKey(), tag.getValue()); 554 if (cmd.getObjectsNumber() > 0) { 555 cmds.add(cmd); 556 } 557 } 533 List<Command> cmds = changedTags.stream() 534 .map(tag -> new ChangePropertyCommand(sel, tag.getKey(), tag.getValue())) 535 .filter(cmd -> cmd.getObjectsNumber() > 0) 536 .collect(StreamUtils.toUnmodifiableList()); 558 537 559 538 if (cmds.isEmpty()) -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetType.java
r13564 r16438 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets; 3 4 import java.util.Arrays; 3 5 4 6 import org.openstreetmap.josm.data.osm.IPrimitive; … … 78 80 */ 79 81 public static TaggingPresetType fromString(String type) { 80 for (TaggingPresetType t : TaggingPresetType.values()) { 81 if (t.getName().equals(type)) { 82 return t; 83 } 84 } 85 return null; 82 return Arrays.stream(TaggingPresetType.values()) 83 .filter(t -> t.getName().equals(type)) 84 .findFirst().orElse(null); 86 85 } 87 86 } -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r15586 r16438 33 33 import java.util.concurrent.ExecutionException; 34 34 import java.util.concurrent.FutureTask; 35 import java.util.stream.Stream; 35 36 36 37 import javax.swing.GrayFilter; … … 640 641 Collection<String> fonts = Arrays.asList( 641 642 GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); 642 for (String f : new String[]{"Khmer UI", "DaunPenh", "MoolBoran"}) { 643 if (fonts.contains(f)) { 644 setUIFont(f); 645 break; 646 } 647 } 643 Stream.of("Khmer UI", "DaunPenh", "MoolBoran") 644 .filter(fonts::contains) 645 .findFirst() 646 .ifPresent(GuiHelper::setUIFont); 648 647 } 649 648 } -
trunk/src/org/openstreetmap/josm/gui/util/StayOpenPopupMenu.java
r15497 r16438 56 56 Field tableField = appContextClass.getDeclaredField("table"); 57 57 ReflectionUtils.setObjectsAccessible(tableField); 58 Object mouseGrabber = null; 59 for (Entry<?, ?> e : ((Map<?, ?>) 60 tableField.get(appContextClass.getMethod("getAppContext").invoke(appContextClass))).entrySet()) { 61 if (MOUSE_GRABBER_KEY.equals(Objects.toString(e.getKey()))) { 62 mouseGrabber = e.getValue(); 63 break; 64 } 65 } 58 Object mouseGrabber = ((Map<?, ?>) tableField.get(appContextClass.getMethod("getAppContext").invoke(appContextClass))) 59 .entrySet().stream() 60 .filter(e -> MOUSE_GRABBER_KEY.equals(Objects.toString(e.getKey()))) 61 .map(Entry::getValue) 62 .findFirst().orElse(null); 66 63 final ChangeListener changeListener = (ChangeListener) mouseGrabber; 67 64 final AWTEventListener awtEventListener = (AWTEventListener) mouseGrabber; -
trunk/src/org/openstreetmap/josm/gui/widgets/EditableList.java
r14153 r16438 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.util.ArrayList;10 9 import java.util.List; 10 import java.util.stream.Collectors; 11 import java.util.stream.IntStream; 11 12 12 13 import javax.swing.DefaultListModel; … … 145 146 */ 146 147 public List<String> getItems() { 147 final List<String> items = new ArrayList<>(sourcesList.getModel().getSize()); 148 for (int i = 0; i < sourcesList.getModel().getSize(); ++i) { 149 items.add(sourcesList.getModel().getElementAt(i)); 150 } 151 return items; 148 return IntStream.range(0, sourcesList.getModel().getSize()) 149 .mapToObj(i -> sourcesList.getModel().getElementAt(i)) 150 .collect(Collectors.toList()); 152 151 } 153 152 -
trunk/src/org/openstreetmap/josm/gui/widgets/FilterField.java
r15116 r16438 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Array List;6 import java.util.Arrays; 7 7 import java.util.List; 8 8 import java.util.Objects; 9 9 import java.util.regex.PatternSyntaxException; 10 import java.util.stream.Collectors; 10 11 11 12 import javax.swing.JTable; … … 86 87 expr = expr.replace("+", "\\+"); 87 88 // split search string on whitespace, do case-insensitive AND search 88 List<RowFilter<Object, Object>> andFilters = new ArrayList<>(); 89 for (String word : expr.split("\\s+")) { 90 andFilters.add(RowFilter.regexFilter("(?i)" + word)); 91 } 89 List<RowFilter<Object, Object>> andFilters = Arrays.stream(expr.split("\\s+")) 90 .map(word -> RowFilter.regexFilter("(?i)" + word)) 91 .collect(Collectors.toList()); 92 92 sorter.setRowFilter(RowFilter.andFilter(andFilters)); 93 93 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java
r14977 r16438 8 8 import java.beans.PropertyChangeEvent; 9 9 import java.beans.PropertyChangeListener; 10 import java.util.ArrayList;11 10 import java.util.Arrays; 12 11 import java.util.Collection; 13 12 import java.util.List; 14 15 import javax.accessibility.Accessible; 13 import java.util.stream.Collectors; 14 import java.util.stream.IntStream; 15 16 16 import javax.swing.ComboBoxEditor; 17 17 import javax.swing.ComboBoxModel; … … 80 80 public JosmComboBox(ComboBoxModel<E> aModel) { 81 81 super(aModel); 82 List<E> list = new ArrayList<>(aModel.getSize()); 83 for (int i = 0; i < aModel.getSize(); i++) { 84 list.add(aModel.getElementAt(i)); 85 } 82 List<E> list = IntStream.range(0, aModel.getSize()) 83 .mapToObj(aModel::getElementAt) 84 .collect(Collectors.toList()); 86 85 init(findPrototypeDisplayValue(list)); 87 86 } … … 155 154 } 156 155 157 @SuppressWarnings("unchecked")158 156 protected final JList<Object> getList() { 159 for (int i = 0; i < getUI().getAccessibleChildrenCount(this); i++) { 160 Accessible child = getUI().getAccessibleChild(this, i); 161 if (child instanceof ComboPopup) { 162 return ((ComboPopup) child).getList(); 163 } 164 } 165 return null; 157 return IntStream.range(0, getUI().getAccessibleChildrenCount(this)) 158 .mapToObj(i -> getUI().getAccessibleChild(this, i)) 159 .filter(child -> child instanceof ComboPopup) 160 .map(child -> ((ComboPopup) child).getList()) 161 .findFirst().orElse(null); 166 162 } 167 163 -
trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitLayout.java
r14273 r16438 777 777 } else if (root instanceof Split) { 778 778 Split split = (Split) root; 779 for (Node child : split.getChildren()) {780 if (child.getBounds().contains(x, y))781 return dividerAt(child, x, y);782 }779 return split.getChildren().stream() 780 .filter(child -> child.getBounds().contains(x, y)) 781 .map(child -> dividerAt(child, x, y)) 782 .findFirst().orElse(null); 783 783 } 784 784 return null; -
trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java
r16276 r16438 10 10 import java.awt.event.MouseEvent; 11 11 import java.awt.event.MouseListener; 12 import java.util.stream.IntStream; 12 13 13 14 import javax.swing.AbstractAction; … … 216 217 private void nextState() { 217 218 State current = getState(); 218 for (int i = 0; i < allowed.length; i++) { 219 if (allowed[i] == current) { 220 setState((i == allowed.length-1) ? allowed[0] : allowed[i+1]); 221 break; 222 } 223 } 219 IntStream.range(0, allowed.length).filter(i -> allowed[i] == current) 220 .findFirst() 221 .ifPresent(i -> setState((i == allowed.length - 1) ? allowed[0] : allowed[i + 1])); 224 222 } 225 223
Note:
See TracChangeset
for help on using the changeset viewer.