Changeset 5848 in josm
- Timestamp:
- 2013-04-13T23:13:25+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java
r4817 r5848 30 30 public long getEnd() { 31 31 return end; 32 } 33 34 /* (non-Javadoc) 35 * @see java.lang.Object#toString() 36 */ 37 @Override 38 public String toString() { 39 return "Range [start=" + start + ", end=" + end + "]"; 32 40 } 33 41 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r5847 r5848 374 374 375 375 /** 376 * Matches objects with the given object ID. 377 */ 378 private static class Id extends Match { 379 private long id; 380 public Id(long id) { 381 this.id = id; 382 } 376 * Matches objects with ID in the given range. 377 */ 378 private static class Id extends RangeMatch { 379 public Id(Range range) {super(range);} 383 380 public Id(PushbackTokenizer tokenizer) throws ParseError { 384 this(tokenizer.readNumber(tr("Primitive id expected"))); 385 } 386 @Override public boolean match(OsmPrimitive osm) { 387 return id == 0?osm.isNew():osm.getUniqueId() == id; 388 } 389 @Override public String toString() {return "id="+id;} 390 } 391 392 /** 393 * Matches objects with the given changeset ID. 394 */ 395 private static class ChangesetId extends Match { 396 private long changesetid; 397 public ChangesetId(long changesetid) {this.changesetid = changesetid;} 381 this(tokenizer.readRange(tr("Range of primitive ids expected"))); 382 } 383 @Override protected Long getNumber(OsmPrimitive osm) { 384 return osm.isNew() ? 0 : osm.getUniqueId(); 385 } 386 @Override protected String getString() { 387 return "id"; 388 } 389 } 390 391 /** 392 * Matches objects with a changeset ID in the given range. 393 */ 394 private static class ChangesetId extends RangeMatch { 395 public ChangesetId(Range range) {super(range);} 398 396 public ChangesetId(PushbackTokenizer tokenizer) throws ParseError { 399 this(tokenizer.readNumber(tr("Changeset id expected"))); 400 } 401 @Override public boolean match(OsmPrimitive osm) { 402 return osm.getChangesetId() == changesetid; 403 } 404 @Override public String toString() {return "changeset="+changesetid;} 405 } 406 407 /** 408 * Matches objects with the given version number. 409 */ 410 private static class Version extends Match { 411 private long version; 412 public Version(long version) {this.version = version;} 397 this(tokenizer.readRange(tr("Range of changeset ids expected"))); 398 } 399 @Override protected Long getNumber(OsmPrimitive osm) { 400 return (long) osm.getChangesetId(); 401 } 402 @Override protected String getString() { 403 return "changeset"; 404 } 405 } 406 407 /** 408 * Matches objects with a version number in the given range. 409 */ 410 private static class Version extends RangeMatch { 411 public Version(Range range) {super(range);} 413 412 public Version(PushbackTokenizer tokenizer) throws ParseError { 414 this(tokenizer.readNumber(tr("Version expected"))); 415 } 416 @Override public boolean match(OsmPrimitive osm) { 417 return osm.getVersion() == version; 418 } 419 @Override public String toString() {return "version="+version;} 413 this(tokenizer.readRange(tr("Range of versions expected"))); 414 } 415 @Override protected Long getNumber(OsmPrimitive osm) { 416 return (long) osm.getVersion(); 417 } 418 @Override protected String getString() { 419 return "version"; 420 } 420 421 } 421 422 … … 833 834 * Matches objects with properties in a certain range. 834 835 */ 835 private abstract static class CountRangeextends Match {836 837 private long min Count;838 private long max Count;839 840 public CountRange(long minCount, long maxCount) {841 this.min Count= Math.min(minCount, maxCount);842 this.max Count= Math.max(minCount, maxCount);843 } 844 845 public CountRange(Range range) {836 private abstract static class RangeMatch extends Match { 837 838 private final long min; 839 private final long max; 840 841 public RangeMatch(long min, long max) { 842 this.min = Math.min(min, max); 843 this.max = Math.max(min, max); 844 } 845 846 public RangeMatch(Range range) { 846 847 this(range.getStart(), range.getEnd()); 847 848 } 848 849 849 protected abstract Long get Count(OsmPrimitive osm);850 851 protected abstract String get CountString();850 protected abstract Long getNumber(OsmPrimitive osm); 851 852 protected abstract String getString(); 852 853 853 854 @Override 854 855 public boolean match(OsmPrimitive osm) { 855 Long count = getCount(osm);856 if ( count== null)856 Long num = getNumber(osm); 857 if (num == null) 857 858 return false; 858 859 else 859 return ( count>= minCount) && (count<= maxCount);860 return (num >= min) && (num <= max); 860 861 } 861 862 862 863 @Override 863 864 public String toString() { 864 return get CountString() + "=" + minCount+ "-" + maxCount;865 return getString() + "=" + min + "-" + max; 865 866 } 866 867 } … … 870 871 * Matches ways with a number of nodes in given range 871 872 */ 872 private static class NodeCountRange extends CountRange{873 private static class NodeCountRange extends RangeMatch { 873 874 public NodeCountRange(Range range) { 874 875 super(range); … … 880 881 881 882 @Override 882 protected Long get Count(OsmPrimitive osm) {883 protected Long getNumber(OsmPrimitive osm) { 883 884 if (!(osm instanceof Way)) 884 885 return null; … … 888 889 889 890 @Override 890 protected String get CountString() {891 protected String getString() { 891 892 return "nodes"; 892 893 } … … 896 897 * Matches objects with a number of tags in given range 897 898 */ 898 private static class TagCountRange extends CountRange{899 private static class TagCountRange extends RangeMatch { 899 900 public TagCountRange(Range range) { 900 901 super(range); … … 906 907 907 908 @Override 908 protected Long get Count(OsmPrimitive osm) {909 protected Long getNumber(OsmPrimitive osm) { 909 910 return (long) osm.getKeys().size(); 910 911 } 911 912 912 913 @Override 913 protected String get CountString() {914 protected String getString() { 914 915 return "tags"; 915 916 } … … 919 920 * Matches objects with a timestamp in given range 920 921 */ 921 private static class TimestampRange extends CountRange{922 private static class TimestampRange extends RangeMatch { 922 923 923 924 public TimestampRange(long minCount, long maxCount) { … … 926 927 927 928 @Override 928 protected Long get Count(OsmPrimitive osm) {929 protected Long getNumber(OsmPrimitive osm) { 929 930 return osm.getTimestamp().getTime(); 930 931 } 931 932 932 933 @Override 933 protected String get CountString() {934 protected String getString() { 934 935 return "timestamp"; 935 936 } … … 1051 1052 * @author Ole Jørgen Brønner 1052 1053 */ 1053 private static class AreaSize extends CountRange{1054 private static class AreaSize extends RangeMatch { 1054 1055 1055 1056 public AreaSize(Range range) { … … 1062 1063 1063 1064 @Override 1064 protected Long get Count(OsmPrimitive osm) {1065 protected Long getNumber(OsmPrimitive osm) { 1065 1066 if (!(osm instanceof Way && ((Way) osm).isClosed())) 1066 1067 return null; … … 1070 1071 1071 1072 @Override 1072 protected String get CountString() {1073 protected String getString() { 1073 1074 return "areasize"; 1074 1075 }
Note:
See TracChangeset
for help on using the changeset viewer.