<commit_before>package org.pac4j.async.core.matching;

import org.pac4j.async.core.context.AsyncWebContext;

import java.util.concurrent.CompletableFuture;

/**
 * Async version of the Matcher class
 */
public interface AsyncMatcher {

    /**
     * Check if the web context matches.
     *
     * @param context the web context
     * @return CompletableFuture which will resolve to true in the event of a match, false in no match
     * or completeExceptionally in the case of an exception during determination of matching. This exception
     * can be an HttpAction so can lead to further http behaviour
     *
     */
    CompletableFuture<Boolean> matches(AsyncWebContext context);


}
<commit_msg>pac4j-async-112 Enable conversion of non-blocking async-convertible matchers into async matchers.<commit_after>package org.pac4j.async.core.matching;

import com.aol.cyclops.invokedynamic.ExceptionSoftener;
import org.pac4j.async.core.AsynchronousComputation;
import org.pac4j.async.core.context.AsyncWebContext;
import org.pac4j.core.context.WebContextBase;
import org.pac4j.core.matching.Matcher;
import org.pac4j.core.profile.CommonProfile;

import java.util.concurrent.CompletableFuture;

/**
 * Async version of the Matcher class
 */
public interface AsyncMatcher {

    /**
     * Given an existing non-blocking but synchronous Matcher, convert it into an async non-blocking
     * one
     */
    static <U extends CommonProfile> AsyncMatcher fromNonBlockingMatcher(final Matcher<WebContextBase<?>> syncMatcher) {
        return context -> AsynchronousComputation.fromNonBlocking(ExceptionSoftener.softenSupplier(() -> syncMatcher.matches(context)));
    }

    /**
     * Check if the web context matches.
     *
     * @param context the web context
     * @return CompletableFuture which will resolve to true in the event of a match, false in no match
     * or completeExceptionally in the case of an exception during determination of matching. This exception
     * can be an HttpAction so can lead to further http behaviour
     *
     */
    CompletableFuture<Boolean> matches(AsyncWebContext context);


}

{'fraction_non_alphanumeric': 0.07670588235294118, 'fraction_numerical': 0.005647058823529412, 'mean_word_length': 3.8099547511312215, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5046857', 'n_tokens_mistral': 595, 'n_tokens_neox': 571, 'n_words': 187}