@@ -0,0 +1,1781 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.util;%0A%0Aimport java.util.Optional;%0A%0Aimport static com.google.common.base.Preconditions.checkArgument;%0A%0Apublic class Types%0A%7B%0A    private Types() %7B%7D%0A%0A    public static %3CT%3E T checkType(Object object, Class%3CT%3E expectedClass)%0A    %7B%0A        return checkType(object, expectedClass, %22Expected an object of type %5B%25s%5D%22, expectedClass.getCanonicalName());%0A    %7D%0A%0A    public static %3CT%3E T checkType(Object object, Class%3CT%3E expectedClass, String messageTemplate, Object... arguments)%0A    %7B%0A        checkArgument(expectedClass.isInstance(object), messageTemplate, arguments);%0A        return expectedClass.cast(object);%0A    %7D%0A%0A    public static void checkSameType(Object left, Object right)%0A    %7B%0A        Class%3C?%3E leftClass = left.getClass();%0A        Class%3C?%3E rightClass = right.getClass();%0A        String message = %22Values must be of same type, got %5B%25s : %25s%5D and %5B%25s : %25s%5D%22;%0A        checkArgument(leftClass.equals(rightClass), message, left, leftClass, right, rightClass);%0A    %7D%0A%0A    public static %3CR, T extends R%3E Optional%3CR%3E tryCast(Optional%3C?%3E optional, Class%3CT%3E targetClass)%0A    %7B%0A        return optional%0A                .filter(targetClass::isInstance)%0A                .map(targetClass::cast);%0A    %7D%0A%7D%0A

Add Types.{checkType,checkSameTypes,tryCast} util methods