1 7 8 package java.lang; 9 10 22 public final class StackTraceElement implements java.io.Serializable { 23 private String declaringClass; 25 private String methodName; 26 private String fileName; 27 private int lineNumber; 28 29 49 public StackTraceElement(String declaringClass, String methodName, 50 String fileName, int lineNumber) { 51 if (declaringClass == null) 52 throw new NullPointerException ("Declaring class is null"); 53 if (methodName == null) 54 throw new NullPointerException ("Method name is null"); 55 56 this.declaringClass = declaringClass; 57 this.methodName = methodName; 58 this.fileName = fileName; 59 this.lineNumber = lineNumber; 60 } 61 62 74 public String getFileName() { 75 return fileName; 76 } 77 78 89 public int getLineNumber() { 90 return lineNumber; 91 } 92 93 100 public String getClassName() { 101 return declaringClass; 102 } 103 104 115 public String getMethodName() { 116 return methodName; 117 } 118 119 126 public boolean isNativeMethod() { 127 return lineNumber == -2; 128 } 129 130 156 public String toString() { 157 return getClassName() + "." + methodName + 158 (isNativeMethod() ? "(Native Method)" : 159 (fileName != null && lineNumber >= 0 ? 160 "(" + fileName + ":" + lineNumber + ")" : 161 (fileName != null ? "("+fileName+")" : "(Unknown Source)"))); 162 } 163 164 187 public boolean equals(Object obj) { 188 if (obj==this) 189 return true; 190 if (!(obj instanceof StackTraceElement )) 191 return false; 192 StackTraceElement e = (StackTraceElement )obj; 193 return e.declaringClass.equals(declaringClass) && e.lineNumber == lineNumber 194 && eq(methodName, e.methodName) && eq(fileName, e.fileName); 195 } 196 197 private static boolean eq(Object a, Object b) { 198 return a==b || (a != null && a.equals(b)); 199 } 200 201 204 public int hashCode() { 205 int result = 31*declaringClass.hashCode() + methodName.hashCode(); 206 result = 31*result + (fileName == null ? 0 : fileName.hashCode()); 207 result = 31*result + lineNumber; 208 return result; 209 } 210 211 private static final long serialVersionUID = 6992337162326171013L; 212 } 213 | Popular Tags |