Class DefaultTypeConverter

  • All Implemented Interfaces:
    TypeConverter

    public class DefaultTypeConverter
    extends java.lang.Object
    implements TypeConverter
    A default implementation of a type converter.

    The following types can be converted to the listed types:

    Boolean
    boolean
    Character
    char
    Number
    Long, long, Integer, int, Double, double, Float, float
    String
    char[], Enum, Pattern, URIPath
    Author:
    Garret Wilson
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DefaultTypeConverter()
      Default constructor; used only for the singleton instance and for extension.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T convert​(java.lang.Object object, java.lang.Class<T> requiredType)
      Converts an object from one type to another.
      • Methods inherited from class java.lang.Object

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

      • INSTANCE

        public static final DefaultTypeConverter INSTANCE
        The default, shared instance of the converter.
    • Constructor Detail

      • DefaultTypeConverter

        protected DefaultTypeConverter()
        Default constructor; used only for the singleton instance and for extension.
    • Method Detail

      • convert

        public <T> T convert​(java.lang.Object object,
                             java.lang.Class<T> requiredType)
                      throws java.lang.IllegalArgumentException
        Description copied from interface: TypeConverter
        Converts an object from one type to another. If the object is already of the correct type, no action occurs.
        Specified by:
        convert in interface TypeConverter
        Type Parameters:
        T - The type of object required.
        Parameters:
        object - The object to convert.
        requiredType - The class representing required type of the object.
        Returns:
        The object as the required type, or null if the object cannot be converted to the required type.
        Throws:
        java.lang.IllegalArgumentException - if the given object should be able to be converted to the required type but something about its state, format, or contents prevented the conversion.