Ignore:
Timestamp:
2020-01-18T14:14:01+01:00 (4 years ago)
Author:
simon04
Message:

Java 8: use Collectors.joining

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/AbstractCopyAction.java

    r13956 r15717  
    33
    44import java.awt.event.ActionEvent;
     5import java.util.Arrays;
    56import java.util.Collection;
    67import java.util.Objects;
    7 import java.util.Set;
    8 import java.util.TreeSet;
    98import java.util.function.IntFunction;
    109import java.util.function.Supplier;
     10import java.util.stream.Collectors;
    1111
    1212import javax.swing.AbstractAction;
     
    1515import org.openstreetmap.josm.data.osm.Tagged;
    1616import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    17 import org.openstreetmap.josm.tools.Utils;
    1817
    1918/**
     
    4443    public void actionPerformed(ActionEvent ae) {
    4544        int[] rows = tagTable.getSelectedRows();
    46         Set<String> values = new TreeSet<>();
    4745        Collection<? extends Tagged> sel = objectSupplier.get();
    4846        if (rows.length == 0 || sel == null || sel.isEmpty()) return;
    4947
    50         for (int row: rows) {
    51             String key = keySupplier.apply(row);
    52             for (Tagged p : sel) {
    53                 Collection<String> s = getString(p, key);
    54                 if (s != null) {
    55                     values.addAll(s);
    56                 }
    57             }
    58         }
     48        final String values = Arrays.stream(rows)
     49                .mapToObj(keySupplier)
     50                .flatMap(key -> sel.stream().map(p -> getString(p, key)))
     51                .filter(Objects::nonNull)
     52                .flatMap(Collection::stream)
     53                .sorted()
     54                .collect(Collectors.joining("\n"));
    5955        if (!values.isEmpty()) {
    60             ClipboardUtils.copyString(Utils.join("\n", values));
     56            ClipboardUtils.copyString(values);
    6157        }
    6258    }
Note: See TracChangeset for help on using the changeset viewer.