Changeset 17876 in josm


Ignore:
Timestamp:
2021-05-06T22:37:43+02:00 (3 years ago)
Author:
simon04
Message:

fix #20851, see #20842 - Tagging presets: value_template="..." for conditional template

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r17662 r17876  
    66import java.util.Map;
    77import java.util.Objects;
     8import java.util.stream.Collectors;
    89import java.util.stream.Stream;
    910
     
    234235    }
    235236
     237
     238    /**
     239     * Returns a Tagged instance for the given tag collection
     240     * @param tags the tag collection
     241     * @return a Tagged instance for the given tag collection
     242     */
     243    static Tagged ofTags(Collection<Tag> tags) {
     244        return ofMap(tags.stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue, (a, b) -> a)));
     245    }
     246
    236247    /**
    237248     * Returns a Tagged instance for the given tag map
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemGuiSupport.java

    r17875 r17876  
    44import org.openstreetmap.josm.data.osm.OsmPrimitive;
    55import org.openstreetmap.josm.data.osm.Tag;
     6import org.openstreetmap.josm.data.osm.Tagged;
    67import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    78import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
     
    107108    @Override
    108109    public boolean evaluateCondition(SearchCompiler.Match condition) {
    109         throw new UnsupportedOperationException();
     110        Tagged tagged = Tagged.ofTags(changedTagsSupplier.get());
     111        return condition.match(tagged);
    110112    }
    111113
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItemGuiSupportTest.java

    r17611 r17876  
    3737    void testTemplate() throws Exception {
    3838        ArrayList<Tag> tags = new ArrayList<>(Arrays.asList(
     39                new Tag("route", "bus"),
    3940                new Tag("name", "xxx"),
    4041                new Tag("from", "Foo"),
     
    4647        TemplateEntry templateEntry = new TemplateParser("Bus {ref}: {from} -> {to}").parse();
    4748        assertEquals("Bus 42: Foo -> Bar", templateEntry.getText(support));
     49        templateEntry = new TemplateParser("?{route=train 'Train'|route=bus 'Bus'|'X'} {ref}: {from} -> {to}").parse();
     50        assertEquals("Bus 42: Foo -> Bar", templateEntry.getText(support));
    4851    }
    4952}
Note: See TracChangeset for help on using the changeset viewer.