diff --git a/src/org/openstreetmap/josm/data/validation/tests/Lanes.java b/src/org/openstreetmap/josm/data/validation/tests/Lanes.java
index 976fac9..ed3ab5b 100644
|
a
|
b
|
package org.openstreetmap.josm.data.validation.tests;
|
| 3 | 3 | |
| 4 | 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | 5 | |
| 6 | | import java.util.ArrayList; |
| 7 | 6 | import java.util.Arrays; |
| 8 | | import java.util.Collection; |
| 9 | | import java.util.HashSet; |
| | 7 | import java.util.List; |
| 10 | 8 | import java.util.Set; |
| 11 | | import java.util.regex.Pattern; |
| | 9 | import java.util.stream.Collectors; |
| 12 | 10 | |
| 13 | 11 | import org.openstreetmap.josm.Main; |
| 14 | 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
| 15 | 13 | import org.openstreetmap.josm.data.validation.Severity; |
| 16 | 14 | import org.openstreetmap.josm.data.validation.Test; |
| 17 | 15 | import org.openstreetmap.josm.data.validation.TestError; |
| 18 | | import org.openstreetmap.josm.tools.Predicates; |
| 19 | 16 | import org.openstreetmap.josm.tools.Utils; |
| 20 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 21 | 17 | |
| 22 | 18 | /** |
| 23 | 19 | * Test that validates {@code lane:} tags. |
| … |
… |
public class Lanes extends Test.TagTest {
|
| 44 | 40 | } |
| 45 | 41 | |
| 46 | 42 | 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)))); |
| | 43 | List<String> blacklist = Arrays.asList(BLACKLIST); |
| | 44 | final Set<Integer> lanesCount = |
| | 45 | p.keySet().stream() |
| | 46 | .filter(x -> x.endsWith(":" + lanesKey)) |
| | 47 | .filter(x -> !blacklist.contains(x)) |
| | 48 | .map(key -> getLanesCount(p.get(key))) |
| | 49 | .collect(Collectors.toSet()); |
| | 50 | |
| 56 | 51 | if (lanesCount.size() > 1) { |
| 57 | 52 | // if not all numbers are the same |
| 58 | 53 | errors.add(new TestError(this, Severity.WARNING, message, 3100, p)); |
diff --git a/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java b/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
index 8c93790..28c3fa6 100644
|
a
|
b
|
import java.util.HashMap;
|
| 11 | 11 | import java.util.LinkedList; |
| 12 | 12 | import java.util.List; |
| 13 | 13 | import java.util.Map; |
| | 14 | import java.util.stream.Collectors; |
| 14 | 15 | |
| 15 | 16 | import org.openstreetmap.josm.command.Command; |
| 16 | 17 | import org.openstreetmap.josm.command.DeleteCommand; |
| … |
… |
import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
|
| 28 | 29 | import org.openstreetmap.josm.gui.tagging.presets.items.Roles; |
| 29 | 30 | import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role; |
| 30 | 31 | import org.openstreetmap.josm.tools.Utils; |
| 31 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Check for wrong relations. |
| … |
… |
public class RelationChecker extends Test {
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // 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("/")); |
| 259 | 259 | |
| 260 | 260 | errors.add(new TestError(this, Severity.WARNING, ROLE_VERIF_PROBLEM_MSG, |
| 261 | 261 | tr(s, member.getType(), typesStr, rolePreset.name), s, WRONG_TYPE, |
| … |
… |
public class RelationChecker extends Test {
|
| 292 | 292 | // verify unwanted members |
| 293 | 293 | for (String key : map.keySet()) { |
| 294 | 294 | 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("/")); |
| 296 | 296 | |
| 297 | 297 | if (!key.isEmpty()) { |
| 298 | 298 | String s = marktr("Role {0} unknown in templates {1}"); |
diff --git a/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java b/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
index 5b9e3ce..bef4acd 100644
|
a
|
b
|
import java.util.List;
|
| 18 | 18 | import java.util.Locale; |
| 19 | 19 | import java.util.Map; |
| 20 | 20 | import java.util.Set; |
| | 21 | import java.util.stream.Collectors; |
| 21 | 22 | |
| 22 | 23 | import org.openstreetmap.josm.Main; |
| 23 | 24 | import org.openstreetmap.josm.data.coor.CoordinateFormat; |
| … |
… |
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetNameTemplateList;
|
| 41 | 42 | import org.openstreetmap.josm.tools.AlphanumComparator; |
| 42 | 43 | import org.openstreetmap.josm.tools.I18n; |
| 43 | 44 | import org.openstreetmap.josm.tools.Utils; |
| 44 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * This is the default implementation of a {@link NameFormatter} for names of {@link OsmPrimitive}s |
| … |
… |
public class DefaultNameFormatter implements NameFormatter, HistoryNameFormatter
|
| 630 | 630 | * @return HTML unordered list |
| 631 | 631 | */ |
| 632 | 632 | 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()); |
| 635 | 634 | return Utils.joinAsHtmlUnorderedList(Utils.limit(displayNames, maxElements, "...")); |
| 636 | 635 | } |
| 637 | 636 | |
diff --git a/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java b/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
index 58704b1..3ba2d10 100644
|
a
|
b
|
import java.util.Collection;
|
| 21 | 21 | import java.util.LinkedList; |
| 22 | 22 | import java.util.List; |
| 23 | 23 | import java.util.Set; |
| | 24 | import java.util.stream.Collectors; |
| 24 | 25 | |
| 25 | 26 | import javax.swing.AbstractAction; |
| 26 | 27 | import javax.swing.Action; |
| … |
… |
import org.openstreetmap.josm.gui.help.HelpUtil;
|
| 47 | 48 | import org.openstreetmap.josm.gui.util.GuiHelper; |
| 48 | 49 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
| 49 | 50 | import org.openstreetmap.josm.tools.ImageProvider; |
| | 51 | import org.openstreetmap.josm.tools.StreamUtils; |
| 50 | 52 | import org.openstreetmap.josm.tools.UserCancelException; |
| 51 | | import org.openstreetmap.josm.tools.Utils; |
| 52 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 53 | 53 | import org.openstreetmap.josm.tools.WindowGeometry; |
| 54 | 54 | |
| 55 | 55 | /** |
| … |
… |
public class CombinePrimitiveResolverDialog extends JDialog {
|
| 568 | 568 | protected static void informAboutTagConflicts( |
| 569 | 569 | final Collection<? extends OsmPrimitive> primitives, |
| 570 | 570 | 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()); |
| 574 | 573 | String msg = /* for correct i18n of plural forms - see #9110 */ trn("You are about to combine {0} objects, " |
| 575 | 574 | + "but the following tags are used conflictingly:<br/>{1}" |
| 576 | 575 | + "If these objects are combined, the resulting object may have unwanted tags.<br/>" |
| … |
… |
public class CombinePrimitiveResolverDialog extends JDialog {
|
| 593 | 592 | throw new UserCancelException(); |
| 594 | 593 | } |
| 595 | 594 | } |
| | 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 | } |
| 596 | 603 | } |
diff --git a/src/org/openstreetmap/josm/gui/dialogs/OsmIdSelectionDialog.java b/src/org/openstreetmap/josm/gui/dialogs/OsmIdSelectionDialog.java
index 712ce01..5f9f246 100644
|
a
|
b
|
import java.awt.event.WindowListener;
|
| 12 | 12 | import java.util.Arrays; |
| 13 | 13 | import java.util.Collection; |
| 14 | 14 | import java.util.Collections; |
| 15 | | import java.util.EnumSet; |
| 16 | 15 | import java.util.LinkedList; |
| 17 | 16 | import java.util.List; |
| 18 | 17 | import java.util.Set; |
| | 18 | import java.util.stream.Collectors; |
| 19 | 19 | |
| 20 | 20 | import javax.swing.BorderFactory; |
| 21 | 21 | import javax.swing.GroupLayout; |
| … |
… |
import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
| 38 | 38 | import org.openstreetmap.josm.gui.widgets.OsmIdTextField; |
| 39 | 39 | import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox; |
| 40 | 40 | import org.openstreetmap.josm.tools.Utils; |
| 41 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 42 | 41 | |
| 43 | 42 | /** |
| 44 | 43 | * Dialog prompt to user to let him choose OSM primitives by specifying their type and IDs. |
| … |
… |
public class OsmIdSelectionDialog extends ExtendedDialog implements WindowListen
|
| 203 | 202 | if (buf.length() > Main.pref.getInteger("downloadprimitive.max-autopaste-length", 2000)) return; |
| 204 | 203 | final List<SimplePrimitiveId> ids = SimplePrimitiveId.fuzzyParse(buf); |
| 205 | 204 | 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(", ")); |
| 208 | 207 | 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()); |
| 211 | 209 | if (types.size() == 1) { |
| 212 | 210 | // select corresponding type |
| 213 | 211 | cbType.setSelectedItem(types.iterator().next()); |
diff --git a/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java b/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
index 7b721e4..658678d 100644
|
a
|
b
|
import java.util.Collection;
|
| 16 | 16 | import java.util.HashSet; |
| 17 | 17 | import java.util.List; |
| 18 | 18 | import java.util.Set; |
| | 19 | import java.util.stream.Collectors; |
| 19 | 20 | |
| 20 | 21 | import javax.swing.AbstractAction; |
| 21 | 22 | import javax.swing.BorderFactory; |
| … |
… |
import org.openstreetmap.josm.gui.util.GuiHelper;
|
| 52 | 53 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel; |
| 53 | 54 | import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; |
| 54 | 55 | import org.openstreetmap.josm.tools.ImageProvider; |
| 55 | | import org.openstreetmap.josm.tools.Utils; |
| 56 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 57 | 56 | import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; |
| 58 | 57 | |
| 59 | 58 | /** |
| … |
… |
public class ChangesetContentPanel extends JPanel implements PropertyChangeListe
|
| 300 | 299 | |
| 301 | 300 | @Override |
| 302 | 301 | 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()); |
| 305 | 304 | Main.worker.submit(new DownloadPrimitivesWithReferrersTask(false, primitiveIds, true, true, null, null)); |
| 306 | 305 | } |
| 307 | 306 | |
diff --git a/src/org/openstreetmap/josm/io/ChangesetQuery.java b/src/org/openstreetmap/josm/io/ChangesetQuery.java
index 687c9e7..9c6228d 100644
|
a
|
b
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
| 6 | 6 | import java.text.DateFormat; |
| 7 | 7 | import java.text.MessageFormat; |
| 8 | 8 | import java.text.ParseException; |
| 9 | | import java.util.Arrays; |
| 10 | 9 | import java.util.Collection; |
| 11 | 10 | import java.util.Collections; |
| 12 | 11 | import java.util.Date; |
| 13 | 12 | import java.util.HashMap; |
| 14 | | import java.util.HashSet; |
| 15 | 13 | import java.util.Map; |
| 16 | 14 | import java.util.Map.Entry; |
| | 15 | import java.util.stream.Collectors; |
| | 16 | import java.util.stream.Stream; |
| 17 | 17 | |
| 18 | 18 | import org.openstreetmap.josm.Main; |
| 19 | 19 | import org.openstreetmap.josm.data.Bounds; |
| 20 | 20 | import org.openstreetmap.josm.data.coor.LatLon; |
| 21 | 21 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
| 22 | 22 | import org.openstreetmap.josm.tools.Utils; |
| 23 | | import org.openstreetmap.josm.tools.Utils.Function; |
| 24 | 23 | import org.openstreetmap.josm.tools.date.DateUtils; |
| 25 | 24 | |
| 26 | 25 | public class ChangesetQuery { |
| … |
… |
public class ChangesetQuery {
|
| 404 | 403 | } |
| 405 | 404 | |
| 406 | 405 | 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 | } |
| 410 | 411 | } |
| 411 | 412 | |
| 412 | 413 | protected ChangesetQuery createFromMap(Map<String, String> queryParams) throws ChangesetQueryUrlException { |
diff --git a/src/org/openstreetmap/josm/io/imagery/WMSImagery.java b/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
index 4f9c6a4..4cae411 100644
|
a
|
b
|
public class WMSImagery {
|
| 179 | 179 | public String buildGetMapUrl(Collection<LayerDetails> selectedLayers, String format) { |
| 180 | 180 | return buildRootUrl() + "FORMAT=" + format + (imageFormatHasTransparency(format) ? "&TRANSPARENT=TRUE" : "") |
| 181 | 181 | + "&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(",")) |
| 183 | 183 | + "&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}"; |
| 184 | 184 | } |
| 185 | 185 | |
diff --git a/src/org/openstreetmap/josm/tools/StreamUtils.java b/src/org/openstreetmap/josm/tools/StreamUtils.java
index 8f39c48..42a7997 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.tools; |
| 3 | 3 | |
| | 4 | import java.util.EnumSet; |
| 4 | 5 | import java.util.Iterator; |
| | 6 | import java.util.Set; |
| 5 | 7 | import java.util.Spliterator; |
| 6 | 8 | import java.util.Spliterators; |
| | 9 | import java.util.function.BiConsumer; |
| | 10 | import java.util.function.BinaryOperator; |
| | 11 | import java.util.function.Function; |
| | 12 | import java.util.function.Supplier; |
| | 13 | import java.util.stream.Collector; |
| 7 | 14 | import java.util.stream.Stream; |
| 8 | 15 | import java.util.stream.StreamSupport; |
| 9 | 16 | |
| … |
… |
import java.util.stream.StreamSupport;
|
| 14 | 21 | */ |
| 15 | 22 | public final class StreamUtils { |
| 16 | 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 | } |
| | 50 | |
| 17 | 51 | /** |
| 18 | 52 | * Utility class |
| 19 | 53 | */ |
| … |
… |
public final class StreamUtils {
|
| 29 | 63 | Spliterator<T> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED); |
| 30 | 64 | return StreamSupport.stream(spliterator, false); |
| 31 | 65 | } |
| | 66 | |
| | 67 | /** |
| | 68 | * Creates a new Collector that collects the items and returns them as HTML unordered list. |
| | 69 | * @return The collector. |
| | 70 | */ |
| | 71 | public static Collector<String, ?, String> toHtmlList() { |
| | 72 | return new HtmlListCollector(); |
| | 73 | } |
| 32 | 74 | } |
diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java
index cd25da4..1fd0efd 100644
|
a
|
b
|
public final class Utils {
|
| 326 | 326 | * @return An unordered HTML list |
| 327 | 327 | */ |
| 328 | 328 | 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()); |
| 336 | 330 | } |
| 337 | 331 | |
| 338 | 332 | /** |
diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/PresetClassificationsTest.java
index 72959f0..9a4625c 100644
|
a
|
b
|
import java.util.Collection;
|
| 9 | 9 | import java.util.Collections; |
| 10 | 10 | import java.util.EnumSet; |
| 11 | 11 | import java.util.List; |
| | 12 | import java.util.stream.Collectors; |
| 12 | 13 | |
| 13 | 14 | import org.junit.BeforeClass; |
| 14 | 15 | import org.junit.Test; |
| … |
… |
import org.openstreetmap.josm.data.osm.OsmUtils;
|
| 19 | 20 | import org.openstreetmap.josm.data.osm.Way; |
| 20 | 21 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector.PresetClassification; |
| 21 | 22 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector.PresetClassifications; |
| 22 | | import org.openstreetmap.josm.tools.Utils; |
| 23 | 23 | import org.xml.sax.SAXException; |
| 24 | 24 | |
| 25 | 25 | /** |
| … |
… |
public class PresetClassificationsTest {
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | private List<String> getMatchingPresetNames(String searchText, OsmPrimitive w) { |
| 50 | | return Utils.transform(getMatchingPresets(searchText, w), new Utils.Function<PresetClassification, String>() { |
| 51 | | @Override |
| 52 | | public String apply(PresetClassification x) { |
| 53 | | return x.preset.name; |
| 54 | | } |
| 55 | | }); |
| | 50 | return getMatchingPresets(searchText, w).stream().map(x -> x.preset.name).collect(Collectors.toList()); |
| 56 | 51 | } |
| 57 | 52 | |
| 58 | 53 | /** |
diff --git a/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java b/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReaderTest.java
index 2162b62..9b3a163 100644
|
a
|
b
|
package org.openstreetmap.josm.gui.tagging.presets;
|
| 4 | 4 | import static org.CustomMatchers.hasSize; |
| 5 | 5 | import static org.junit.Assert.assertEquals; |
| 6 | 6 | import static org.junit.Assert.assertThat; |
| | 7 | import static org.junit.Assert.assertTrue; |
| 7 | 8 | |
| 8 | 9 | import java.io.IOException; |
| 9 | 10 | import java.util.Collection; |
| 10 | 11 | import java.util.List; |
| | 12 | import java.util.stream.Collectors; |
| 11 | 13 | |
| 12 | 14 | import org.junit.Assert; |
| 13 | 15 | import org.junit.BeforeClass; |
| … |
… |
import org.openstreetmap.josm.JOSMFixture;
|
| 16 | 18 | import org.openstreetmap.josm.TestUtils; |
| 17 | 19 | import org.openstreetmap.josm.gui.tagging.presets.items.Check; |
| 18 | 20 | import org.openstreetmap.josm.gui.tagging.presets.items.Key; |
| 19 | | import org.openstreetmap.josm.tools.Utils; |
| 20 | 21 | import org.xml.sax.SAXException; |
| 21 | 22 | |
| 22 | 23 | /** |
| … |
… |
public class TaggingPresetReaderTest {
|
| 58 | 59 | final Collection<TaggingPreset> presets = TaggingPresetReader.readAll(TestUtils.getTestDataRoot() + "preset_chunk.xml", true); |
| 59 | 60 | assertThat(presets, hasSize(1)); |
| 60 | 61 | final TaggingPreset abc = presets.iterator().next(); |
| 61 | | final List<String> keys = Utils.transform(abc.data, new Utils.Function<TaggingPresetItem, String>() { |
| 62 | | @Override |
| 63 | | public String apply(TaggingPresetItem x) { |
| 64 | | return x instanceof Key ? ((Key) x).key : null; |
| 65 | | } |
| 66 | | }); |
| | 62 | assertTrue(abc.data.stream().allMatch(Key.class::isInstance)); |
| | 63 | final List<String> keys = abc.data.stream().map(x -> ((Key) x).key).collect(Collectors.toList()); |
| 67 | 64 | assertEquals("[A1, A2, A3, B1, B2, B3, C1, C2, C3]", keys.toString()); |
| 68 | 65 | } |
| 69 | 66 | |
diff --git a/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java b/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java
index 54112ac..996e6c2 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.io; |
| 3 | 3 | |
| 4 | | import static org.junit.Assert.assertEquals; |
| | 4 | import static org.junit.Assert.assertArrayEquals; |
| 5 | 5 | |
| 6 | 6 | import java.util.ArrayList; |
| 7 | 7 | import java.util.Arrays; |
| … |
… |
import java.util.List;
|
| 10 | 10 | |
| 11 | 11 | import org.junit.Test; |
| 12 | 12 | import org.openstreetmap.josm.data.osm.NodeData; |
| 13 | | import org.openstreetmap.josm.tools.Utils; |
| 14 | 13 | |
| 15 | 14 | /** |
| 16 | 15 | * Unit tests of {@link OsmWriter} class. |
| … |
… |
public class OsmWriterTest {
|
| 32 | 31 | |
| 33 | 32 | Collections.sort(ids, OsmWriter.byIdComparator); |
| 34 | 33 | |
| 35 | | final String idsAsString = Utils.transform(ids, new Utils.Function<NodeData, Object>() { |
| 36 | | @Override |
| 37 | | public Object apply(NodeData x) { |
| 38 | | return x.getUniqueId(); |
| 39 | | } |
| 40 | | }).toString(); |
| 41 | | |
| 42 | | assertEquals("[-3, -12, -20, -9223372036854775808, 0, 2, 12, 65, 9223372036854775807]", idsAsString); |
| | 34 | final long[] longIds = ids.stream().mapToLong(x -> x.getUniqueId()).toArray(); |
| | 35 | assertArrayEquals(new long[] { |
| | 36 | -3, -12, -20, -9223372036854775808l, 0, 2, 12, 65, 9223372036854775807l |
| | 37 | }, longIds); |
| 43 | 38 | } |
| 44 | 39 | } |
diff --git a/test/unit/org/openstreetmap/josm/tools/UtilsTest.java b/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
index cbe2b8b..2025389 100644
|
a
|
b
|
import java.io.BufferedReader;
|
| 7 | 7 | import java.io.IOException; |
| 8 | 8 | import java.net.URL; |
| 9 | 9 | import java.util.Arrays; |
| | 10 | import java.util.Collections; |
| | 11 | import java.util.List; |
| 10 | 12 | import java.util.Locale; |
| 11 | 13 | |
| 12 | 14 | import org.junit.Assert; |
| … |
… |
public class UtilsTest {
|
| 192 | 194 | Utils.getSizeString(-1, Locale.ENGLISH); |
| 193 | 195 | } |
| 194 | 196 | |
| | 197 | /** |
| | 198 | * Test {@link Utils#joinAsHtmlUnorderedList(Iterable)} |
| | 199 | */ |
| | 200 | @Test |
| | 201 | public void joinAsHtmlUnorderedList() { |
| | 202 | List<? extends Object> items = Arrays.asList("1", new Integer(2)); |
| | 203 | assertEquals("<ul><li>1</li><li>2</li></ul>", Utils.joinAsHtmlUnorderedList(items)); |
| | 204 | assertEquals("<ul></ul>", Utils.joinAsHtmlUnorderedList(Collections.emptyList())); |
| | 205 | } |
| | 206 | |
| 195 | 207 | } |