/*
 * 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 com.facebook.presto.spi.type.Type;
import com.google.common.collect.ImmutableMap;

import java.util.Map;
import java.util.Objects;
import java.util.OptionalLong;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.unmodifiableMap;
import static java.util.Objects.requireNonNull;

public class BoundVariables
{
    private final Map<String, Type> typeVariables;
    private final Map<String, OptionalLong> longVariables;

    public BoundVariables(Map<String, Type> typeVariables,
            Map<String, OptionalLong> longVariables)
    {
        requireNonNull(typeVariables, "typeVariableBindings is null");
        requireNonNull(longVariables, "longVariableBindings is null");
        this.typeVariables = ImmutableMap.copyOf(typeVariables);
        this.longVariables = ImmutableMap.copyOf(longVariables);
    }

    public Type getTypeVariable(String variableName)
    {
        return getValue(typeVariables, variableName);
    }

    public boolean containsTypeVariable(String variableName)
    {
        return containsValue(typeVariables, variableName);
    }

    public Map<String, Type> getTypeVariables()
    {
        return unmodifiableMap(typeVariables);
    }

    public OptionalLong getLongVariable(String variableName)
    {
        return getValue(longVariables, variableName);
    }

    public boolean containsLongVariable(String variableName)
    {
        return containsValue(longVariables, variableName);
    }

    public Map<String, OptionalLong> getLongVariables()
    {
        return unmodifiableMap(longVariables);
    }

    private <T> T getValue(Map<String, T> map, String variableName)
    {
        checkState(variableName != null, "variableName is null");
        T value = map.get(variableName);
        checkState(value != null, "value for variable '%s' is null", variableName);
        return value;
    }

    private boolean containsValue(Map<String, ?> map, String variableName)
    {
        checkState(variableName != null, "variableName is null");
        return map.containsKey(variableName);
    }

    @Override
    public boolean equals(Object o)
    {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BoundVariables that = (BoundVariables) o;
        return Objects.equals(typeVariables, that.typeVariables) &&
                Objects.equals(longVariables, that.longVariables);
    }

    @Override
    public int hashCode()
    {
        return Objects.hash(typeVariables, longVariables);
    }
}

@@ -764,16 +764,81 @@
 lLong;%0A%0A
+import static com.google.common.base.MoreObjects.toStringHelper;%0A
 import s
@@ -3273,11 +3273,238 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public String toString()%0A    %7B%0A        return toStringHelper(this)%0A                .add(%22typeVariables%22, typeVariables)%0A                .add(%22longVariables%22, longVariables)%0A                .toString();%0A    %7D
 %0A%7D%0A

Add BoundVariables.toString()