/*
 * Licensed to Crate.io GmbH ("Crate") under one or more contributor
 * license agreements.  See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.  Crate licenses
 * this file to you 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.
 *
 * However, if you have executed another commercial license agreement
 * with Crate these terms will supersede the license and you may use the
 * software solely pursuant to the terms of the relevant commercial agreement.
 */

package io.crate.analyze;

import com.google.common.base.Predicates;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;

import static java.util.Map.entry;

public class MatchOptionsAnalysis {

    private static final Predicate<Object> POSITIVE_NUMBER = x -> x instanceof Number && ((Number) x).doubleValue() > 0;
    private static final Predicate<Object> IS_STRING = x -> x instanceof String;
    private static final Predicate<Object> IS_NUMBER = x -> x instanceof Number;
    private static final Predicate<Object> NUMBER_OR_STRING = IS_NUMBER.or(IS_STRING);

    private static final Map<String, Predicate<Object>> ALLOWED_SETTINGS = Map.ofEntries(
        entry("analyzer", IS_STRING),
        entry("boost", POSITIVE_NUMBER),
        entry("cutoff_frequency", POSITIVE_NUMBER),
        entry("fuzziness", NUMBER_OR_STRING), // validated at ES QueryParser
        entry("fuzzy_rewrite", IS_STRING),
        entry("max_expansions", POSITIVE_NUMBER),
        entry("minimum_should_match", NUMBER_OR_STRING),
        entry(
            "operator",
            Predicates.in(List.of("or", "and", "OR", "AND"))),
        entry("prefix_length", POSITIVE_NUMBER),
        entry("rewrite", IS_STRING),
        entry("slop", POSITIVE_NUMBER),
        entry("tie_breaker", IS_NUMBER),
        entry("zero_terms_query", IS_STRING)
    );

    public static void validate(Map<String, Object> options) {
        for (Map.Entry<String, Object> e : options.entrySet()) {
            String optionName = e.getKey();
            Predicate<Object> validator = ALLOWED_SETTINGS.get(optionName);
            if (validator == null) {
                throw new IllegalArgumentException(
                    String.format(Locale.ENGLISH, "unknown match option '%s'", optionName));
            }
            Object value = e.getValue();
            if (!validator.test(value)) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "invalid value for option '%s': %s", optionName, value));
            }
        }
    }
}

@@ -1037,74 +1037,8 @@
 e;%0A%0A
-import com.google.common.base.Predicates;%0A%0Aimport java.util.List;%0A
 impo
@@ -1080,16 +1080,38 @@
 il.Map;%0A
+import java.util.Set;%0A
 import j
@@ -1582,16 +1582,117 @@
 STRING);
+%0A    private static final Predicate%3CObject%3E IS_OPERATOR = Set.of(%22or%22, %22and%22, %22OR%22, %22AND%22)::contains;
 %0A%0A    pr
@@ -2151,93 +2151,31 @@
 try(
-%0A            %22operator%22,%0A            Predicates.in(List.of(%22or%22, %22and%22, %22OR%22, %22AND%22))
+%22operator%22, IS_OPERATOR
 ),%0A 

Remove Guava's Predicates