Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.facebook.presto.metadata;
 
 
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
 public enum OperatorType
 {
     ADD("+")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     SUBTRACT("-")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     MULTIPLY("*")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     DIVIDE("/")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     MODULUS("%")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     NEGATION("-")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateOperatorSignature(thisreturnTypeargumentTypes, 1);
                 }
             },
 
     EQUAL("=")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     NOT_EQUAL("<>")
             {
                 @Override
                 void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                 {
                     validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                 }
             },
 
     LESS_THAN("<")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                }
            },
    LESS_THAN_OR_EQUAL("<=")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                }
            },
    GREATER_THAN(">")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                }
            },
    GREATER_THAN_OR_EQUAL(">=")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 2);
                }
            },
    BETWEEN("BETWEEN")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateComparisonOperatorSignature(thisreturnTypeargumentTypes, 3);
                }
            },
    CAST("CAST")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateOperatorSignature(thisreturnTypeargumentTypes, 1);
                }
            },
    SUBSCRIPT("[]")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateOperatorSignature(thisreturnTypeargumentTypes, 2);
                    checkArgument(argumentTypes.get(0).getBase().equals(.) || argumentTypes.get(0).getBase().equals(.), "First argument must be an ARRAY or MAP");
                    if (argumentTypes.get(0).getBase().equals(.)) {
                        checkArgument(argumentTypes.get(1).getBase().equals(.), "Second argument must be a BIGINT");
                        TypeSignature elementType = argumentTypes.get(0).getParameters().get(0);
                        checkArgument(returnType.equals(elementType), "[] return type does not match ARRAY element type");
                    }
                    else {
                        TypeSignature valueType = argumentTypes.get(0).getParameters().get(1);
                        checkArgument(returnType.equals(valueType), "[] return type does not match MAP value type");
                    }
                }
            },
    HASH_CODE("HASH CODE")
            {
                @Override
                void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes)
                {
                    validateOperatorSignature(thisreturnTypeargumentTypes, 1);
                    checkArgument(returnType.getBase().equals(.), "%s operator must return a BIGINT: %s"thisformatSignature(thisreturnTypeargumentTypes));
                }
            };
    private final String operator;
    OperatorType(String operator)
    {
        this. = operator;
    }
    public String getOperator()
    {
        return ;
    }
    abstract void validateSignature(TypeSignature returnTypeList<TypeSignatureargumentTypes);
    private static void validateOperatorSignature(OperatorType operatorTypeTypeSignature returnTypeList<TypeSignatureargumentTypesint expectedArgumentCount)
    {
        String signature = formatSignature(operatorTypereturnTypeargumentTypes);
        checkArgument(!returnType.getBase().equals(.), "%s operator return type can not be NULL: %s"operatorTypesignature);
        checkArgument(argumentTypes.size() == expectedArgumentCount"%s operator must have exactly %s argument: %s"operatorTypeexpectedArgumentCountsignature);
    }
    private static void validateComparisonOperatorSignature(OperatorType operatorTypeTypeSignature returnTypeList<TypeSignatureargumentTypesint expectedArgumentCount)
    {
        validateOperatorSignature(operatorTypereturnTypeargumentTypesexpectedArgumentCount);
        checkArgument(returnType.getBase().equals(.), "%s operator must return a BOOLEAN: %s"operatorTypeformatSignature(operatorTypereturnTypeargumentTypes));
    }
    private static String formatSignature(OperatorType operatorTypeTypeSignature returnTypeList<TypeSignatureargumentTypes)
    {
        return operatorType + "(" + Joiner.on(", ").join(argumentTypes) + ")::" + returnType;
    }
New to GrepCode? Check out our FAQ X