/*
 * Copyright (c) 2013-2018 Cinchapi Inc.
 *
 * 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 com.cinchapi.concourse.util;

import java.util.function.Function;

import com.cinchapi.ccl.Parser;
import com.cinchapi.ccl.type.Operator;
import com.cinchapi.concourse.lang.Language;
import com.cinchapi.concourse.thrift.TCriteria;
import com.google.common.collect.Multimap;

/**
 * Utilities for {@link Parser}s.
 *
 * @author Jeff Nelson
 */
public final class Parsers {

    /**
     * The canonical function to transform strings to java values in a
     * {@link Parser}.
     */
    public static final Function<String, Object> PARSER_TRANSFORM_VALUE_FUNCTION = value -> Convert
            .stringToJava(value);

    /**
     * The canonical function to transform strings to operators in a
     * {@link Parser}.
     */
    public static final Function<String, Operator> PARSER_TRANSFORM_OPERATOR_FUNCTION = operator -> Convert
            .stringToOperator(operator);

    /**
     * Return a {@link Parser} for the {@code ccl} statement.
     * 
     * @param ccl a CCL statement
     * @return a {@link Parser}
     */
    public static Parser create(String ccl) {
        return Parser.create(ccl, PARSER_TRANSFORM_VALUE_FUNCTION,
                PARSER_TRANSFORM_OPERATOR_FUNCTION);
    }

    /**
     * Return a {@link Parser} for the {@code ccl} statement that uses the
     * provided {@code data} for local resolution.
     * 
     * @param ccl a CCL statement
     * @param data a dataset
     * @return a {@link Parser}
     */
    public static Parser create(String ccl, Multimap<String, Object> data) {
        return Parser.create(ccl, data, PARSER_TRANSFORM_VALUE_FUNCTION,
                PARSER_TRANSFORM_OPERATOR_FUNCTION);
    }

    /**
     * Return a {@link Parser} for the {@code ccl} statement.
     * 
     * @param criteria
     * @return a {@link Parser}
     */
    public static Parser create(TCriteria criteria) {
        return create(
                Language.translateFromThriftCriteria(criteria).getCclString());
    }

    /**
     * Return a {@link Parser} for the {@code ccl} statement that uses the
     * provided {@code data} for local resolution.
     * 
     * @param criteria
     * @param data a dataset
     * @return a {@link Parser}
     */
    public static Parser create(TCriteria criteria,
            Multimap<String, Object> data) {
        return create(
                Language.translateFromThriftCriteria(criteria).getCclString(),
                data);
    }

    private Parsers() {/* no-init */}

}

@@ -741,16 +741,61 @@
 erator;%0A
+import com.cinchapi.concourse.lang.Criteria;%0A
 import c
@@ -1520,24 +1520,654 @@
 operator);%0A%0A
+    /**%0A     * Return a %7B@link Parser%7D for the %7B@code criteria%7D.%0A     * %0A     * @param criteria%0A     * @return a %7B@link Parser%7D%0A     */%0A    public static Parser create(Criteria criteria) %7B%0A        return create(criteria.getCclString());%0A    %7D%0A%0A    /**%0A     * Return a %7B@link Parser%7D for the %7B@code criteria%7D that uses the provided%0A     * %7B@code data%7D for local resolution.%0A     * %0A     * @param criteria%0A     * @param data a dataset%0A     * @return a %7B@link Parser%7D%0A     */%0A    public static Parser create(Criteria criteria,%0A            Multimap%3CString, Object%3E data) %7B%0A        return create(criteria.getCclString(), data);%0A    %7D%0A%0A
     /**%0A    
@@ -2390,91 +2390,72 @@
 cl, 
-PARSER_TRANSFORM_VALUE_FUNCTION,%0A                PARSER_TRANSFORM_OPERATOR_FUNCTION
+Convert::stringToJava,%0A                Convert::stringToOperator
 );%0A 
@@ -2826,91 +2826,72 @@
 ta, 
-PARSER_TRANSFORM_VALUE_FUNCTION,%0A                PARSER_TRANSFORM_OPERATOR_FUNCTION
+Convert::stringToJava,%0A                Convert::stringToOperator
 );%0A 
@@ -2947,37 +2947,32 @@
 the %7B@code c
-cl%7D statement
+riteria%7D
 .%0A     * %0A  
@@ -3247,37 +3247,32 @@
 the %7B@code c
-cl%7D statement
+riteria%7D
  that uses t
@@ -3265,39 +3265,32 @@
 a%7D that uses the
-%0A     *
  provided %7B@code
@@ -3274,32 +3274,39 @@
 ses the provided
+%0A     *
  %7B@code data%7D fo

add Parsers#create methods that take a Criteria object