1 package csdl.jblanket.methodset; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 14 public class MethodInfo { 15 16 17 private String className; 18 19 private String methodName; 20 21 private List parameterTypeList; 22 23 private String methodString; 24 25 private int hashCode; 26 27 35 public MethodInfo(String className, String methodName, List parameterTypeList) { 36 if ((className == null) || (methodName == null) || (parameterTypeList == null)) { 38 throw new RuntimeException ("Args to MethodInfo constructor cannot be null!"); 39 } 40 this.className = className; 41 this.methodName = methodName; 42 this.parameterTypeList = parameterTypeList; 45 this.methodString = this.className + "." + this.methodName + " " + this.parameterTypeList; 46 this.hashCode = this.methodString.hashCode(); 47 } 48 49 50 55 public String getClassName() { 56 return this.className; 57 } 58 59 65 String getMethodString() { 66 return this.methodString; 67 } 68 69 70 75 public String getMethodName() { 76 return this.methodName; 77 } 78 79 80 87 public List getParameterTypeList() { 88 return this.parameterTypeList; 89 } 90 91 92 99 public String getPackageName() { 100 int endPackageIndex = this.className.lastIndexOf('.'); 101 return (endPackageIndex >= 0) ? this.className.substring((endPackageIndex + 1)) : ""; 102 } 103 104 105 110 public String toString() { 111 return "[Method " + methodString + "]"; 112 } 113 114 121 public int compareTo(Object obj) { 122 return this.methodString.compareTo(((MethodInfo) obj).methodString); 123 } 124 125 131 public boolean equals(Object obj) { 132 return ((obj instanceof MethodInfo) && 133 (this.methodString.equals(((MethodInfo) obj).methodString))); 134 } 135 136 137 142 public int hashCode() { 143 return this.hashCode; 144 } 145 146 147 152 public static void main(String args[]) { 153 ArrayList params = new ArrayList (); 154 params.add("java.lang.String"); 155 params.add("java.lang.Boolean"); 156 MethodInfo method1 = new MethodInfo("foo.bar.Baz", "qux", params); 157 System.out.println(method1); 158 System.out.println("Package: " + method1.getPackageName()); 159 MethodInfo method2 = new MethodInfo("Baz", "qux", null); 160 System.out.println("Package: " + method2.getPackageName()); 161 System.out.println("Test equal methods: " + method1.equals(method1)); 162 System.out.println("Test non-equal methods: " + method1.equals(method2)); 163 } 164 } 165 | Popular Tags |