Changeset 12464 in josm for trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
- Timestamp:
- 2017-07-10T23:12:16+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r11978 r12464 21 21 import java.util.regex.Pattern; 22 22 import java.util.regex.PatternSyntaxException; 23 import java.util.stream.Collectors; 23 24 24 25 import org.openstreetmap.josm.Main; … … 39 40 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 40 41 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 42 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 43 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetMenu; 44 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSeparator; 45 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 41 46 import org.openstreetmap.josm.tools.AlphanumComparator; 42 47 import org.openstreetmap.josm.tools.Geometry; … … 116 121 "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "deleted", "selected", 117 122 "incomplete", "untagged", "closed", "new", "indownloadedarea", 118 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole"); 123 "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%", "hasRole", "preset"); 119 124 120 125 @Override … … 152 157 case "type": 153 158 return new ExactType(tokenizer.readTextOrNumber()); 159 case "preset": 160 return new Preset(tokenizer.readTextOrNumber()); 154 161 case "user": 155 162 return new UserMatch(tokenizer.readTextOrNumber()); … … 1555 1562 } 1556 1563 1564 /** 1565 * Matches presets. 1566 * @since 12464 1567 */ 1568 private static class Preset extends Match { 1569 private final List<TaggingPreset> presets; 1570 1571 Preset(String presetName) throws ParseError { 1572 1573 if (presetName == null || presetName.equals("")) { 1574 throw new ParseError("The name of the preset is required"); 1575 } 1576 1577 int wildCardIdx = presetName.lastIndexOf("*"); 1578 int length = presetName.length() - 1; 1579 1580 /* 1581 * Match strictly (simply comparing the names) if there is no '*' symbol 1582 * at the end of the name or '*' is a part of the preset name. 1583 */ 1584 boolean matchStrictly = wildCardIdx == -1 || wildCardIdx != length; 1585 1586 this.presets = TaggingPresets.getTaggingPresets() 1587 .stream() 1588 .filter(preset -> !(preset instanceof TaggingPresetMenu || preset instanceof TaggingPresetSeparator)) 1589 .filter(preset -> this.presetNameMatch(presetName, preset, matchStrictly)) 1590 .collect(Collectors.toList()); 1591 1592 if (this.presets.isEmpty()) { 1593 throw new ParseError(tr("Unknown preset name: ") + presetName); 1594 } 1595 } 1596 1597 @Override 1598 public boolean match(OsmPrimitive osm) { 1599 for (TaggingPreset preset : this.presets) { 1600 if (preset.test(osm)) { 1601 return true; 1602 } 1603 } 1604 1605 return false; 1606 } 1607 1608 private boolean presetNameMatch(String name, TaggingPreset preset, boolean matchStrictly) { 1609 if (matchStrictly) { 1610 return name.equalsIgnoreCase(preset.getRawName()); 1611 } 1612 1613 try { 1614 String groupSuffix = name.substring(0, name.length() - 2); // try to remove '/*' 1615 TaggingPresetMenu group = preset.group; 1616 1617 return group != null && groupSuffix.equalsIgnoreCase(group.getRawName()); 1618 } catch (StringIndexOutOfBoundsException ex) { 1619 return false; 1620 } 1621 } 1622 } 1623 1557 1624 public static class ParseError extends Exception { 1558 1625 public ParseError(String msg) { … … 1805 1872 } 1806 1873 } 1874
Note:
See TracChangeset
for help on using the changeset viewer.
