Changeset 13430 in josm for trunk


Ignore:
Timestamp:
2018-02-17T15:40:42+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #15943 - allow to search empty values

Location:
trunk
Files:
3 edited

Legend:

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

    r13414 r13430  
    7676    /**
    7777     * Replies true if there is a tag with key <code>key</code>.
     78     * The value could however be empty. See {@link #hasTag(String)} to check for non-empty tags.
    7879     *
    7980     * @param key the key
    8081     * @return true, if there is a tag with key <code>key</code>
     82     * @see #hasTag(String)
    8183     * @since 11608
    8284     */
    8385    default boolean hasKey(String key) {
    8486        return get(key) != null;
     87    }
     88
     89    /**
     90     * Replies true if there is a non-empty tag with key <code>key</code>.
     91     *
     92     * @param key the key
     93     * @return true, if there is a non-empty tag with key <code>key</code>
     94     * @see Tagged#hasKey(String)
     95     * @since 13430
     96     */
     97    default boolean hasTag(String key) {
     98        String v = get(key);
     99        return v != null && !v.isEmpty();
    85100    }
    86101
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r13317 r13430  
    836836                return false;
    837837            case MISSING_KEY:
    838                 return osm.get(key) == null;
     838                return !osm.hasTag(key);
    839839            case ANY:
    840840                return true;
    841841            case ANY_VALUE:
    842                 return osm.get(key) != null;
     842                return osm.hasTag(key);
    843843            case ANY_KEY:
    844844                for (String v:osm.getKeys().values()) {
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r13325 r13430  
    496496
    497497    /**
     498     * Test empty values.
     499     * @throws SearchParseError never
     500     */
     501    @Test
     502    public void testEmptyValues15943() throws SearchParseError {
     503        Match matcher = SearchCompiler.compile("access=");
     504        assertTrue(matcher.match(new Tag("access", null)));
     505        assertTrue(matcher.match(new Tag("access", "")));
     506        assertFalse(matcher.match(new Tag("access", "private")));
     507    }
     508
     509    /**
    498510     * Unit test of {@link SearchCompiler.ExactKeyValue.Mode} enum.
    499511     */
     
    562574    }
    563575
    564 
    565576    /**
    566577     * Ensures that correct presets are stored in the {@link org.openstreetmap.josm.data.osm.search.SearchCompiler.Preset}
Note: See TracChangeset for help on using the changeset viewer.