src/main/java/de/blau/android/presets/Preset.java
/**
     * Finds the preset item best matching a certain tag set, or null if no preset item matches. To match, all
     * (mandatory) tags of the preset item need to be in the tag set. The preset item does NOT need to have all tags in
     * the tag set, but the tag set needs to have all (mandatory) tags of the preset item.
     * 
     * If multiple items match, the most specific one (i.e. having most tags) wins. If there is a draw, no guarantees
     * are made.
     * 
     * @param presets presets presets to match against
     * @param tags tags to check against (i.e. tags of a map element)
     * @param region if not null this will be taken in to account wrt scoring
     * @param useAddressKeys use addr: keys if true
     * @return a preset or null if none found
     */
Finds the preset item best matching a certain tag set, or null if no preset item matches. To match, all
(mandatory) tags of the preset item need to be in the tag set. The preset item does NOT need to have all tags in
the tag set, but the tag set needs to have all (mandatory) tags of the preset item.

If multiple items match, the most specific one  wins. If there is a draw, no guarantees
are made.


Finds the preset item best matching a certain tag set or null if no preset item matches . To match all ( mandatory ) tags of the preset item need to be in the tag set . The preset item does NOT need to have all tags in the tag set but the tag set needs to have all ( mandatory ) tags of the preset item . If multiple items match the most specific one wins . If there is a draw no guarantees are made .
@Nullable
    public static PresetItem findBestMatch(@Nullable Preset[] presets, @Nullable Map<String, String> tags, @Nullable String region, boolean useAddressKeys) {
        int bestMatchStrength = 0;
        PresetItem bestMatch = null;
        if (tags == null || presets == null) {
            Log.e(DEBUG_TAG, "findBestMatch " + (tags == null ? "tags null" : "presets null"));
            return null;
        }
        Set<PresetItem> possibleMatches = buildPossibleMatches(presets, tags, false);
        if (useAddressKeys && possibleMatches.isEmpty()) {
            possibleMatches = buildPossibleMatches(presets, tags, true);
        }
        final int FIXED_WEIGHT = 1000; 
        for (PresetItem possibleMatch : possibleMatches) {
            int fixedTagCount = possibleMatch.getFixedTagCount() * FIXED_WEIGHT;
            int recommendedTagCount = possibleMatch.getRecommendedKeyCount();
            if (fixedTagCount + recommendedTagCount >= bestMatchStrength) {
                int matches = 0;
                if (fixedTagCount > 0) {
                    if (!possibleMatch.matches(tags)) {
                        continue; 
                    }
                    matches = fixedTagCount;
                }
                if (region != null && !possibleMatch.appliesIn(region)) {
                    matches -= 200;
                }
                if (recommendedTagCount > 0) {
                    matches = matches + possibleMatch.matchesRecommended(tags);
                }
                if (matches > bestMatchStrength) {
                    bestMatch = possibleMatch;
                    bestMatchStrength = matches;
                }
            }
        }
        return bestMatch;
    }
@ Nullable public static PresetItem findBestMatch ( @ Nullable Preset [ ] presets , @ Nullable Map < String , String > tags , @ Nullable String region , boolean useAddressKeys ) { int bestMatchStrength = 0 ; PresetItem bestMatch = null ; if ( tags == null || presets == null ) { Log . e ( DEBUG_TAG , "findBestMatch " + ( tags == null ? "tags null" : "presets null" ) ) ; return null ; } Set < PresetItem > possibleMatches = buildPossibleMatches ( presets , tags , false ) ; if ( useAddressKeys && possibleMatches . isEmpty ( ) ) { possibleMatches = buildPossibleMatches ( presets , tags , true ) ; } final int FIXED_WEIGHT = 1000 ; for ( PresetItem possibleMatch : possibleMatches ) { int fixedTagCount = possibleMatch . getFixedTagCount ( ) * FIXED_WEIGHT ; int recommendedTagCount = possibleMatch . getRecommendedKeyCount ( ) ; if ( fixedTagCount + recommendedTagCount >= bestMatchStrength ) { int matches = 0 ; if ( fixedTagCount > 0 ) { if ( ! possibleMatch . matches ( tags ) ) { continue ; } matches = fixedTagCount ; } if ( region != null && ! possibleMatch . appliesIn ( region ) ) { matches -= 200 ; } if ( recommendedTagCount > 0 ) { matches = matches + possibleMatch . matchesRecommended ( tags ) ; } if ( matches > bestMatchStrength ) { bestMatch = possibleMatch ; bestMatchStrength = matches ; } } } return bestMatch ; }
Finds the preset item best matching a certain tag set, or null if no preset item matches.
Finds the preset item best matching a certain tag set or null if no preset item matches .
// Build candidate list // if we only have address keys retry // Find best // always prioritize presets with fixed keys // minimum requirement // has all required tags // downgrade so much that recommended tags can't compensate