001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2005, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs;
021:
022: import java.util.Collections;
023: import java.util.List;
024: import java.util.Set;
025:
026: import org.w3c.dom.Node;
027: import org.w3c.dom.NodeList;
028:
029: /**
030: * This class provides substitutes for 1.5 methods that we don't want to depend upon in
031: * FindBugs.
032: *
033: */
034: public class TigerSubstitutes {
035:
036: @SuppressWarnings("unchecked")
037: public static final <T> List<T> emptyList() {
038: return (List<T>) Collections.EMPTY_LIST;
039: }
040:
041: @SuppressWarnings("unchecked")
042: public static final <T> Set<T> emptySet() {
043: return (Set<T>) Collections.EMPTY_SET;
044: }
045:
046: public static boolean parseBoolean(String s) {
047: // return Boolean.parseBoolean(s);
048: return Boolean.valueOf(s).booleanValue();
049: }
050:
051: public static Long valueOf(long value) {
052: // return Long.valueOf(value);
053: return (Long) value;
054: }
055:
056: /**
057: * Copied from java.util.Arrays;
058: *
059: */
060: public static int hashCode(Object a[]) {
061: if (a == null)
062: return 0;
063:
064: int result = 1;
065:
066: for (Object element : a)
067: result = 31 * result
068: + (element == null ? 0 : element.hashCode());
069:
070: return result;
071: }
072:
073: public static <U> Class<? extends U> asSubclass(Class<?> base,
074: Class<U> clazz) {
075: if (clazz.isAssignableFrom(base))
076: return (Class<? extends U>) base;
077: else
078: throw new ClassCastException(base.toString());
079: }
080:
081: public static String getSimpleName(Class<?> c) {
082: if (c.isArray())
083: return getSimpleName(c.getComponentType()) + "[]";
084: String name = c.getName();
085: name = name.substring(name.lastIndexOf(".") + 1);
086: int index = name.lastIndexOf("$");
087: if (index == -1)
088: return name;
089: if (index + 1 == name.length())
090: throw new InternalError("Malformed class name");
091: if (isAsciiDigit(name.charAt(index + 1)))
092: return "";
093: return name.substring(index + 1);
094: }
095:
096: private static boolean isAsciiDigit(char c) {
097: return '0' <= c && c <= '9';
098: }
099:
100: public static String getTextContent(Node n) {
101: NodeList nodeList = n.getChildNodes();
102: StringBuffer buf = new StringBuffer();
103: for (int j = 0; j < nodeList.getLength(); j++) {
104: Node k = nodeList.item(j);
105: buf.append(k.getNodeValue());
106: }
107: return buf.toString();
108: }
109:
110: }
|