1 22 package org.jboss.reflect.plugins.javassist; 23 24 import org.jboss.reflect.spi.TypeInfo; 25 import org.jboss.util.JBossStringBuilder; 26 27 28 34 class SignatureKey 35 { 36 37 String name; 38 39 40 String [] params; 41 42 43 private transient int cachedHashCode = Integer.MIN_VALUE; 44 45 51 public SignatureKey(String name, TypeInfo[] typeInfos) 52 { 53 this.name = name; 54 if (typeInfos != null && typeInfos.length > 0) 55 { 56 params = new String [typeInfos.length]; 57 for (int i = 0; i < typeInfos.length; ++i) 58 params[i] = typeInfos[i].getName(); 59 } 60 } 61 62 68 public SignatureKey(String name, String [] params) 69 { 70 this.name = name; 71 this.params = params; 72 } 73 74 public boolean equals(Object obj) 75 { 76 if (obj == this) 77 return true; 78 if (obj == null || obj instanceof SignatureKey == false) 79 return false; 80 81 SignatureKey other = (SignatureKey) obj; 82 83 if (name == null && other.name != null) 84 return false; 85 if (name != null && other.name == null) 86 return false; 87 if (name != null && name.equals(other.name) == false) 88 return false; 89 90 if (params == null && other.params == null) 91 return true; 92 if (params == null && other.params != null) 93 return false; 94 if (params != null && other.params == null) 95 return false; 96 97 if (params.length != other.params.length) 98 return false; 99 100 for (int i = 0; i < params.length; ++i) 101 { 102 if (params[i].equals(other.params[i]) == false) 103 return false; 104 } 105 return true; 106 } 107 108 public int hashCode() 109 { 110 if (cachedHashCode == Integer.MIN_VALUE) 111 { 112 JBossStringBuilder builder = new JBossStringBuilder(); 113 if (name != null) 114 builder.append(name); 115 if (params != null) 116 { 117 for (int i = 0; i < params.length; ++i) 118 builder.append(params[i]); 119 } 120 cachedHashCode = builder.toString().hashCode(); 121 } 122 return cachedHashCode; 123 } 124 } 125 | Popular Tags |