1 19 20 package edu.umd.cs.findbugs; 21 22 23 28 public class TigerSubstitutes { 29 public static boolean parseBoolean(String s) { 30 return Boolean.valueOf(s).booleanValue(); 32 } 33 public static Long valueOf(long value) { 34 return (Long ) value; 36 } 37 38 42 public static int hashCode(Object a[]) { 43 if (a == null) 44 return 0; 45 46 int result = 1; 47 48 for (Object element : a) 49 result = 31 * result + (element == null ? 0 : element.hashCode()); 50 51 return result; 52 } 53 54 public static <U> Class <? extends U> asSubclass(Class base, Class <U> clazz) { 55 if (clazz.isAssignableFrom(base)) 56 return (Class <? extends U>) base; 57 else 58 throw new ClassCastException (base.toString()); 59 } 60 61 public static String getSimpleName(Class c) { 62 if (c.isArray()) 63 return getSimpleName(c.getComponentType())+"[]"; 64 String name = c.getName(); 65 name = name.substring(name.lastIndexOf(".")+1); 66 int index = name.lastIndexOf("$"); 67 if (index == -1) return name; 68 if (index +1 ==name.length() ) 69 throw new InternalError ("Malformed class name"); 70 if (isAsciiDigit(name.charAt(index+1))) return ""; 71 return name.substring(index+1); 72 } 73 private static boolean isAsciiDigit(char c) { 74 return '0' <= c && c <= '9'; 75 } 76 } 77 | Popular Tags |