/*
 * Licensed to CRATE Technology 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.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;

public class MatchOptionsAnalysis {

    private static final Predicate<Object> POSITIVE_NUMBER = new Predicate<Object>() {
        @Override
        public boolean apply(@Nullable Object input) {
            return input != null && input instanceof Number && ((Number) input).doubleValue() > 0;
        }
    };
    private static final Predicate<Object> IS_STRING = Predicates.instanceOf(String.class);
    private static final Predicate<Object> IS_NUMBER = Predicates.instanceOf(Number.class);
    private static final Predicate<Object> NUMBER_OR_STRING = Predicates.or(IS_STRING, IS_NUMBER);

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

    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.apply(value)) {
                throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "invalid value for option '%s': %s", optionName, value));
            }
        }
    }
}

@@ -1047,49 +1047,8 @@
 e;%0A%0A
-import com.google.common.base.Predicate;%0A
 impo
@@ -1085,16 +1085,16 @@
 icates;%0A
+
 import c
@@ -1137,42 +1137,8 @@
 p;%0A%0A
-import javax.annotation.Nullable;%0A
 impo
@@ -1204,16 +1204,53 @@
 til.Map;
+%0Aimport java.util.function.Predicate;
 %0A%0Apublic
@@ -1345,148 +1345,14 @@
 R = 
-new Predicate%3CObject%3E() %7B%0A        @Override%0A        public boolean apply(@Nullable Object input) %7B%0A            return input != null && input
+x -%3E x
  ins
@@ -1383,13 +1383,9 @@
 er) 
-input
+x
 ).do
@@ -1405,25 +1405,8 @@
  0;%0A
-        %7D%0A    %7D;%0A
     
@@ -1456,35 +1456,31 @@
 TRING = 
-Predicates.
+x -%3E x 
 instance
 Of(Strin
@@ -1475,24 +1475,17 @@
 ance
-Of(
+of 
 String
-.class)
 ;%0A  
@@ -1541,27 +1541,23 @@
 R = 
-Predicates.
+x -%3E x 
 instance
 Of(N
@@ -1556,24 +1556,17 @@
 ance
-Of(
+of 
 Number
-.class)
 ;%0A  
@@ -1625,26 +1625,25 @@
 TRING = 
-Predicates
+IS_NUMBER
 .or(IS_S
@@ -1647,27 +1647,16 @@
 S_STRING
-, IS_NUMBER
 );%0A%0A    
@@ -2996,13 +2996,12 @@
 tor.
-apply
+test
 (val

Replace Guava Predicate with JDK Predicate in MatchOptionsAnalysis