Changeset 8884 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-10-17T02:01:36+02:00 (9 years ago)
Author:
simon04
Message:

fix #10465 - SearchAction: add hasRole and isRole keywords

Location:
trunk/src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r8883 r8884  
    419419                .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building")
    420420                .addKeyword("parent <i>expr</i>", "parent ", tr("all parents of objects matching the expression"), "parent bus_stop")
    421                 .addKeyword("nth:<i>7</i>", "nth: ",
     421                .addKeyword("hasRole:<i>stop</i>", "hasRole:", tr("relation containing a member of role <i>stop</i>"))
     422                .addKeyword("isRole:<i>stop</i>", "isRole:", tr("objects being part of a relation as role <i>stop</i>"))
     423                .addKeyword("nth:<i>7</i>", "nth:",
    422424                        tr("n-th member of relation and/or n-th node of way"), "nth:5 (child type:relation)", "nth:-1")
    423                 .addKeyword("nth%:<i>7</i>", "nth%: ",
     425                .addKeyword("nth%:<i>7</i>", "nth%:",
    424426                        tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)"),
    425427                GBC.eol());
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r8859 r8884  
    109109                "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "selected",
    110110                "incomplete", "untagged", "closed", "new", "indownloadedarea",
    111                 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%");
     111                "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole", "isRole");
    112112
    113113        @Override
     
    157157                    case "nth%":
    158158                        return new Nth(tokenizer, true);
     159                    case "hasRole":
     160                        return new HasRole(tokenizer);
     161                    case "isRole":
     162                        return new IsRole(tokenizer);
    159163                    case "timestamp":
    160164                        // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
     
    11241128        protected String getString() {
    11251129            return "timestamp";
     1130        }
     1131    }
     1132
     1133    /**
     1134     * Matches relations with a member of the given role
     1135     */
     1136    private static class HasRole extends Match {
     1137        private final String role;
     1138
     1139        HasRole(PushbackTokenizer tokenizer) {
     1140            role = tokenizer.readTextOrNumber();
     1141        }
     1142
     1143        @Override
     1144        public boolean match(OsmPrimitive osm) {
     1145            return osm instanceof Relation && ((Relation) osm).getMemberRoles().contains(role);
     1146        }
     1147    }
     1148
     1149    /**
     1150     * Matches object which are part of a relation with the given role
     1151     */
     1152    private static class IsRole extends Match {
     1153        private final String role;
     1154
     1155        IsRole(PushbackTokenizer tokenizer) {
     1156            role = tokenizer.readTextOrNumber();
     1157        }
     1158
     1159        @Override
     1160        public boolean match(final OsmPrimitive osm) {
     1161            for (final OsmPrimitive ref : osm.getReferrers()) {
     1162                if (ref instanceof Relation && Utils.exists(((Relation) ref).getMembers(), new Predicate<RelationMember>() {
     1163                    @Override
     1164                    public boolean evaluate(RelationMember object) {
     1165                        return osm.equals(object.getMember()) && role.equals(object.getRole());
     1166                    }
     1167                })) {
     1168                    return true;
     1169                }
     1170            }
     1171            return false;
    11261172        }
    11271173    }
Note: See TracChangeset for help on using the changeset viewer.