Class TypeUtils


  • public class TypeUtils
    extends java.lang.Object
    Global type conversion utilities.
    Version:
    $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $
    Author:
    Dmitri Plotnikov
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canConvert​(java.lang.Object object, java.lang.Class toType)
      Returns true if the global converter can convert the supplied object to the specified type.
      static java.lang.Object convert​(java.lang.Object object, java.lang.Class toType)
      Converts the supplied object to the specified type.
      static TypeConverter getTypeConverter()
      Returns the current type converter.
      static void setTypeConverter​(TypeConverter converter)
      Install an alternative type converter.
      static java.lang.Class wrapPrimitive​(java.lang.Class p)
      Return the appropriate wrapper type for the specified class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PRIMITIVE_TYPE_MAP

        private static final java.util.HashMap PRIMITIVE_TYPE_MAP
    • Constructor Detail

      • TypeUtils

        public TypeUtils()
    • Method Detail

      • setTypeConverter

        public static void setTypeConverter​(TypeConverter converter)
        Install an alternative type converter.
        Parameters:
        converter - new TypeConverter
      • getTypeConverter

        public static TypeConverter getTypeConverter()
        Returns the current type converter.
        Returns:
        TypeConverter
      • canConvert

        public static boolean canConvert​(java.lang.Object object,
                                         java.lang.Class toType)
        Returns true if the global converter can convert the supplied object to the specified type.
        Parameters:
        object - object to test
        toType - target class
        Returns:
        boolean
      • convert

        public static java.lang.Object convert​(java.lang.Object object,
                                               java.lang.Class toType)
        Converts the supplied object to the specified type. May throw a RuntimeException.
        Parameters:
        object - object to convert
        toType - target class
        Returns:
        resulting Object
      • wrapPrimitive

        public static java.lang.Class wrapPrimitive​(java.lang.Class p)
        Return the appropriate wrapper type for the specified class.
        Parameters:
        p - Class for which to retrieve a wrapper class.
        Returns:
        the wrapper if p is primitive, else p.
        Since:
        JXPath 1.3