- Timestamp:
- 2011-08-28T13:54:11+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r4347 r4372 8 8 import java.io.StringReader; 9 9 import java.text.Normalizer; 10 import java.util.Collection; 10 11 import java.util.regex.Matcher; 11 12 import java.util.regex.Pattern; … … 61 62 abstract public static class Match { 62 63 abstract public boolean match(OsmPrimitive osm); 64 65 /** 66 * Tests whether one of the primitives matches. 67 */ 68 protected boolean existsMatch(Collection<? extends OsmPrimitive> primitives) { 69 for (OsmPrimitive p : primitives) { 70 if (match(p)) { 71 return true; 72 } 73 } 74 return false; 75 } 76 77 /** 78 * Tests whether all primitives match. 79 */ 80 protected boolean forallMatch(Collection<? extends OsmPrimitive> primitives) { 81 for (OsmPrimitive p : primitives) { 82 if (!match(p)) { 83 return false; 84 } 85 } 86 return true; 87 } 63 88 } 64 89 … … 695 720 protected String getCountString() { 696 721 return "area"; 722 } 723 } 724 725 /** 726 * Matches data in source area ("downloaded area"). 727 */ 728 private static class InDataSourceArea extends Match { 729 730 private final java.awt.geom.Area dataSourceArea = Main.main.getCurrentDataSet().getDataSourceArea(); 731 private final boolean all; 732 733 /** 734 * @param all if true, all way nodes or relation members have to be within source area;if false, one suffices. 735 */ 736 public InDataSourceArea(boolean all) { 737 this.all = all; 738 } 739 740 @Override 741 public boolean match(OsmPrimitive osm) { 742 if (!osm.isUsable()) { 743 return false; 744 } else if (osm instanceof Node) { 745 return dataSourceArea.contains(((Node) osm).getCoor()); 746 } else if (osm instanceof Way) { 747 Collection<Node> nodes = ((Way) osm).getNodes(); 748 return all ? forallMatch(nodes) : existsMatch(nodes); 749 } else if (osm instanceof Relation) { 750 Collection<OsmPrimitive> primitives = ((Relation) osm).getMemberPrimitives(); 751 return all ? forallMatch(primitives) : existsMatch(primitives); 752 } else { 753 return false; 754 } 697 755 } 698 756 } … … 795 853 else if ("parent".equals(key)) 796 854 return new Parent(parseFactor()); 855 else if ("inDownloadedArea".equals(key)) 856 return new InDataSourceArea(false); 857 else if ("allinDownloadedArea".equals(key)) 858 return new InDataSourceArea(true); 797 859 else 798 860 return new Any(key, regexSearch, caseSensitive);
Note:
See TracChangeset
for help on using the changeset viewer.