Changeset 4679 in josm for trunk/src/org


Ignore:
Timestamp:
2011-12-21T10:16:39+01:00 (9 years ago)
Author:
simon04
Message:

fix #1728 - Search for objects by modification time

Location:
trunk/src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r4613 r4679  
    229229            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>tags:</b>... - objects with given number of tags (<b>tags:</b>count, <b>tags:</b>min-max, <b>tags:</b>min- or <b>tags:</b>-max)"));
    230230            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>role:</b>... - objects with given role in a relation"));
    231             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>timestamp:</b>... - objects with this timestamp (2009-11-12T14:51:09Z, 2009-11-12 or T14:51 ...)"));
     231            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>timestamp:</b>timestamp - objects with this last modification timestamp (2009-11-12T14:51:09Z, 2009-11-12 or T14:51 ...)"));
     232            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>timestamp:</b>min/max - objects with last modification within range"));
    232233            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>areasize:</b>... - closed ways with given area in m\u00b2 (<b>areasize:</b>min-max or <b>areasize:</b>max)"));
    233234            /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>modified</b> - all changed objects"));
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r4546 r4679  
    99import java.text.Normalizer;
    1010import java.util.Collection;
     11import java.util.Date;
    1112import java.util.regex.Matcher;
    1213import java.util.regex.Pattern;
     
    550551    private abstract static class CountRange extends Match {
    551552
    552         private int minCount;
    553         private int maxCount;
    554 
    555         public CountRange(int minCount, int maxCount) {
     553        private long minCount;
     554        private long maxCount;
     555
     556        public CountRange(long minCount, long maxCount) {
    556557            this.minCount = Math.min(minCount, maxCount);
    557558            this.maxCount = Math.max(minCount, maxCount);
    558559        }
    559560
    560         protected abstract Integer getCount(OsmPrimitive osm);
     561        protected abstract Long getCount(OsmPrimitive osm);
    561562
    562563        protected abstract String getCountString();
     
    564565        @Override
    565566        public boolean match(OsmPrimitive osm) {
    566             Integer count = getCount(osm);
     567            Long count = getCount(osm);
    567568            if (count == null)
    568569                return false;
     
    581582    private static class NodeCountRange extends CountRange {
    582583
    583         public NodeCountRange(int minCount, int maxCount) {
     584        public NodeCountRange(long minCount, long maxCount) {
    584585            super(minCount, maxCount);
    585586        }
    586587
    587588        @Override
    588         protected Integer getCount(OsmPrimitive osm) {
     589        protected Long getCount(OsmPrimitive osm) {
    589590            if (!(osm instanceof Way))
    590591                return null;
    591592            else
    592                 return ((Way) osm).getNodesCount();
     593                return (long) ((Way) osm).getNodesCount();
    593594        }
    594595
     
    601602    private static class TagCountRange extends CountRange {
    602603
    603         public TagCountRange(int minCount, int maxCount) {
     604        public TagCountRange(long minCount, long maxCount) {
    604605            super(minCount, maxCount);
    605606        }
    606607
    607608        @Override
    608         protected Integer getCount(OsmPrimitive osm) {
    609             return osm.getKeys().size();
     609        protected Long getCount(OsmPrimitive osm) {
     610            return (long) osm.getKeys().size();
    610611        }
    611612
     
    614615            return "tags";
    615616        }
     617    }
     618
     619    private static class TimestampRange extends CountRange {
     620
     621        public TimestampRange(long minCount, long maxCount) {
     622            super(minCount, maxCount);
     623        }
     624
     625        @Override
     626        protected Long getCount(OsmPrimitive osm) {
     627            return osm.getTimestamp().getTime();
     628        }
     629
     630        @Override
     631        protected String getCountString() {
     632            return "timestamp";
     633        }
     634
    616635    }
    617636
     
    725744    private static class Area extends CountRange {
    726745
    727         public Area(int minCount, int maxCount) {
     746        public Area(long minCount, long maxCount) {
    728747            super(minCount, maxCount);
    729748        }
    730749
    731750        @Override
    732         protected Integer getCount(OsmPrimitive osm) {
     751        protected Long getCount(OsmPrimitive osm) {
    733752            if (!(osm instanceof Way && ((Way) osm).isClosed()))
    734753                return null;
    735754            Way way = (Way) osm;
    736             return (int) Geometry.closedWayArea(way);
     755            return (long) Geometry.closedWayArea(way);
    737756        }
    738757
     
    873892                else if ("tags".equals(key)) {
    874893                    Range range = tokenizer.readRange(tr("Range of numbers expected"));
    875                     return new TagCountRange((int)range.getStart(), (int)range.getEnd());
     894                    return new TagCountRange(range.getStart(), range.getEnd());
    876895                } else if ("nodes".equals(key)) {
    877896                    Range range = tokenizer.readRange(tr("Range of numbers expected"));
    878                     return new NodeCountRange((int)range.getStart(), (int)range.getEnd());
     897                    return new NodeCountRange(range.getStart(), range.getEnd());
    879898                } else if ("areasize".equals(key)) {
    880899                    Range range = tokenizer.readRange(tr("Range of numbers expected"));
    881                     return new Area((int)range.getStart(), (int)range.getEnd());
     900                    return new Area(range.getStart(), range.getEnd());
     901                } else if ("timestamp".equals(key)) {
     902                    String rangeS = " " + tokenizer.readTextOrNumber() + " "; // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
     903                    String[] rangeA = rangeS.split("/");
     904                    if (rangeA.length == 1) {
     905                        return new KeyValue(key, rangeS, regexSearch, caseSensitive);
     906                    } else if (rangeA.length == 2) {
     907                        String rangeA1 = rangeA[0].trim();
     908                        String rangeA2 = rangeA[1].trim();
     909                        long minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime(); // if min timestap is empty: use lowest possible date
     910                        long maxDate = rangeA2.isEmpty() ? new Date().getTime() : DateUtils.fromString(rangeA2).getTime(); // if max timestamp is empty: use "now"
     911                        return new TimestampRange(minDate, maxDate);
     912                    } else {
     913                        throw new ParseError(tr("Expecting <i>min</i>/<i>max</i>'' after ''timestamp2''"));
     914                    }
    882915                } else if ("changeset".equals(key))
    883916                    return new ChangesetId(tokenizer.readNumber(tr("Changeset id expected")));
Note: See TracChangeset for help on using the changeset viewer.