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 javax.annotation.concurrent.Immutable;
019
020import java.lang.reflect.Type;
021
022import static com.google.common.base.Preconditions.checkArgument;
023import static com.google.common.base.Preconditions.checkNotNull;
024
025@Immutable
026public class ThriftParameterInjection implements ThriftInjection
027{
028    private final short id;
029    private final String name;
030    private final int parameterIndex;
031    private final Type javaType;
032
033    public ThriftParameterInjection(
034            short id,
035            String name,
036            int parameterIndex,
037            Type javaType)
038    {
039
040        checkArgument(id >= 0, "fieldId is negative");
041        checkArgument(parameterIndex >= 0, "parameterIndex is negative");
042
043        this.javaType = checkNotNull(javaType, "javaType is null");
044        this.name = checkNotNull(name, "name is null");
045
046        this.id = id;
047        this.parameterIndex = parameterIndex;
048    }
049
050    @Override
051    public short getId()
052    {
053        return id;
054    }
055
056    @Override
057    public String getName()
058    {
059        return name;
060    }
061
062    @Override
063    public FieldKind getFieldKind()
064    {
065        return FieldKind.THRIFT_FIELD;
066    }
067
068    public int getParameterIndex()
069    {
070        return parameterIndex;
071    }
072
073    public Type getJavaType()
074    {
075        return javaType;
076    }
077
078    @Override
079    public String toString()
080    {
081        final StringBuilder sb = new StringBuilder();
082        sb.append("ThriftParameterInjection");
083        sb.append("{fieldId=").append(id);
084        sb.append(", name=").append(name);
085        sb.append(", index=").append(parameterIndex);
086        sb.append(", javaType=").append(javaType);
087        sb.append('}');
088        return sb.toString();
089    }
090}