package com.ryantenney.metrics.spring;

import java.lang.reflect.Method;
import java.util.Arrays;

class MethodKey {

	private final String name;
	private final Class<?> returnType;
	private final Class<?>[] parameterTypes;
	private final int hashCode;

	public static MethodKey forMethod(Method method) {
		return new MethodKey(method);
	}

	private MethodKey(Method method) {
		this.name = method.getName();
		this.returnType = method.getReturnType();
		this.parameterTypes = method.getParameterTypes();
		this.hashCode = computeHashCode();
	}

	@Override
	public int hashCode() {
		return hashCode;
	}

	private int computeHashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (name == null ? 0 : name.hashCode());
		result = prime * result + Arrays.hashCode(parameterTypes);
		result = prime * result + (returnType == null ? 0 : returnType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		MethodKey other = (MethodKey) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		}
		else if (!name.equals(other.name)) {
			return false;
		}
		if (!Arrays.equals(parameterTypes, other.parameterTypes)) {
			return false;
		}
		if (returnType == null) {
			if (other.returnType != null) {
				return false;
			}
		}
		else if (!returnType.equals(other.returnType)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder(64);
		sb.append(returnType.getSimpleName());
		sb.append(' ');
		sb.append(name);
		sb.append('(');
		boolean firstParam = true;
		for (Class<?> parameterType : parameterTypes) {
			if (firstParam) {
				firstParam = false;
			} else {
				sb.append(", ");
			}
			sb.append(parameterType.getSimpleName());
		}
		sb.append(')');
		return sb.toString();
	}

}

@@ -705,28 +705,8 @@
 lt +
- (name == null ? 0 :
  nam
@@ -713,25 +713,24 @@
 e.hashCode()
-)
 ;%0A%09%09result =
@@ -811,34 +811,8 @@
 lt +
- (returnType == null ? 0 :
  ret
@@ -829,17 +829,16 @@
 shCode()
-)
 ;%0A%09%09retu
@@ -1085,402 +1085,138 @@
 ;%0A%09%09
-if (name == null) %7B%0A%09%09%09if (other.name != null) %7B
+return name.equals(other.name)
 %0A%09%09%09
-%09
+&& 
 return
- false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09else if (!name.equals(other.name)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09if (!Arrays.equals(parameterTypes, other.parameterTypes)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09if (returnType == null) %7B%0A%09%09%09if (other.returnType != null) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09else if (!returnType.equals(other.returnType)) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09return true
+Type.equals(other.returnType)%0A%09%09%09&& Arrays.equals(parameterTypes, other.parameterTypes)
 ;%0A%09%7D

Save some code by correctly assuming that all fields in MethodKey are non-nullable.