Changeset 9932 in josm


Ignore:
Timestamp:
2016-03-05T17:57:04+01:00 (9 years ago)
Author:
simon04
Message:

see #8460 - fix typo from r9931, fix matching, improve conditions, add unit test

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r9931 r9932  
    30893089            </optional>
    30903090            <roles>
    3091                 <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
    3092                 <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
    3093                 <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
    3094                 <role key="platform" text="platform" requisite="optional" type="node,way,closedway,multipolygon" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
    3095                 <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
    3096                 <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=stop_position (train OR subway OR monorail OR tram OR light_rail)" />
     3091                <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
     3092                <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
     3093                <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" member_expression="public_transport=stop_position (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
     3094                <role key="platform" text="platform" requisite="optional" type="node,way,closedway,multipolygon" member_expression="public_transport=platform (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
     3095                <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
     3096                <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (train=yes OR subway=yes OR monorail=yes OR tram=yes OR light_rail=yes)" />
    30973097                <role key="" text="route segment" requisite="required" type="way,closedway" member_expression="railway" />
    30983098            </roles>
     
    31093109            </optional>
    31103110            <roles>
    3111                 <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position (bus OR trolleybus)" />
    3112                 <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position (bus OR trolleybus)" />
    3113                 <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" member_expression="public_transport=stop_position (bus OR trolleybus)" />
    3114                 <role key="platform" text="platform" requisite="optional" type="node,way,closedway,multipolygon" member_expression="public_transport=platform (bus OR trolleybus)" />
    3115                 <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (bus OR trolleybus)" />
    3116                 <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (bus OR trolleybus)" />
     3111                <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position (bus=yes OR trolleybus=yes)" />
     3112                <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position (bus=yes OR trolleybus=yes)" />
     3113                <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" member_expression="public_transport=stop_position (bus=yes OR trolleybus=yes)" />
     3114                <role key="platform" text="platform" requisite="optional" type="node,way,closedway,multipolygon" member_expression="public_transport=platform (bus=yes OR trolleybus=yes)" />
     3115                <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (bus=yes OR trolleybus=yes)" />
     3116                <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform (bus=yes OR trolleybus=yes)" />
    31173117                <role key="" text="route segment" requisite="required" type="way,closedway" member_expression="highway" />
    31183118            </roles>
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

    r9574 r9932  
    2525import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    2626import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    27 import org.openstreetmap.josm.gui.tagging.presets.items.Key;
     27import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
    2828import org.openstreetmap.josm.gui.tagging.presets.items.Roles;
    2929import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role;
     
    145145
    146146        for (TaggingPreset p : relationpresets) {
    147             boolean matches = true;
    148             Roles r = null;
    149             for (TaggingPresetItem i : p.data) {
    150                 if (i instanceof Key) {
    151                     Key k = (Key) i;
    152                     if (!k.value.equals(n.get(k.key))) {
    153                         matches = false;
    154                         break;
    155                     }
    156                 } else if (i instanceof Roles) {
    157                     r = (Roles) i;
    158                 }
    159             }
     147            final boolean matches = TaggingPresetItem.matches(Utils.filteredCollection(p.data, KeyedItem.class), n.getKeys());
     148            final Roles r = Utils.find(p.data, Roles.class);
    160149            if (matches && r != null) {
    161150                for (Role role: r.roles) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r9623 r9932  
    562562        else if (!typeMatches(t))
    563563            return false;
    564         boolean atLeastOnePositiveMatch = false;
    565         for (TaggingPresetItem item : data) {
    566             Boolean m = item.matches(tags);
    567             if (m != null && !m)
    568                 return false;
    569             else if (m != null) {
    570                 atLeastOnePositiveMatch = true;
    571             }
    572         }
    573         return atLeastOnePositiveMatch;
     564        else
     565            return TaggingPresetItem.matches(data, tags);
    574566    }
    575567
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java

    r9574 r9932  
    134134        return imgProv.get();
    135135    }
     136
     137    /**
     138     * Determine whether the given preset items match the tags
     139     * @param data the preset items
     140     * @param tags the tags to match
     141     * @return whether the given preset items match the tags
     142     * @sice 9932
     143     */
     144    public static boolean matches(Iterable<? extends TaggingPresetItem> data, Map<String, String> tags) {
     145        boolean atLeastOnePositiveMatch = false;
     146        for (TaggingPresetItem item : data) {
     147            Boolean m = item.matches(tags);
     148            if (m != null && !m)
     149                return false;
     150            else if (m != null) {
     151                atLeastOnePositiveMatch = true;
     152            }
     153        }
     154        return atLeastOnePositiveMatch;
     155    }
    136156}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.groovy

    r8863 r9932  
    118118        assert errors.get(0).getDescription() == "Role member does not match expression power in template Power Route"
    119119    }
     120
     121    void testRouteMemberExpression() {
     122        def r = createRelation("type=route route=tram public_transport:version=2")
     123        r.addMember(new RelationMember("", createPrimitive("way railway=tram")))
     124        r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position tram=yes")))
     125        r.addMember(new RelationMember("platform", createPrimitive("node public_transport=platform tram=yes")))
     126        assert testRelation(r).size() == 0
     127
     128        r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes")))
     129        assert testRelation(r).size() == 1
     130        assert testRelation(r).get(0).getDescription() == "Role member does not match expression railway in template Public Transport Route (Rail)"
     131
     132        r.removeMember(3)
     133        r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes")))
     134        assert testRelation(r).size() == 1
     135        assert testRelation(r).get(0).getDescription() == "Role member type way does not match accepted list of node in template Public Transport Route (Rail)"
     136
     137        r.removeMember(3)
     138        r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes")))
     139        assert testRelation(r).size() == 1
     140        assert testRelation(r).get(0).getDescription() == "Role member does not match expression public_transport=stop_position && (train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes) in template Public Transport Route (Rail)"
     141    }
    120142}
Note: See TracChangeset for help on using the changeset viewer.