Package com.globalmentor.model
Class DefaultTypeConverter
- java.lang.Object
-
- com.globalmentor.model.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
-
-
Field Summary
Fields Modifier and Type Field Description static DefaultTypeConverter
INSTANCE
The default, shared instance of the converter.
-
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.
-
-
-
Field Detail
-
INSTANCE
public static final DefaultTypeConverter INSTANCE
The default, shared instance of the converter.
-
-
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 interfaceTypeConverter
- 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.
-
-