001/*
002 * Copyright (C) 2012 Facebook, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may
005 * not use this file except in compliance with the License. You may obtain
006 * a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016package com.facebook.swift.codec.metadata;
017
018import com.google.common.base.Preconditions;
019
020import javax.annotation.concurrent.Immutable;
021import java.lang.reflect.Method;
022
023@Immutable
024public class TypeCoercion
025{
026    private final ThriftType thriftType;
027    private final Method toThrift;
028    private final Method fromThrift;
029
030    public TypeCoercion(ThriftType thriftType, Method toThrift, Method fromThrift)
031    {
032        Preconditions.checkNotNull(thriftType, "thriftType is null");
033        Preconditions.checkNotNull(toThrift, "toThrift is null");
034        Preconditions.checkNotNull(fromThrift, "fromThrift is null");
035
036        this.thriftType = thriftType;
037        this.toThrift = toThrift;
038        this.fromThrift = fromThrift;
039    }
040
041    public ThriftType getThriftType()
042    {
043        return thriftType;
044    }
045
046    public Method getToThrift()
047    {
048        return toThrift;
049    }
050
051    public Method getFromThrift()
052    {
053        return fromThrift;
054    }
055
056    @Override
057    public String toString()
058    {
059        final StringBuilder sb = new StringBuilder();
060        sb.append("TypeCoercion");
061        sb.append("{thriftType=").append(thriftType);
062        sb.append(", toThrift=").append(toThrift);
063        sb.append(", fromThrift=").append(fromThrift);
064        sb.append('}');
065        return sb.toString();
066    }
067}