Changeset 2357 in josm for trunk/src


Ignore:
Timestamp:
2009-10-31T09:20:00+01:00 (14 years ago)
Author:
Gubaer
Message:

applied #3807: patch by avar: Add tags: operator to search engine to search for a given number of tags

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

Legend:

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

    r2264 r2357  
    112112                    + "<li>"+tr("<b>id:</b>... - object with given ID (0 for new objects)")+"</li>"
    113113                    + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
     114                    + "<li>"+tr("<b>tags:</b>... - object with given number of tags (tags:count or tags:min-max)")+"</li>"
    114115                    + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
    115116                    + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r2291 r2357  
    415415    }
    416416
     417    private static class TagCount extends Match {
     418        private int count;
     419        public TagCount(int count) {this.count = count;}
     420        @Override public boolean match(OsmPrimitive osm) {
     421            int size = osm.getKeys().size();
     422            return size == count;
     423        }
     424        @Override public String toString() {return "tags="+count;}
     425    }
     426
     427    private static class TagCountRange extends Match {
     428        private int minCount;
     429        private int maxCount;
     430        public TagCountRange(int minCount, int maxCount) {
     431            if(maxCount < minCount) {
     432                this.minCount = maxCount;
     433                this.maxCount = minCount;
     434            } else {
     435                this.minCount = minCount;
     436                this.maxCount = maxCount;
     437            }
     438        }
     439        @Override public boolean match(OsmPrimitive osm) {
     440            int size = osm.getKeys().size();
     441            return (size >= minCount) && (size <= maxCount);
     442        }
     443        @Override public String toString() {return "tags="+minCount+"-"+maxCount;}
     444    }
     445
    417446    private static class Modified extends Match {
    418447        @Override public boolean match(OsmPrimitive osm) {
     
    610639        else if (key.equals("user"))
    611640            return new UserMatch(value);
     641        else if (key.equals("tags"))
     642            try {
     643                String[] range = value.split("-");
     644                if (range.length == 1)
     645                    return new TagCount(Integer.parseInt(value));
     646                else if (range.length == 2)
     647                    return new TagCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1]));
     648                else
     649                    throw new ParseError(tr("Wrong number of parameters for tags operator."));
     650            } catch (NumberFormatException e) {
     651                throw new ParseError(tr("Incorrect value of tags operator: {0}. Tags operator expects number of tags or range, for example tags:1 or tags:2-5", value));
     652            }
    612653        else if (key.equals("nodes")) {
    613654            try {
Note: See TracChangeset for help on using the changeset viewer.