static Credentials matchCredentials(final Map<AuthScope, Credentials> map, final AuthScope authScope) {
        // see if we get a direct hit
        Credentials creds = map.get(authScope);
        if (creds == null) {
            // Nope.
            // Do a full scan
            int bestMatchFactor = -1;
            AuthScope bestMatch = null;
            for (final AuthScope current: map.keySet()) {
                final int factor = authScope.match(current);
                if (factor > bestMatchFactor) {
                    bestMatchFactor = factor;
                    bestMatch = current;
                }
            }
            if (bestMatch != null) {
                creds = map.get(bestMatch);
            }
        }
        return creds;
    }
Find matching {@link Credentials credentials} for the given authentication scope.

@param map the credentials hash map
@param authScope the {@link AuthScope authentication scope}
@return the credentials
httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/CredentialsMatcher.java