Changeset 13668 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-04-23T22:28:34+02:00 (7 years ago)
Author:
Don-vip
Message:

move a few methods from AbstractPrimitive to Tagged

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

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

    r13637 r13668  
    1212import java.util.Map;
    1313import java.util.Map.Entry;
    14 import java.util.Objects;
    1514import java.util.Set;
    1615import java.util.concurrent.TimeUnit;
     
    467466    }
    468467
    469     /**
    470      * Calls the visitor for every key/value pair of this primitive.
    471      *
    472      * @param visitor The visitor to call.
    473      * @see #getKeys()
    474      * @since 8742
    475      */
     468    @Override
    476469    public void visitKeys(KeyValueVisitor visitor) {
    477470        final String[] keys = this.keys;
     
    769762        return getName();
    770763    }
    771 
    772     /**
    773      * Tests whether this primitive contains a tag consisting of {@code key} and {@code value}.
    774      * @param key the key forming the tag.
    775      * @param value value forming the tag.
    776      * @return true if primitive contains a tag consisting of {@code key} and {@code value}.
    777      */
    778     public boolean hasTag(String key, String value) {
    779         return Objects.equals(value, get(key));
    780     }
    781 
    782     /**
    783      * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}.
    784      * @param key the key forming the tag.
    785      * @param values one or many values forming the tag.
    786      * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}.
    787      */
    788     public boolean hasTag(String key, String... values) {
    789         return hasTag(key, Arrays.asList(values));
    790     }
    791 
    792     /**
    793      * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}.
    794      * @param key the key forming the tag.
    795      * @param values one or many values forming the tag.
    796      * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}.
    797      */
    798     public boolean hasTag(String key, Collection<String> values) {
    799         return values.contains(get(key));
    800     }
    801 
    802     /**
    803      * Tests whether this primitive contains a tag consisting of {@code key} and a value different from {@code value}.
    804      * @param key the key forming the tag.
    805      * @param value value not forming the tag.
    806      * @return true if primitive contains a tag consisting of {@code key} and a value different from {@code value}.
    807      * @since 11608
    808      */
    809     public boolean hasTagDifferent(String key, String value) {
    810         String v = get(key);
    811         return v != null && !v.equals(value);
    812     }
    813 
    814     /**
    815      * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
    816      * @param key the key forming the tag.
    817      * @param values one or many values forming the tag.
    818      * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
    819      * @since 11608
    820      */
    821     public boolean hasTagDifferent(String key, String... values) {
    822         return hasTagDifferent(key, Arrays.asList(values));
    823     }
    824 
    825     /**
    826      * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
    827      * @param key the key forming the tag.
    828      * @param values one or many values forming the tag.
    829      * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
    830      * @since 11608
    831      */
    832     public boolean hasTagDifferent(String key, Collection<String> values) {
    833         String v = get(key);
    834         return v != null && !values.contains(v);
    835     }
    836764}
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r13625 r13668  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.Arrays;
    45import java.util.Collection;
    56import java.util.Map;
     7import java.util.Objects;
    68
    79/**
     
    3537
    3638    /**
     39     * Calls the visitor for every key/value pair.
     40     *
     41     * @param visitor The visitor to call.
     42     * @see #getKeys()
     43     * @since 13668
     44     */
     45    default void visitKeys(KeyValueVisitor visitor) {
     46        getKeys().forEach((k, v) -> visitor.visitKeyValue(this, k, v));
     47    }
     48
     49    /**
    3750     * Sets a key/value pairs
    3851     *
     
    101114
    102115    /**
     116     * Tests whether this primitive contains a tag consisting of {@code key} and {@code value}.
     117     * @param key the key forming the tag.
     118     * @param value value forming the tag.
     119     * @return true if primitive contains a tag consisting of {@code key} and {@code value}.
     120     * @since 13668
     121     */
     122    default boolean hasTag(String key, String value) {
     123        return Objects.equals(value, get(key));
     124    }
     125
     126    /**
     127     * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}.
     128     * @param key the key forming the tag.
     129     * @param values one or many values forming the tag.
     130     * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}.
     131     * @since 13668
     132     */
     133    default boolean hasTag(String key, String... values) {
     134        return hasTag(key, Arrays.asList(values));
     135    }
     136
     137    /**
     138     * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}.
     139     * @param key the key forming the tag.
     140     * @param values one or many values forming the tag.
     141     * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}.
     142     * @since 13668
     143     */
     144    default boolean hasTag(String key, Collection<String> values) {
     145        return values.contains(get(key));
     146    }
     147
     148    /**
     149     * Tests whether this primitive contains a tag consisting of {@code key} and a value different from {@code value}.
     150     * @param key the key forming the tag.
     151     * @param value value not forming the tag.
     152     * @return true if primitive contains a tag consisting of {@code key} and a value different from {@code value}.
     153     * @since 13668
     154     */
     155    default boolean hasTagDifferent(String key, String value) {
     156        String v = get(key);
     157        return v != null && !v.equals(value);
     158    }
     159
     160    /**
     161     * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
     162     * @param key the key forming the tag.
     163     * @param values one or many values forming the tag.
     164     * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
     165     * @since 13668
     166     */
     167    default boolean hasTagDifferent(String key, String... values) {
     168        return hasTagDifferent(key, Arrays.asList(values));
     169    }
     170
     171    /**
     172     * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}.
     173     * @param key the key forming the tag.
     174     * @param values one or many values forming the tag.
     175     * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}.
     176     * @since 13668
     177     */
     178    default boolean hasTagDifferent(String key, Collection<String> values) {
     179        String v = get(key);
     180        return v != null && !values.contains(v);
     181    }
     182
     183    /**
    103184     * Replies the set of keys
    104185     *
Note: See TracChangeset for help on using the changeset viewer.