/*
 * 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 io.prestosql.connector.system.jdbc;

import io.airlift.slice.Slice;
import io.prestosql.metadata.QualifiedTablePrefix;
import io.prestosql.spi.predicate.Domain;
import io.prestosql.spi.predicate.TupleDomain;

import java.util.Optional;

public final class FilterUtil
{
    private FilterUtil() {}

    public static <T> Optional<String> tryGetSingleVarcharValue(TupleDomain<T> constraint, T index)
    {
        if (constraint.isNone()) {
            return Optional.empty();
        }

        Domain domain = constraint.getDomains().get().get(index);
        if ((domain == null) || !domain.isSingleValue()) {
            return Optional.empty();
        }

        Object value = domain.getSingleValue();
        return Optional.of(((Slice) value).toStringUtf8());
    }

    public static QualifiedTablePrefix tablePrefix(String catalog, Optional<String> schema, Optional<String> table)
    {
        QualifiedTablePrefix prefix = new QualifiedTablePrefix(catalog);
        if (schema.isPresent()) {
            prefix = new QualifiedTablePrefix(catalog, schema.get());
            if (table.isPresent()) {
                prefix = new QualifiedTablePrefix(catalog, schema.get(), table.get());
            }
        }
        return prefix;
    }

    public static <T> boolean emptyOrEquals(Optional<T> value, T other)
    {
        return !value.isPresent() || value.get().equals(other);
    }
}

@@ -1472,91 +1472,39 @@
     
-QualifiedTablePrefix prefix = new QualifiedTablePrefix(catalog);%0A        if (schema
+if (schema.isPresent() && table
 .isP
@@ -1523,32 +1523,30 @@
             
-p
 re
-fix =
+turn
  new Qualifi
@@ -1576,31 +1576,50 @@
 schema.get()
+, table.get()
 );%0A    
+    %7D%0A
         if (
@@ -1618,21 +1618,22 @@
     if (
-table
+schema
 .isPrese
@@ -1656,20 +1656,14 @@
     
-    prefix =
+return
  new
@@ -1709,69 +1709,69 @@
 et()
-, table.get());%0A            %7D%0A        %7D%0A        return prefix
+);%0A        %7D%0A        return new QualifiedTablePrefix(catalog)
 ;%0A  

Simplify control flow