Ticket #24075: 24075.KeyedItem_match.patch

File 24075.KeyedItem_match.patch, 4.3 KB (added by taylor.smock, 15 months ago)

KeyedItem.match visibility reduction

  • src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    Subject: [PATCH] #24075: KeyedItem precalculated match enum
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java b/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
    a b  
    420420                List<TaggingPresetItem> minData = new ArrayList<>();
    421421                for (TaggingPresetItem i : p.data) {
    422422                    if (i instanceof KeyedItem) {
    423                         if (!"none".equals(((KeyedItem) i).match))
     423                        if (!"none".equals(((KeyedItem) i).match()))
    424424                            minData.add(i);
    425425                        addPresetValue((KeyedItem) i);
    426426                    } else if (i instanceof CheckGroup) {
    427427                        for (Check c : ((CheckGroup) i).checks) {
    428                             if (!"none".equals(c.match))
     428                            if (!"none".equals(c.match()))
    429429                                minData.add(c);
    430430                            addPresetValue(c);
    431431                        }
  • src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java
    a b  
    5151     * Note that for a match, at least one positive and no negative is required.
    5252     * Default is "keyvalue!" for {@link Key} and "none" for {@link Text}, {@link Combo}, {@link MultiSelect} and {@link Check}.
    5353     */
    54     public String match = getDefaultMatch().getValue(); // NOSONAR
     54    protected MatchType match = getDefaultMatch(); // NOSONAR
    5555
    5656    /**
    5757     * List of regions the preset is applicable for.
     
    181181        }
    182182    }
    183183
     184    /**
     185     * Allows to change the matching process, i.e., determining whether the tags of an OSM object fit into this preset.
     186     * If a preset fits then it is linked in the Tags/Membership dialog.<ul>
     187     * <li>none: neutral, i.e., do not consider this item for matching</li>
     188     * <li>key: positive if key matches, neutral otherwise</li>
     189     * <li>key!: positive if key matches, negative otherwise</li>
     190     * <li>keyvalue: positive if key and value matches, neutral otherwise</li>
     191     * <li>keyvalue!: positive if key and value matches, negative otherwise</li></ul>
     192     * Note that for a match, at least one positive and no negative is required.
     193     * Default is "keyvalue!" for {@link Key} and "none" for {@link Text}, {@link Combo}, {@link MultiSelect} and {@link Check}.
     194     * @param match The match type. One of <code>none</code>, <code>key</code>, <code>key!</code>, <code>keyvalue</code>,
     195     *              or <code>keyvalue!</code>.
     196     * @since xxx
     197     */
     198    public void setMatch(String match) {
     199        this.match = MatchType.ofString(match);
     200    }
     201
     202    /**
     203     * Get the match type for this item
     204     * @return The match type
     205     * @since xxx
     206     */
     207    public String match() {
     208        return this.match.getValue();
     209    }
     210
    184211    /**
    185212     * Computes the tag usage for the given key from the given primitives
    186213     * @param sel the primitives
     
    221248     * @return whether key or key+value are required
    222249     */
    223250    public boolean isKeyRequired() {
    224         final MatchType type = MatchType.ofString(match);
     251        final MatchType type = this.match;
    225252        return MatchType.KEY_REQUIRED == type || MatchType.KEY_VALUE_REQUIRED == type;
    226253    }
    227254
     
    243270
    244271    @Override
    245272    public Boolean matches(Map<String, String> tags) {
    246         switch (MatchType.ofString(match)) {
     273        switch (this.match) {
    247274        case NONE:
    248275            return null; // NOSONAR
    249276        case KEY: