KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > TigerSubstitutes


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2005, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs;
21
22
23 /**
24  * This class provides substitutes for 1.5 methods that we don't want to depend upon in
25  * FindBugs.
26  *
27  */

28 public class TigerSubstitutes {
29     public static boolean parseBoolean(String JavaDoc s) {
30         // return Boolean.parseBoolean(s);
31
return Boolean.valueOf(s).booleanValue();
32     }
33     public static Long JavaDoc valueOf(long value) {
34         // return Long.valueOf(value);
35
return (Long JavaDoc) value;
36     }
37     
38     /**
39      * Copied from java.util.Arrays;
40      *
41      */

42       public static int hashCode(Object JavaDoc a[]) {
43             if (a == null)
44                 return 0;
45
46             int result = 1;
47
48             for (Object JavaDoc element : a)
49                 result = 31 * result + (element == null ? 0 : element.hashCode());
50
51             return result;
52         }
53
54       public static <U> Class JavaDoc<? extends U> asSubclass(Class JavaDoc base, Class JavaDoc<U> clazz) {
55           if (clazz.isAssignableFrom(base))
56               return (Class JavaDoc<? extends U>) base;
57           else
58               throw new ClassCastException JavaDoc(base.toString());
59       }
60       
61       public static String JavaDoc getSimpleName(Class JavaDoc c) {
62               if (c.isArray())
63                   return getSimpleName(c.getComponentType())+"[]";
64               String JavaDoc 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 JavaDoc("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