Changeset 5848 in josm for trunk


Ignore:
Timestamp:
2013-04-13T23:13:25+02:00 (7 years ago)
Author:
Don-vip
Message:

Search: allow to search for numerical ranges for id:, changeset: and version: operators (like nodes:)

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  
    3030        public long getEnd() {
    3131            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 + "]";
    3240        }
    3341    }
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r5847 r5848  
    374374
    375375    /**
    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);}
    383380        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);}
    398396        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);}
    413412        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        }
    420421    }
    421422
     
    833834     * Matches objects with properties in a certain range.
    834835     */
    835     private abstract static class CountRange extends Match {
    836 
    837         private long minCount;
    838         private long maxCount;
    839 
    840         public CountRange(long minCount, long maxCount) {
    841             this.minCount = Math.min(minCount, maxCount);
    842             this.maxCount = 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) {
    846847            this(range.getStart(), range.getEnd());
    847848        }
    848849
    849         protected abstract Long getCount(OsmPrimitive osm);
    850 
    851         protected abstract String getCountString();
     850        protected abstract Long getNumber(OsmPrimitive osm);
     851
     852        protected abstract String getString();
    852853
    853854        @Override
    854855        public boolean match(OsmPrimitive osm) {
    855             Long count = getCount(osm);
    856             if (count == null)
     856            Long num = getNumber(osm);
     857            if (num == null)
    857858                return false;
    858859            else
    859                 return (count >= minCount) && (count <= maxCount);
     860                return (num >= min) && (num <= max);
    860861        }
    861862
    862863        @Override
    863864        public String toString() {
    864             return getCountString() + "=" + minCount + "-" + maxCount;
     865            return getString() + "=" + min + "-" + max;
    865866        }
    866867    }
     
    870871     * Matches ways with a number of nodes in given range
    871872     */
    872     private static class NodeCountRange extends CountRange {
     873    private static class NodeCountRange extends RangeMatch {
    873874        public NodeCountRange(Range range) {
    874875            super(range);
     
    880881
    881882        @Override
    882         protected Long getCount(OsmPrimitive osm) {
     883        protected Long getNumber(OsmPrimitive osm) {
    883884            if (!(osm instanceof Way))
    884885                return null;
     
    888889
    889890        @Override
    890         protected String getCountString() {
     891        protected String getString() {
    891892            return "nodes";
    892893        }
     
    896897     * Matches objects with a number of tags in given range
    897898     */
    898     private static class TagCountRange extends CountRange {
     899    private static class TagCountRange extends RangeMatch {
    899900        public TagCountRange(Range range) {
    900901            super(range);
     
    906907
    907908        @Override
    908         protected Long getCount(OsmPrimitive osm) {
     909        protected Long getNumber(OsmPrimitive osm) {
    909910            return (long) osm.getKeys().size();
    910911        }
    911912
    912913        @Override
    913         protected String getCountString() {
     914        protected String getString() {
    914915            return "tags";
    915916        }
     
    919920     * Matches objects with a timestamp in given range
    920921     */
    921     private static class TimestampRange extends CountRange {
     922    private static class TimestampRange extends RangeMatch {
    922923
    923924        public TimestampRange(long minCount, long maxCount) {
     
    926927
    927928        @Override
    928         protected Long getCount(OsmPrimitive osm) {
     929        protected Long getNumber(OsmPrimitive osm) {
    929930            return osm.getTimestamp().getTime();
    930931        }
    931932
    932933        @Override
    933         protected String getCountString() {
     934        protected String getString() {
    934935            return "timestamp";
    935936        }
     
    10511052     * @author Ole Jørgen Brønner
    10521053     */
    1053     private static class AreaSize extends CountRange {
     1054    private static class AreaSize extends RangeMatch {
    10541055
    10551056        public AreaSize(Range range) {
     
    10621063
    10631064        @Override
    1064         protected Long getCount(OsmPrimitive osm) {
     1065        protected Long getNumber(OsmPrimitive osm) {
    10651066            if (!(osm instanceof Way && ((Way) osm).isClosed()))
    10661067                return null;
     
    10701071
    10711072        @Override
    1072         protected String getCountString() {
     1073        protected String getString() {
    10731074            return "areasize";
    10741075        }
Note: See TracChangeset for help on using the changeset viewer.