Changeset 16270 in josm
- Timestamp:
- 2020-04-12T14:55:07+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/TagInfoExtract.java
r16269 r16270 20 20 import java.util.Collections; 21 21 import java.util.EnumSet; 22 import java.util.LinkedHashMap; 22 23 import java.util.List; 23 24 import java.util.Locale; 25 import java.util.Map; 24 26 import java.util.Optional; 25 27 import java.util.Set; … … 27 29 import java.util.regex.Pattern; 28 30 import java.util.stream.Collectors; 31 import java.util.stream.Stream; 29 32 30 33 import javax.imageio.ImageIO; … … 69 72 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; 70 73 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType; 74 import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup; 71 75 import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem; 72 76 import org.openstreetmap.josm.io.CachedFile; … … 262 266 List<TagInfoTag> convertPresets(Iterable<TaggingPreset> presets, String descriptionPrefix, boolean addImages) { 263 267 final List<TagInfoTag> tags = new ArrayList<>(); 268 final Map<Tag, TagInfoTag> optionalTags = new LinkedHashMap<>(); 264 269 for (TaggingPreset preset : presets) { 265 for (KeyedItem item : Utils.filteredCollection(preset.data, KeyedItem.class)) { 266 final Iterable<String> values = item.isKeyRequired() 267 ? item.getValues() 268 : Collections.emptyList(); 269 for (String value : values) { 270 final Set<TagInfoTag.Type> types = TagInfoTag.Type.forPresetTypes(preset.types); 271 tags.add(new TagInfoTag(descriptionPrefix + preset.getName(), item.key, value, types, 272 addImages && preset.iconName != null ? options.findImageUrl(preset.iconName) : null)); 273 } 274 } 275 } 270 preset.data.stream() 271 .flatMap(item -> item instanceof KeyedItem 272 ? Stream.of(((KeyedItem) item)) 273 : item instanceof CheckGroup 274 ? ((CheckGroup) item).checks.stream() 275 : Stream.empty()) 276 .forEach(item -> { 277 for (String value : item.getValues()) { 278 Set<TagInfoTag.Type> types = TagInfoTag.Type.forPresetTypes(preset.types); 279 if (item.isKeyRequired()) { 280 tags.add(new TagInfoTag(descriptionPrefix + preset.getName(), item.key, value, types, 281 addImages && preset.iconName != null ? options.findImageUrl(preset.iconName) : null)); 282 } else { 283 optionalTags.compute(new Tag(item.key, value), (osmTag, tagInfoTag) -> { 284 if (tagInfoTag == null) { 285 String description = descriptionPrefix + "Optional for: " + preset.getName(); 286 return new TagInfoTag(description, item.key, value, types, null); 287 } else { 288 tagInfoTag.descriptions.add(preset.getName()); 289 tagInfoTag.objectTypes.addAll(types); 290 return tagInfoTag; 291 } 292 }); 293 } 294 } 295 }); 296 } 297 tags.addAll(optionalTags.values()); 276 298 return tags; 277 299 } … … 524 546 */ 525 547 private static class TagInfoTag { 526 final Stringdescription;548 final Collection<String> descriptions = new ArrayList<>(); 527 549 final String key; 528 550 final String value; … … 531 553 532 554 TagInfoTag(String description, String key, String value, Set<Type> objectTypes, String iconURL) { 533 this.description = description; 555 if (description != null) { 556 this.descriptions.add(description); 557 } 534 558 this.key = key; 535 559 this.value = value; … … 540 564 JsonObjectBuilder toJson() { 541 565 final JsonObjectBuilder object = Json.createObjectBuilder(); 542 if (description != null) {543 object.add("description", description); 566 if (!descriptions.isEmpty()) { 567 object.add("description", String.join(", ", Utils.limit(descriptions, 8, "..."))); 544 568 } 545 569 object.add("key", key);
Note:
See TracChangeset
for help on using the changeset viewer.