Changeset 8884 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-10-17T02:01:36+02:00 (9 years ago)
- 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 419 419 .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building") 420 420 .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:", 422 424 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%:", 424 426 tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)"), 425 427 GBC.eol()); -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r8859 r8884 109 109 "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "selected", 110 110 "incomplete", "untagged", "closed", "new", "indownloadedarea", 111 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%" );111 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole", "isRole"); 112 112 113 113 @Override … … 157 157 case "nth%": 158 158 return new Nth(tokenizer, true); 159 case "hasRole": 160 return new HasRole(tokenizer); 161 case "isRole": 162 return new IsRole(tokenizer); 159 163 case "timestamp": 160 164 // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""}) … … 1124 1128 protected String getString() { 1125 1129 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; 1126 1172 } 1127 1173 }
Note:
See TracChangeset
for help on using the changeset viewer.