package com.mgmtp.perfload.agent.util;


import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import org.apache.commons.lang3.text.StrBuilder;
import org.objectweb.asm.Type;

import java.util.List;

import static com.google.common.collect.FluentIterable.from;
import static org.apache.commons.lang.StringUtils.substringAfterLast;
import static org.apache.commons.lang.StringUtils.substringBeforeLast;

/**
 * Utility class for class names.
 *
 * @since 1.3.0
 * @author rnaegele
 */
public class ClassNameUtils {
	public static String computeFullyQualifiedMethodName(final String className, final String methodName, final Type[] argumentTypes) {
		StrBuilder sb = new StrBuilder(50);
		sb.append(abbreviatePackageName(className));
		sb.append('.');
		sb.append(methodName);
		sb.append('(');
		for (int i = 0; i < argumentTypes.length; ++i) {
			sb.appendSeparator(", ", i);
			sb.append(abbreviatePackageName(argumentTypes[i].getClassName()));
		}
		sb.append(')');
		return sb.toString();
	}

	public static String abbreviatePackageName(String className) {
		if (className.contains(".")) {
			String packageName = substringBeforeLast(className, ".");
			String simpleClassName = substringAfterLast(className, ".");
			List<String> list = from(Splitter.on('.').splitToList(packageName)).transform(new Function<String, String>() {
				@Override
				public String apply(String input) {
					return input.substring(0, 1);
				}
			}).toList();
			return Joiner.on('.').join(list) + '.' + simpleClassName;
		} else {
			return className;
		}
	}
}

@@ -1,12 +1,633 @@
+/*%0A * Copyright (c) 2013-2014 mgm technology partners GmbH%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package com.

Add missing license header