Class TypeUtil
- java.lang.Object
-
- com.sun.enterprise.deployment.util.TypeUtil
-
public class TypeUtil extends Object
Datatype management utility methods
-
-
Constructor Summary
Constructors Constructor Description TypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
addCommas(float f)
Deprecated.Use standard java.* APIs which create the correct localized number format.static String
addCommas(String numStr)
Deprecated.Use standard java.* APIs which create the correct localized number format.static String
arrayToString(String[] from, String separator)
Convert an array of strings to a single line with elements separated by the given separator.static Method
getDeclaredMethod(Class declaringClass, ClassLoader loader, String name, String[] paramClassNames)
static Method
getMethod(Class declaringClass, ClassLoader loader, String name, String[] paramClassNames)
static Set
getSuperInterfaces(ClassLoader cl, String className, String baseClassName)
Get all super-interfaces of a class, excluding the given base interface.static int
hashCode(String s)
Work around a performance bug in String.hashCode() for strings longer than sixteen characters, by calculating a (slower) hash on all the characters in the string.static int
intGetBytes(int src, byte[] buf, int offset)
Place a byte representation of src into the byte array buf.static int
intGetChars(int src, char[] buf, int offset)
Place a character representation of src into the buffer.static boolean
isSubclassOf(Class sub, Class sup)
Deprecated.Use sup.isAssignableFrom(sub)static Class[]
paramClassNamesToTypes(String[] paramClassNames, ClassLoader loader)
Convert String array of class names into array of Classes.static String
propertyNameToSetterMethod(String propertyName)
Convert a java beans property name to a setter method namestatic boolean
sameMethodSignature(Method m1, Method m2)
Compares the signatures of two methods to see if they have the same method name, parameters, and return type.static boolean
sameParamTypes(Method m1, Method m2)
Compares the signatures of two methods to see if they have the same numer of parameters and same parameter types.static String
setterMethodToPropertyName(String setterMethodName)
Convert a java beans setter method to its property name.static String[]
stringToArray(String from, String separator)
Convert a string of delimited strings to an array of strings.static String
truncateFloat(float f, int digits)
Truncate a float to the required number of significant digits.static String[]
wordWrap(String msg, int widthInChars)
Word-wrap a string into an array of strings.
-
-
-
Method Detail
-
intGetChars
public static int intGetChars(int src, char[] buf, int offset)
Place a character representation of src into the buffer. No formatting (e.g. localization) is done.- Parameters:
src
- - the integer to convert. Must not be Integer.MIN_VALUE.buf
- - the buf to put the result inoffset
- - the offset in buf to place the first digit- Returns:
- the number of bytes added to buf
- Throws:
IllegalArgumentException
- if src is Integer.MIN_VALUE.
-
intGetBytes
public static int intGetBytes(int src, byte[] buf, int offset)
Place a byte representation of src into the byte array buf. No commas or any other formatting is done to the integer.- Parameters:
src
- - the integer to convert. Must not be Integer.MIN_VALUE.buf
- - the buf to put the result inoffset
- - the offset in buf to place the first digit- Returns:
- the number of bytes added to buf
- Throws:
IllegalArgumentException
- if src is Integer.MIN_VALUE.
-
hashCode
public static int hashCode(String s)
Work around a performance bug in String.hashCode() for strings longer than sixteen characters, by calculating a (slower) hash on all the characters in the string. Not needed starting in the JDK 1.2 release.
-
wordWrap
public static String[] wordWrap(String msg, int widthInChars)
Word-wrap a string into an array of strings. Space is the only separator character recognized.
-
arrayToString
public static String arrayToString(String[] from, String separator)
Convert an array of strings to a single line with elements separated by the given separator. Similar to Tcl'sjoin
.- Parameters:
from
- the array of strings to convertseparator
- the string to insert between each element
-
stringToArray
public static String[] stringToArray(String from, String separator)
Convert a string of delimited strings to an array of strings. Similar to AWK's and Tcl'ssplit
.- Parameters:
from
- the string to convertseparator
- the delimiter
-
truncateFloat
public static String truncateFloat(float f, int digits)
Truncate a float to the required number of significant digits.
-
addCommas
public static String addCommas(float f)
Deprecated.Use standard java.* APIs which create the correct localized number format.Add commas to a number for "123,456.7" style formatting.
-
addCommas
public static String addCommas(String numStr)
Deprecated.Use standard java.* APIs which create the correct localized number format.Add commas to a number for "123,456.7" style formatting.
-
isSubclassOf
public static boolean isSubclassOf(Class sub, Class sup)
Deprecated.Use sup.isAssignableFrom(sub)Test if a class is a subclass of another.
-
getSuperInterfaces
public static Set getSuperInterfaces(ClassLoader cl, String className, String baseClassName) throws ClassNotFoundException
Get all super-interfaces of a class, excluding the given base interface. Returns a set of strings containing class names.- Throws:
ClassNotFoundException
-
getMethod
public static Method getMethod(Class declaringClass, ClassLoader loader, String name, String[] paramClassNames) throws Exception
- Throws:
Exception
-
getDeclaredMethod
public static Method getDeclaredMethod(Class declaringClass, ClassLoader loader, String name, String[] paramClassNames) throws Exception
- Throws:
Exception
-
sameParamTypes
public static boolean sameParamTypes(Method m1, Method m2)
Compares the signatures of two methods to see if they have the same numer of parameters and same parameter types. Note that this equality check does NOT cover : 1) declaring class 2) exceptions 3) method name 4) return type
-
sameMethodSignature
public static boolean sameMethodSignature(Method m1, Method m2)
Compares the signatures of two methods to see if they have the same method name, parameters, and return type. Note that this equality check does NOT cover : 1) declaring class 2) exceptions
-
setterMethodToPropertyName
public static String setterMethodToPropertyName(String setterMethodName)
Convert a java beans setter method to its property name.
-
propertyNameToSetterMethod
public static String propertyNameToSetterMethod(String propertyName)
Convert a java beans property name to a setter method name
-
paramClassNamesToTypes
public static Class[] paramClassNamesToTypes(String[] paramClassNames, ClassLoader loader) throws Exception
Convert String array of class names into array of Classes.- Throws:
Exception
-
-