1 package com.fasterxml.jackson.databind.introspect; 2 3 import java.lang.reflect.Constructor; 4 import java.lang.reflect.Method; 5 6 /** 7 * Helper class needed to be able to efficiently access class 8 * member functions ({@link Method}s and {@link Constructor}s) 9 * in {@link java.util.Map}s. 10 */ 11 public final class MemberKey 12 { 13 final static Class<?>[] NO_CLASSES = new Class<?>[0]; 14 15 final String _name; 16 final Class<?>[] _argTypes; 17 MemberKey(Method m)18 public MemberKey(Method m) 19 { 20 this(m.getName(), m.getParameterTypes()); 21 } 22 MemberKey(Constructor<?> ctor)23 public MemberKey(Constructor<?> ctor) 24 { 25 this("", ctor.getParameterTypes()); 26 } 27 MemberKey(String name, Class<?>[] argTypes)28 public MemberKey(String name, Class<?>[] argTypes) 29 { 30 _name = name; 31 _argTypes = (argTypes == null) ? NO_CLASSES : argTypes; 32 } 33 getName()34 public String getName() { 35 return _name; 36 } 37 argCount()38 public int argCount() { 39 return _argTypes.length; 40 } 41 42 @Override toString()43 public String toString() { 44 return _name + "(" + _argTypes.length+"-args)"; 45 } 46 47 @Override hashCode()48 public int hashCode() { 49 return _name.hashCode() + _argTypes.length; 50 } 51 52 @Override equals(Object o)53 public boolean equals(Object o) 54 { 55 if (o == this) return true; 56 if (o == null) return false; 57 if (o.getClass() != getClass()) { 58 return false; 59 } 60 MemberKey other = (MemberKey) o; 61 if (!_name.equals(other._name)) { 62 return false; 63 } 64 Class<?>[] otherArgs = other._argTypes; 65 int len = _argTypes.length; 66 if (otherArgs.length != len) { 67 return false; 68 } 69 for (int i = 0; i < len; ++i) { 70 Class<?> type1 = otherArgs[i]; 71 Class<?> type2 = _argTypes[i]; 72 if (type1 == type2) { 73 continue; 74 } 75 /* 23-Feb-2009, tatu: Are there any cases where we would have to 76 * consider some narrowing conversions or such? For now let's 77 * assume exact type match is enough 78 */ 79 /* 07-Apr-2009, tatu: Indeed there are (see [JACKSON-97]). 80 * This happens with generics when a bound is specified. 81 * I hope this works; check here must be transitive 82 */ 83 /* 14-Oct-2014, tatu: No, doing that is wrong. Conflicts may (and will) be 84 * handled at a later point; trying to change definition of equality 85 * will just cause problems like [jackson-core#158] 86 */ 87 /* 88 if (type1.isAssignableFrom(type2) || type2.isAssignableFrom(type1)) { 89 continue; 90 } 91 */ 92 return false; 93 } 94 return true; 95 } 96 } 97