Changeset 10638 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-07-25T21:19:38+02:00 (8 years ago)
- 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 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;10 7 import java.util.Set; 11 import java.util. regex.Pattern;8 import java.util.stream.Collectors; 12 9 13 10 import org.openstreetmap.josm.Main; … … 16 13 import org.openstreetmap.josm.data.validation.Test; 17 14 import org.openstreetmap.josm.data.validation.TestError; 18 import org.openstreetmap.josm.tools.Predicates;19 15 import org.openstreetmap.josm.tools.Utils; 20 import org.openstreetmap.josm.tools.Utils.Function;21 16 22 17 /** … … 45 40 46 41 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 56 49 if (lanesCount.size() > 1) { 57 50 // if not all numbers are the same -
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r10608 r10638 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; … … 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 /** … … 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, … … 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()) { -
trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
r10634 r10638 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; … … 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 /** … … 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 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/CombinePrimitiveResolverDialog.java
r10611 r10638 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; … … 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 … … 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}" … … 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 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/OsmIdSelectionDialog.java
r10611 r10638 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; … … 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 /** … … 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 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
r10611 r10638 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; … … 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 … … 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 } -
trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java
r10615 r10638 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; … … 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 … … 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 -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r10615 r10638 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 } -
trunk/src/org/openstreetmap/josm/tools/StreamUtils.java
r10585 r10638 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; … … 14 21 */ 15 22 public 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 } 16 50 17 51 /** … … 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 * @since 10638 71 */ 72 public static Collector<String, ?, String> toHtmlList() { 73 return new HtmlListCollector(); 74 } 32 75 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10627 r10638 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
Note:
See TracChangeset
for help on using the changeset viewer.