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.Joiner; 019import com.google.common.collect.ImmutableList; 020 021import javax.annotation.concurrent.Immutable; 022import java.lang.reflect.Constructor; 023import java.util.List; 024 025import static com.google.common.base.Preconditions.checkNotNull; 026 027@Immutable 028public class ThriftConstructorInjection 029{ 030 private final Constructor<?> constructor; 031 private final List<ThriftParameterInjection> parameters; 032 033 public ThriftConstructorInjection(Constructor<?> constructor, ThriftParameterInjection... parameters) 034 { 035 this(checkNotNull(constructor, "constructor is null"), 036 ImmutableList.copyOf(checkNotNull(parameters, "parameters is null"))); 037 } 038 039 public ThriftConstructorInjection(Constructor<?> constructor, List<ThriftParameterInjection> parameters) 040 { 041 this.constructor = checkNotNull(constructor, "constructor is null"); 042 this.parameters = ImmutableList.copyOf(checkNotNull(parameters, "parameters is null")); 043 } 044 045 public Constructor<?> getConstructor() 046 { 047 return constructor; 048 } 049 050 public List<ThriftParameterInjection> getParameters() 051 { 052 return parameters; 053 } 054 055 @Override 056 public String toString() 057 { 058 final StringBuilder sb = new StringBuilder(); 059 sb.append(constructor.getName()); 060 sb.append('('); 061 Joiner.on(", ").appendTo(sb, parameters); 062 sb.append(')'); 063 return sb.toString(); 064 } 065}