/*
 * 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.hive.util;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

public final class Types
{
    private Types() {}

    public static <A, B extends A> B checkType(A value, Class<B> target, String name)
    {
        checkNotNull(value, "%s is null", name);
        checkArgument(target.isInstance(value),
                "%s must be of type %s, not %s",
                name,
                target.getName(),
                value.getClass().getName());
        return target.cast(value);
    }
}

@@ -595,16 +595,107 @@
 .util;%0A%0A
+import com.facebook.presto.spi.ErrorCode;%0Aimport com.facebook.presto.spi.PrestoException;%0A%0A
 import s
@@ -1248,11 +1248,497 @@
 );%0A    %7D
+%0A%0A    public static %3CA, B extends A%3E B checkType(A value, Class%3CB%3E target, ErrorCode errorCode, String name)%0A    %7B%0A        checkNotNull(value, %22%25s is null%22, name);%0A        if (!target.isInstance(value)) %7B%0A            throw new PrestoException(errorCode, String.format(%0A                    %22%25s must be of type %25s, not %25s%22,%0A                    name,%0A                    target.getName(),%0A                    value.getClass().getName()));%0A        %7D%0A        return target.cast(value);%0A    %7D
 %0A%7D%0A

Add checkType that takes an error code