Changeset 10638 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2016-07-25T21:19:38+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390, fix #13206 - Migrate Function interface to java 8 (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Lanes.java

    r10608 r10638  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.ArrayList;
    76import java.util.Arrays;
    8 import java.util.Collection;
    9 import java.util.HashSet;
    107import java.util.Set;
    11 import java.util.regex.Pattern;
     8import java.util.stream.Collectors;
    129
    1310import org.openstreetmap.josm.Main;
     
    1613import org.openstreetmap.josm.data.validation.Test;
    1714import org.openstreetmap.josm.data.validation.TestError;
    18 import org.openstreetmap.josm.tools.Predicates;
    1915import org.openstreetmap.josm.tools.Utils;
    20 import org.openstreetmap.josm.tools.Utils.Function;
    2116
    2217/**
     
    4540
    4641    protected void checkNumberOfLanesByKey(final OsmPrimitive p, String lanesKey, String message) {
    47         final Collection<String> keysForPattern = new ArrayList<>(Utils.filter(p.keySet(),
    48                 Predicates.stringContainsPattern(Pattern.compile(':' + lanesKey + '$'))));
    49         keysForPattern.removeAll(Arrays.asList(BLACKLIST));
    50         if (keysForPattern.isEmpty()) {
    51             // nothing to check
    52             return;
    53         }
    54         final Set<Integer> lanesCount = new HashSet<>(Utils.transform(keysForPattern,
    55                 (Function<String, Integer>) key -> getLanesCount(p.get(key))));
     42        final Set<Integer> lanesCount =
     43                p.keySet().stream()
     44                .filter(x -> x.endsWith(":" + lanesKey))
     45                .filter(x -> !Arrays.asList(BLACKLIST).contains(x))
     46                .map(key -> getLanesCount(p.get(key)))
     47                .collect(Collectors.toSet());
     48
    5649        if (lanesCount.size() > 1) {
    5750            // if not all numbers are the same
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

    r10608 r10638  
    1212import java.util.List;
    1313import java.util.Map;
     14import java.util.stream.Collectors;
    1415
    1516import org.openstreetmap.josm.command.Command;
     
    2930import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role;
    3031import org.openstreetmap.josm.tools.Utils;
    31 import org.openstreetmap.josm.tools.Utils.Function;
    3232
    3333/**
     
    256256
    257257            // convert in localization friendly way to string of accepted types
    258             String typesStr = Utils.join("/", Utils.transform(types, (Function<TaggingPresetType, Object>) x -> tr(x.getName())));
     258            String typesStr = types.stream().map(x -> tr(x.getName())).collect(Collectors.joining("/"));
    259259
    260260            errors.add(new TestError(this, Severity.WARNING, ROLE_VERIF_PROBLEM_MSG,
     
    293293        for (String key : map.keySet()) {
    294294            if (!allroles.containsKey(key)) {
    295                 String templates = Utils.join("/", Utils.transform(allroles.keySet(), (Function<String, Object>) x -> tr(x)));
     295                String templates = allroles.keySet().stream().map(x -> tr(x)).collect(Collectors.joining("/"));
    296296
    297297                if (!key.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r10634 r10638  
    1919import java.util.Map;
    2020import java.util.Set;
     21import java.util.stream.Collectors;
    2122
    2223import org.openstreetmap.josm.Main;
     
    4243import org.openstreetmap.josm.tools.I18n;
    4344import org.openstreetmap.josm.tools.Utils;
    44 import org.openstreetmap.josm.tools.Utils.Function;
    4545
    4646/**
     
    631631     */
    632632    public String formatAsHtmlUnorderedList(Collection<? extends OsmPrimitive> primitives, int maxElements) {
    633         final Collection<String> displayNames = Utils.transform(primitives,
    634                 (Function<OsmPrimitive, String>) x -> x.getDisplayName(this));
     633        Collection<String> displayNames = primitives.stream().map(x -> x.getDisplayName(this)).collect(Collectors.toList());
    635634        return Utils.joinAsHtmlUnorderedList(Utils.limit(displayNames, maxElements, "..."));
    636635    }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java

    r10611 r10638  
    2222import java.util.List;
    2323import java.util.Set;
     24import java.util.stream.Collectors;
    2425
    2526import javax.swing.AbstractAction;
     
    4849import org.openstreetmap.josm.tools.CheckParameterUtil;
    4950import org.openstreetmap.josm.tools.ImageProvider;
     51import org.openstreetmap.josm.tools.StreamUtils;
    5052import org.openstreetmap.josm.tools.UserCancelException;
    51 import org.openstreetmap.josm.tools.Utils;
    52 import org.openstreetmap.josm.tools.Utils.Function;
    5353import org.openstreetmap.josm.tools.WindowGeometry;
    5454
     
    569569            final Collection<? extends OsmPrimitive> primitives,
    570570            final TagCollection normalizedTags) throws UserCancelException {
    571         String conflicts = Utils.joinAsHtmlUnorderedList(Utils.transform(normalizedTags.getKeysWithMultipleValues(),
    572                 (Function<String, String>) key -> tr("{0} ({1})", key, Utils.join(tr(", "), Utils.transform(normalizedTags.getValues(key),
    573                         (Function<String, String>) x -> x == null || x.isEmpty() ? tr("<i>missing</i>") : x)))));
     571        String conflicts = normalizedTags.getKeysWithMultipleValues().stream().map(
     572                key -> getKeyDescription(key, normalizedTags)).collect(StreamUtils.toHtmlList());
    574573        String msg = /* for correct i18n of plural forms - see #9110 */ trn("You are about to combine {0} objects, "
    575574                + "but the following tags are used conflictingly:<br/>{1}"
     
    594593        }
    595594    }
     595
     596    private static String getKeyDescription(String key, TagCollection normalizedTags) {
     597        String values = normalizedTags.getValues(key)
     598                .stream()
     599                .map(x -> ((x == null || x.isEmpty()) ? tr("<i>missing</i>") : x))
     600                .collect(Collectors.joining(tr(", ")));
     601        return tr("{0} ({1})", key, values);
     602    }
    596603}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/OsmIdSelectionDialog.java

    r10611 r10638  
    1313import java.util.Collection;
    1414import java.util.Collections;
    15 import java.util.EnumSet;
    1615import java.util.LinkedList;
    1716import java.util.List;
    1817import java.util.Set;
     18import java.util.stream.Collectors;
    1919
    2020import javax.swing.BorderFactory;
     
    3939import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox;
    4040import org.openstreetmap.josm.tools.Utils;
    41 import org.openstreetmap.josm.tools.Utils.Function;
    4241
    4342/**
     
    204203        final List<SimplePrimitiveId> ids = SimplePrimitiveId.fuzzyParse(buf);
    205204        if (!ids.isEmpty()) {
    206             final String parsedText = Utils.join(", ", Utils.transform(ids,
    207                     (Function<SimplePrimitiveId, String>) x -> x.getType().getAPIName().charAt(0) + String.valueOf(x.getUniqueId())));
     205            final String parsedText = ids.stream().map(x -> x.getType().getAPIName().charAt(0) + String.valueOf(x.getUniqueId()))
     206                    .collect(Collectors.joining(", "));
    208207            tfId.tryToPasteFrom(parsedText);
    209             final Set<OsmPrimitiveType> types = EnumSet.copyOf(Utils.transform(ids,
    210                     (Function<SimplePrimitiveId, OsmPrimitiveType>) x -> x.getType()));
     208            final Set<OsmPrimitiveType> types = ids.stream().map(x -> x.getType()).collect(Collectors.toSet());
    211209            if (types.size() == 1) {
    212210                // select corresponding type
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r10611 r10638  
    1717import java.util.List;
    1818import java.util.Set;
     19import java.util.stream.Collectors;
    1920
    2021import javax.swing.AbstractAction;
     
    5354import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    5455import org.openstreetmap.josm.tools.ImageProvider;
    55 import org.openstreetmap.josm.tools.Utils;
    56 import org.openstreetmap.josm.tools.Utils.Function;
    5756import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    5857
     
    301300        @Override
    302301        public void actionPerformed(ActionEvent arg0) {
    303             final List<PrimitiveId> primitiveIds = new ArrayList<>(Utils.transform(
    304                     model.getSelectedPrimitives(), (Function<HistoryOsmPrimitive, PrimitiveId>) x -> x.getPrimitiveId()));
     302            final List<PrimitiveId> primitiveIds = model.getSelectedPrimitives().stream().map(x -> x.getPrimitiveId())
     303                    .collect(Collectors.toList());
    305304            Main.worker.submit(new DownloadPrimitivesWithReferrersTask(false, primitiveIds, true, true, null, null));
    306305        }
  • trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java

    r10615 r10638  
    77import java.text.MessageFormat;
    88import java.text.ParseException;
    9 import java.util.Arrays;
    109import java.util.Collection;
    1110import java.util.Collections;
    1211import java.util.Date;
    1312import java.util.HashMap;
    14 import java.util.HashSet;
    1513import java.util.Map;
    1614import java.util.Map.Entry;
     15import java.util.stream.Collectors;
     16import java.util.stream.Stream;
    1717
    1818import org.openstreetmap.josm.Main;
     
    2121import org.openstreetmap.josm.tools.CheckParameterUtil;
    2222import org.openstreetmap.josm.tools.Utils;
    23 import org.openstreetmap.josm.tools.Utils.Function;
    2423import org.openstreetmap.josm.tools.date.DateUtils;
    2524
     
    405404
    406405        protected Collection<Long> parseLongs(String value) {
    407             return value == null || value.isEmpty()
    408                     ? Collections.<Long>emptySet() :
    409                     new HashSet<>(Utils.transform(Arrays.asList(value.split(",")), (Function<String, Long>) x -> Long.valueOf(x)));
     406            if (value == null || value.isEmpty()) {
     407                return Collections.<Long>emptySet();
     408            } else {
     409                return Stream.of(value.split(",")).map(Long::valueOf).collect(Collectors.toSet());
     410            }
    410411        }
    411412
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r10615 r10638  
    180180        return buildRootUrl() + "FORMAT=" + format + (imageFormatHasTransparency(format) ? "&TRANSPARENT=TRUE" : "")
    181181                + "&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS="
    182                 + Utils.join(",", Utils.transform(selectedLayers, x -> x.ident))
     182                + selectedLayers.stream().map(x -> x.ident).collect(Collectors.joining(","))
    183183                + "&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}";
    184184    }
  • trunk/src/org/openstreetmap/josm/tools/StreamUtils.java

    r10585 r10638  
    22package org.openstreetmap.josm.tools;
    33
     4import java.util.EnumSet;
    45import java.util.Iterator;
     6import java.util.Set;
    57import java.util.Spliterator;
    68import java.util.Spliterators;
     9import java.util.function.BiConsumer;
     10import java.util.function.BinaryOperator;
     11import java.util.function.Function;
     12import java.util.function.Supplier;
     13import java.util.stream.Collector;
    714import java.util.stream.Stream;
    815import java.util.stream.StreamSupport;
     
    1421 */
    1522public final class StreamUtils {
     23
     24    private static final class HtmlListCollector implements Collector<String, StringBuilder, String> {
     25        @Override
     26        public Supplier<StringBuilder> supplier() {
     27            return StringBuilder::new;
     28        }
     29
     30        @Override
     31        public BiConsumer<StringBuilder, String> accumulator() {
     32            return (sb, item) -> sb.append("<li>").append(item).append("</li>");
     33        }
     34
     35        @Override
     36        public BinaryOperator<StringBuilder> combiner() {
     37            return StringBuilder::append;
     38        }
     39
     40        @Override
     41        public Function<StringBuilder, String> finisher() {
     42            return sb -> "<ul>" + sb.toString() + "</ul>";
     43        }
     44
     45        @Override
     46        public Set<Characteristics> characteristics() {
     47            return EnumSet.of(Characteristics.CONCURRENT);
     48        }
     49    }
    1650
    1751    /**
     
    3064        return StreamSupport.stream(spliterator, false);
    3165    }
     66
     67    /**
     68     * Creates a new Collector that collects the items and returns them as HTML unordered list.
     69     * @return The collector.
     70     * @since 10638
     71     */
     72    public static Collector<String, ?, String> toHtmlList() {
     73        return new HtmlListCollector();
     74    }
    3275}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r10627 r10638  
    327327     */
    328328    public static String joinAsHtmlUnorderedList(Iterable<?> values) {
    329         StringBuilder sb = new StringBuilder(1024);
    330         sb.append("<ul>");
    331         for (Object i : values) {
    332             sb.append("<li>").append(i).append("</li>");
    333         }
    334         sb.append("</ul>");
    335         return sb.toString();
     329        return StreamUtils.toStream(values.iterator()).map(x -> x.toString()).collect(StreamUtils.toHtmlList());
    336330    }
    337331
Note: See TracChangeset for help on using the changeset viewer.