Class TypeUtil


  • public class TypeUtil
    extends Object
    Datatype management utility methods
    • Constructor Detail

      • TypeUtil

        public TypeUtil()
    • 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 in
        offset - - 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 in
        offset - - 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's join.
        Parameters:
        from - the array of strings to convert
        separator - 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's split.
        Parameters:
        from - the string to convert
        separator - 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.
      • 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