Ignore:
Timestamp:
2017-02-25T03:14:20+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14402 - add blacklist for leisure area values to avoid false positives - improve globally the detection of keys/tags

Location:
trunk/src/org/openstreetmap/josm/data
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r11587 r11608  
    706706     * Replies true, if the map of key/value pairs of this primitive is not empty.
    707707     *
    708      * @return true, if the map of key/value pairs of this primitive is not empty; false
    709      *   otherwise
     708     * @return true, if the map of key/value pairs of this primitive is not empty; false otherwise
    710709     */
    711710    @Override
     
    718717     *
    719718     * @param key the key
    720      * @return true, if his primitive has a tag with key <code>key</code>
    721      */
     719     * @return true, if this primitive has a tag with key <code>key</code>
     720     */
     721    @Override
    722722    public boolean hasKey(String key) {
    723723        return key != null && indexOfKey(keys, key) >= 0;
     
    728728     *
    729729     * @param keys the keys
    730      * @return true, if his primitive has a tag with any of the <code>keys</code>
     730     * @return true, if this primitive has a tag with any of the <code>keys</code>
    731731     * @since 11587
    732732     */
     
    758758
    759759    /**
    760      * Tests whether this primitive contains a tag consisting of {@code key} and {@code values}.
     760     * Tests whether this primitive contains a tag consisting of {@code key} and {@code value}.
    761761     * @param key the key forming the tag.
    762762     * @param value value forming the tag.
    763      * @return true iff primitive contains a tag consisting of {@code key} and {@code value}.
     763     * @return true if primitive contains a tag consisting of {@code key} and {@code value}.
    764764     */
    765765    public boolean hasTag(String key, String value) {
     
    781781     * @param key the key forming the tag.
    782782     * @param values one or many values forming the tag.
    783      * @return true iff primitive contains a tag consisting of {@code key} and any of {@code values}.
     783     * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}.
    784784     */
    785785    public boolean hasTag(String key, Collection<String> values) {
    786786        return values.contains(get(key));
    787787    }
     788
     789    /**
     790     * Tests whether this primitive contains a tag consisting of {@code key} and a value different from {@code value}.
     791     * @param key the key forming the tag.
     792     * @param value value not forming the tag.
     793     * @return true if primitive contains a tag consisting of {@code key} and a value different from {@code value}.
     794     * @since 11608
     795     */
     796    public boolean hasTagDifferent(String key, String value) {
     797        String v = get(key);
     798        return v != null && !v.equals(value);
     799    }
     800
     801    /**
     802     * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
     803     * @param key the key forming the tag.
     804     * @param values one or many values forming the tag.
     805     * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
     806     * @since 11608
     807     */
     808    public boolean hasTagDifferent(String key, String... values) {
     809        return hasTagDifferent(key, Arrays.asList(values));
     810    }
     811
     812    /**
     813     * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
     814     * @param key the key forming the tag.
     815     * @param values one or many values forming the tag.
     816     * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
     817     * @since 11608
     818     */
     819    public boolean hasTagDifferent(String key, Collection<String> values) {
     820        String v = get(key);
     821        return v != null && !values.contains(v);
     822    }
    788823}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r11600 r11608  
    13531353     */
    13541354    public final boolean hasAreaTags() {
    1355         return hasKey("landuse", "amenity", "leisure", "building", "building:part")
    1356                 || "yes".equals(get("area"))
    1357                 || "riverbank".equals(get("waterway"))
     1355        return hasKey("landuse", "amenity", "building", "building:part")
     1356                || hasTag("area", "yes")
     1357                || hasTag("waterway", "riverbank")
     1358                || hasTagDifferent("leisure", "picnic_table", "slipway", "firepit")
    13581359                || hasTag("natural", "water", "wood", "scrub", "wetland", "grassland", "heath", "rock", "bare_rock",
    13591360                                     "sand", "beach", "scree", "bay", "glacier", "shingle", "fell", "reef", "stone",
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r10736 r11608  
    44import java.util.Collection;
    55import java.util.Map;
     6
    67/**
    78 * Objects implement Tagged if they provide a map of key/value pairs.
    89 *
    9  *
     10 * @since 2115
    1011 */
    1112// FIXME: better naming? setTags(), getTags(), getKeys() instead of keySet() ?
     
    6768
    6869    /**
     70     * Replies true if there is a tag with key <code>key</code>.
     71     *
     72     * @param key the key
     73     * @return true, if there is a tag with key <code>key</code>
     74     * @since 11608
     75     */
     76    default boolean hasKey(String key) {
     77        return get(key) != null;
     78    }
     79
     80    /**
    6981     * Replies the set of keys
    7082     *
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r8509 r11608  
    1010
    1111/**
    12  * Represents an immutable OSM node in the context of a historical view on
    13  * OSM data.
    14  *
     12 * Represents an immutable OSM node in the context of a historical view on OSM data.
     13 * @since 1670
    1514 */
    1615public class HistoryNode extends HistoryOsmPrimitive {
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r11553 r11608  
    55
    66import java.text.MessageFormat;
     7import java.util.Collection;
    78import java.util.Collections;
    89import java.util.Date;
     
    1920import org.openstreetmap.josm.data.osm.Relation;
    2021import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     22import org.openstreetmap.josm.data.osm.Tagged;
    2123import org.openstreetmap.josm.data.osm.User;
    2224import org.openstreetmap.josm.data.osm.Way;
     
    2426
    2527/**
    26  * Represents an immutable OSM primitive in the context of a historical view on
    27  * OSM data.
    28  *
     28 * Represents an immutable OSM primitive in the context of a historical view on OSM data.
     29 * @since 1670
    2930 */
    30 public abstract class HistoryOsmPrimitive implements Comparable<HistoryOsmPrimitive> {
     31public abstract class HistoryOsmPrimitive implements Tagged, Comparable<HistoryOsmPrimitive> {
    3132
    3233    private long id;
     
    3839    private long version;
    3940    private Map<String, String> tags;
    40 
    41     protected final void ensurePositiveLong(long value, String name) {
    42         if (value <= 0) {
    43             throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", name, value));
    44         }
    45     }
    4641
    4742    /**
     
    119114    }
    120115
     116    /**
     117     * Returns the id.
     118     * @return the id
     119     */
    121120    public long getId() {
    122121        return id;
    123122    }
    124123
     124    /**
     125     * Returns the primitive id.
     126     * @return the primitive id
     127     */
    125128    public PrimitiveId getPrimitiveId() {
    126129        return new SimplePrimitiveId(id, getType());
    127130    }
    128131
     132    /**
     133     * Determines if the primitive is still visible.
     134     * @return {@code true} if the primitive is still visible
     135     */
    129136    public boolean isVisible() {
    130137        return visible;
    131138    }
    132139
     140    /**
     141     * Returns the user.
     142     * @return the user
     143     */
    133144    public User getUser() {
    134145        return user;
    135146    }
    136147
     148    /**
     149     * Returns the changeset id.
     150     * @return the changeset id
     151     */
    137152    public long getChangesetId() {
    138153        return changesetId;
    139154    }
    140155
     156    /**
     157     * Returns the timestamp.
     158     * @return the timestamp
     159     */
    141160    public Date getTimestamp() {
    142161        return timestamp;
    143162    }
    144163
     164    /**
     165     * Returns the version.
     166     * @return the version
     167     */
    145168    public long getVersion() {
    146169        return version;
    147170    }
    148171
     172    protected final void ensurePositiveLong(long value, String name) {
     173        if (value <= 0) {
     174            throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", name, value));
     175        }
     176    }
     177
    149178    public boolean matches(long id, long version) {
    150179        return this.id == id && this.version == version;
     
    155184    }
    156185
     186    /**
     187     * Returns the primitive type.
     188     * @return the primitive type
     189     */
    157190    public abstract OsmPrimitiveType getType();
    158191
     
    164197    }
    165198
    166     public void put(String key, String value) {
     199    @Override
     200    public final void put(String key, String value) {
    167201        tags.put(key, value);
    168202    }
    169203
    170     public String get(String key) {
     204    @Override
     205    public final String get(String key) {
    171206        return tags.get(key);
    172207    }
    173208
    174     public boolean hasTag(String key) {
    175         return tags.get(key) != null;
    176     }
    177 
     209    @Override
     210    public final boolean hasKey(String key) {
     211        return tags.containsKey(key);
     212    }
     213
     214    @Override
     215    public final Map<String, String> getKeys() {
     216        return getTags();
     217    }
     218
     219    @Override
     220    public final void setKeys(Map<String, String> keys) {
     221        throw new UnsupportedOperationException();
     222    }
     223
     224    @Override
     225    public final void remove(String key) {
     226        throw new UnsupportedOperationException();
     227    }
     228
     229    @Override
     230    public final void removeAll() {
     231        throw new UnsupportedOperationException();
     232    }
     233
     234    @Override
     235    public final boolean hasKeys() {
     236        return !tags.isEmpty();
     237    }
     238
     239    @Override
     240    public final Collection<String> keySet() {
     241        return Collections.unmodifiableSet(tags.keySet());
     242    }
     243
     244    /**
     245     * Replies the key/value map.
     246     * @return the key/value map
     247     */
    178248    public Map<String, String> getTags() {
    179249        return Collections.unmodifiableMap(tags);
     
    272342    public String toString() {
    273343        return getClass().getSimpleName() + " [version=" + version + ", id=" + id + ", visible=" + visible + ", "
    274                 + (timestamp != null ? "timestamp=" + timestamp : "") + ", "
    275                 + (user != null ? "user=" + user + ", " : "") + "changesetId="
     344                + (timestamp != null ? ("timestamp=" + timestamp) : "") + ", "
     345                + (user != null ? ("user=" + user + ", ") : "") + "changesetId="
    276346                + changesetId
    277347                + ']';
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java

    r10632 r11608  
    1515
    1616/**
    17  * Represents an immutable OSM relation in the context of a historical view on
    18  * OSM data.
    19  *
     17 * Represents an immutable OSM relation in the context of a historical view on OSM data.
     18 * @since 1670
    2019 */
    2120public class HistoryRelation extends HistoryOsmPrimitive {
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java

    r10662 r11608  
    1515
    1616/**
    17  * Represents an immutable OSM way in the context of a historical view on
    18  * OSM data.
    19  *
     17 * Represents an immutable OSM way in the context of a historical view on OSM data.
     18 * @since 1670
    2019 */
    2120public class HistoryWay extends HistoryOsmPrimitive {
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r11553 r11608  
    342342     */
    343343    protected static final boolean isBuilding(OsmPrimitive p) {
    344         String v = p.get("building");
    345         return v != null && !"no".equals(v) && !"entrance".equals(v);
     344        return p.hasTagDifferent("building", "no", "entrance");
    346345    }
    347346
     
    357356        Test test = (Test) obj;
    358357        return Objects.equals(name, test.name) &&
    359                 Objects.equals(description, test.description);
     358               Objects.equals(description, test.description);
    360359    }
    361360}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r11339 r11608  
    6363            // warning level only if several relations have different names, see #10945
    6464            final String name = list.get(0).get("name");
    65             if (name == null || SubclassFilteredCollection.filter(list, r -> name.equals(r.get("name"))).size() < list.size()) {
     65            if (name == null || SubclassFilteredCollection.filter(list, r -> r.hasTag("name", name)).size() < list.size()) {
    6666                level = Severity.WARNING;
    6767            } else {
     
    147147                        street.add((Way) p);
    148148                    }
    149                     if (relationName != null && p.hasKey("name") && !relationName.equals(p.get("name"))) {
     149                    if (relationName != null && p.hasTagDifferent("name", relationName)) {
    150150                        if (wrongStreetNames.isEmpty()) {
    151151                            wrongStreetNames.add(r);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java

    r11129 r11608  
    251251
    252252    private static boolean isCoastline(OsmPrimitive osm) {
    253         return osm instanceof Way && "coastline".equals(osm.get("natural"));
     253        return osm instanceof Way && osm.hasTag("natural", "coastline");
    254254    }
    255255
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r11587 r11608  
    241241
    242242    static boolean isHighway(OsmPrimitive w) {
    243         return w.hasKey(HIGHWAY) && !w.hasTag(HIGHWAY, "rest_area", "services");
     243        return w.hasTagDifferent(HIGHWAY, "rest_area", "services");
    244244    }
    245245
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r11129 r11608  
    9292    public void visit(Way w) {
    9393        if (w.isUsable()) {
    94             if (w.isClosed() && w.hasKey("highway") && CLASSIFIED_HIGHWAYS.contains(w.get("highway"))
    95                     && w.hasKey("junction") && "roundabout".equals(w.get("junction"))) {
     94            if (w.isClosed() && w.hasTag("highway", CLASSIFIED_HIGHWAYS) && w.hasTag("junction", "roundabout")) {
    9695                // TODO: find out how to handle splitted roundabouts (see #12841)
    9796                testWrongRoundabout(w);
     
    131130                if (list.size() > 2 || oneway1 == null || oneway2 == null || !oneway1 || !oneway2) {
    132131                    // Error when the highway tags do not match
    133                     if (!w.get("highway").equals(s)) {
     132                    String value = w.get("highway");
     133                    if (!value.equals(s)) {
    134134                        errors.add(TestError.builder(this, Severity.WARNING, WRONG_ROUNDABOUT_HIGHWAY)
    135                                 .message(tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), s))
     135                                .message(tr("Incorrect roundabout (highway: {0} instead of {1})", value, s))
    136136                                .primitives(w)
    137137                                .fix(() -> new ChangePropertyCommand(w, "highway", s))
  • trunk/src/org/openstreetmap/josm/data/validation/tests/LongSegment.java

    r11129 r11608  
    3535    @Override
    3636    public void visit(Way w) {
    37         if ("ferry".equals(w.get("route"))) {
     37        if (w.hasTag("route", "ferry")) {
    3838            return;
    3939        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r11590 r11608  
    175175    private void checkStyleConsistency(Relation r, Multipolygon polygon) {
    176176        ElemStyles styles = MapPaintStyles.getStyles();
    177         if (styles != null && !"boundary".equals(r.get("type"))) {
     177        if (styles != null && !r.hasTag("type", "boundary")) {
    178178            AreaElement area = ElemStyles.getAreaElemStyle(r, false);
    179179            boolean areaStyle = area != null;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java

    r11129 r11608  
    9090
    9191                for (WaySegment ws : duplicated) {
    92                     if (ws.way.get("highway") != null) {
     92                    if (ws.way.hasKey("highway")) {
    9393                        highway++;
    94                     } else if (ws.way.get("railway") != null) {
     94                    } else if (ws.way.hasKey("railway")) {
    9595                        railway++;
    9696                    }
     
    107107                    currentWays.add(ws.way);
    108108                }
    109                 /* These ways not seen before
    110                  * If two or more of the overlapping ways are
    111                  * highways or railways mark a separate error
    112                  */
     109                // These ways not seen before
     110                // If two or more of the overlapping ways are highways or railways mark a separate error
    113111                if ((highlight = seenWays.get(currentWays)) == null) {
    114112                    String errortype;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java

    r11432 r11608  
    165165     */
    166166    private static boolean isPowerIn(OsmPrimitive p, Collection<String> values) {
    167         String v = p.get("power");
    168         return v != null && values != null && values.contains(v);
     167        return p.hasTag("power", values);
    169168    }
    170169
     
    176175     */
    177176    private static boolean isBuildingIn(OsmPrimitive p, Collection<String> values) {
    178         String v = p.get("building");
    179         return v != null && values != null && values.contains(v);
     177        return p.hasTag("building", values);
    180178    }
    181179}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

    r11129 r11608  
    4848    @Override
    4949    public void visit(Relation r) {
    50         if (!"restriction".equals(r.get("type")))
     50        if (!r.hasTag("type", "restriction"))
    5151            return;
    5252
     
    224224
    225225    private static boolean isFullOneway(Way w) {
    226         return w.isOneway() != 0 && !"no".equals(w.get("oneway:bicycle"));
     226        return w.isOneway() != 0 && !w.hasTag("oneway:bicycle", "no");
    227227    }
    228228
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r11587 r11608  
    306306            this.isAbandoned = "abandoned".equals(railway) || w.isKeyTrue("disused");
    307307            this.highway = (highway != null || railway != null) && !isAbandoned;
    308             this.isBoundary = !this.highway && "administrative".equals(w.get("boundary"));
     308            this.isBoundary = !this.highway && w.hasTag("boundary", "administrative");
    309309            line = new Line2D.Double(n1.getEastNorth().east(), n1.getEastNorth().north(),
    310310                    n2.getEastNorth().east(), n2.getEastNorth().north());
Note: See TracChangeset for help on using the changeset viewer.