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/osm
Files:
7 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 {
Note: See TracChangeset for help on using the changeset viewer.