Class BasicTypeConverter

  • All Implemented Interfaces:
    TypeConverter
    Direct Known Subclasses:
    JXPath11CompatibleTypeConverter

    public class BasicTypeConverter
    extends java.lang.Object
    implements TypeConverter
    The default implementation of TypeConverter.
    Version:
    $Revision: 670727 $ $Date: 2008-06-23 15:10:38 -0500 (Mon, 23 Jun 2008) $
    Author:
    Dmitri Plotnikov
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Collection allocateCollection​(java.lang.Class type)
      Create a collection of a given type.
      protected java.lang.Number allocateNumber​(java.lang.Class type, double value)
      Allocate a number of a given type and value.
      boolean canConvert​(java.lang.Object object, java.lang.Class toType)
      Returns true if it can convert the supplied object to the specified class.
      protected boolean canCreateCollection​(java.lang.Class type)
      Learn whether this BasicTypeConverter can create a collection of the specified type.
      java.lang.Object convert​(java.lang.Object object, java.lang.Class toType)
      Converts the supplied object to the specified type.
      protected java.lang.Object convertNullToPrimitive​(java.lang.Class toType)
      Convert null to a primitive type.
      protected java.lang.Object convertStringToPrimitive​(java.lang.Object object, java.lang.Class toType)
      Convert a string to a primitive type.
      protected java.util.Collection unmodifiableCollection​(java.util.Collection collection)
      Get an unmodifiable version of a collection.
      • Methods inherited from class java.lang.Object

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

      • BasicTypeConverter

        public BasicTypeConverter()
    • Method Detail

      • canConvert

        public boolean canConvert​(java.lang.Object object,
                                  java.lang.Class toType)
        Returns true if it can convert the supplied object to the specified class.
        Specified by:
        canConvert in interface TypeConverter
        Parameters:
        object - to check
        toType - prospective destination class
        Returns:
        boolean
      • convert

        public java.lang.Object convert​(java.lang.Object object,
                                        java.lang.Class toType)
        Converts the supplied object to the specified type. Throws a runtime exception if the conversion is not possible.
        Specified by:
        convert in interface TypeConverter
        Parameters:
        object - to convert
        toType - destination class
        Returns:
        converted object
      • convertNullToPrimitive

        protected java.lang.Object convertNullToPrimitive​(java.lang.Class toType)
        Convert null to a primitive type.
        Parameters:
        toType - destination class
        Returns:
        a wrapper
      • convertStringToPrimitive

        protected java.lang.Object convertStringToPrimitive​(java.lang.Object object,
                                                            java.lang.Class toType)
        Convert a string to a primitive type.
        Parameters:
        object - String
        toType - destination class
        Returns:
        wrapper
      • allocateNumber

        protected java.lang.Number allocateNumber​(java.lang.Class type,
                                                  double value)
        Allocate a number of a given type and value.
        Parameters:
        type - destination class
        value - double
        Returns:
        Number
      • canCreateCollection

        protected boolean canCreateCollection​(java.lang.Class type)
        Learn whether this BasicTypeConverter can create a collection of the specified type.
        Parameters:
        type - prospective destination class
        Returns:
        boolean
      • allocateCollection

        protected java.util.Collection allocateCollection​(java.lang.Class type)
        Create a collection of a given type.
        Parameters:
        type - destination class
        Returns:
        Collection
      • unmodifiableCollection

        protected java.util.Collection unmodifiableCollection​(java.util.Collection collection)
        Get an unmodifiable version of a collection.
        Parameters:
        collection - to wrap
        Returns:
        Collection