<commit_before>/*
 * Copyright 2010-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package be.objectify.deadbolt.java.composite;

import be.objectify.deadbolt.java.DeadboltHandler;
import play.mvc.Http;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;

/**
 * @author <NAME> (<EMAIL>)
 */
@FunctionalInterface
public interface Constraint
{
    default CompletionStage<Boolean> test(Http.Context context,
                                          DeadboltHandler handler)
    {
        return test(context,
                    handler,
                    Optional.empty(),
                    (globalMeta, localMeta) -> localMeta);
    }

    CompletionStage<Boolean> test(Http.Context context,
                                  DeadboltHandler handler,
                                  Optional<String> globalMetaData,
                                  BiFunction<Optional<String>, Optional<String>, Optional<String>> metaFn);

    default Constraint and(final Constraint other)
    {
        Objects.requireNonNull(other);
        return (ctx, handler, global, fMeta) ->
                test(ctx, handler, global, fMeta).thenCompose(passed1 -> passed1 ? other.test(ctx, handler, global, fMeta).thenApply(passed2 -> passed2)
                                                                                 : CompletableFuture.completedFuture(false));
    }

    default Constraint negate()
    {
        return (ctx, handler, global, fMeta) -> test(ctx, handler, global, fMeta).thenApply(p -> !p);
    }

    default Constraint or(final Constraint other)
    {
        Objects.requireNonNull(other);
        return (ctx, handler, global, fMeta) ->
                test(ctx, handler, global, fMeta).thenCompose(passed1 -> passed1 ? CompletableFuture.completedFuture(true)
                                                                                                : other.test(ctx, handler, global, fMeta).thenApply(passed2 -> passed2));
    }
}<commit_msg>Switch to RequestHeader in Constraint<commit_after>/*
 * Copyright 2010-2017 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package be.objectify.deadbolt.java.composite;

import be.objectify.deadbolt.java.DeadboltHandler;
import play.mvc.Http;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;

/**
 * @author <NAME> (<EMAIL>)
 */
@FunctionalInterface
public interface Constraint
{
    default CompletionStage<Boolean> test(Http.RequestHeader requestHeader,
                                          DeadboltHandler handler)
    {
        return test(requestHeader,
                    handler,
                    Optional.empty(),
                    (globalMeta, localMeta) -> localMeta);
    }

    CompletionStage<Boolean> test(Http.RequestHeader requestHeader,
                                  DeadboltHandler handler,
                                  Optional<String> globalMetaData,
                                  BiFunction<Optional<String>, Optional<String>, Optional<String>> metaFn);

    default Constraint and(final Constraint other)
    {
        Objects.requireNonNull(other);
        return (ctx, handler, global, fMeta) ->
                test(ctx, handler, global, fMeta).thenCompose(passed1 -> passed1 ? other.test(ctx, handler, global, fMeta).thenApply(passed2 -> passed2)
                                                                                 : CompletableFuture.completedFuture(false));
    }

    default Constraint negate()
    {
        return (ctx, handler, global, fMeta) -> test(ctx, handler, global, fMeta).thenApply(p -> !p);
    }

    default Constraint or(final Constraint other)
    {
        Objects.requireNonNull(other);
        return (ctx, handler, global, fMeta) ->
                test(ctx, handler, global, fMeta).thenCompose(passed1 -> passed1 ? CompletableFuture.completedFuture(true)
                                                                                                : other.test(ctx, handler, global, fMeta).thenApply(passed2 -> passed2));
    }
}
{'fraction_non_alphanumeric': 0.0920407393436439, 'fraction_numerical': 0.007544322897019992, 'mean_word_length': 2.1926550270921132, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5655916', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1272, 'n_words': 376}