Class TypeConverter
java.lang.Object
com.blackrook.redis.struct.TypeConverter
Type converter class for converting types to others.
- Author:
- Matthew Tropiano
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> voidapplyMemberToObject(String name, Object value, T targetObject) Applies an object value to a target object via a "field" name (setter/field).protected final <T> TconvertArray(String memberName, Object array, Class<T> targetType) Converts an array value to a target type.protected final <T> TconvertBoolean(String memberName, Boolean b, Class<T> targetType) Converts a boolean to another type.protected final <T> TconvertByteArray(String memberName, byte[] byteArray, Class<T> targetType) Converts a byte array value to a target type.protected final <T> TconvertCharacter(String memberName, Character c, Class<T> targetType) Converts a character value to a target type.protected final <T> TconvertCharArray(String memberName, char[] charArray, Class<T> targetType) Converts a char array value to a target type.protected final <T> TconvertDate(String memberName, Date d, Class<T> targetType) Converts a date value to a target type.protected final <T> TconvertEnum(String memberName, Enum<?> e, Class<T> targetType) Converts an enum value to a target type.protected final <T> TconvertIterable(String memberName, Iterable<?> iter, Class<T> targetType) Converts an iterable to another type (like an array).protected final <T> TconvertNumber(String memberName, Number n, Class<T> targetType) Converts a numeric value to a target type.protected final <T> TconvertOtherArray(String memberName, Object array, Class<T> targetType) Converts a totally different array type.protected final <T> TconvertString(String memberName, String s, Class<T> targetType) Converts a string value to a target type.<T> TcreateForType(Object object, Class<T> targetType) Reflect.creates a new instance of an object for placement in a POJO or elsewhere.<T> TcreateForType(String memberName, Object object, Class<T> targetType) Reflect.creates a new instance of an object for placement in a POJO or elsewhere.
-
Constructor Details
-
TypeConverter
Creates a type profiler.- Parameters:
profileFactory- the profile factory to use for caching reflection info.
-
-
Method Details
-
createForType
Reflect.creates a new instance of an object for placement in a POJO or elsewhere.- Type Parameters:
T- the return object type.- Parameters:
object- the object to convert to another objecttargetType- the target class type to convert to, if the types differ.- Returns:
- a suitable object of type
targetType. - Throws:
ClassCastException- if the incoming type cannot be converted.
-
createForType
Reflect.creates a new instance of an object for placement in a POJO or elsewhere.- Type Parameters:
T- the return object type.- Parameters:
memberName- the name of the member that is being converted (for reporting).object- the object to convert to another objecttargetType- the target class type to convert to, if the types differ.- Returns:
- a suitable object of type
targetType. - Throws:
ClassCastException- if the incoming type cannot be converted.
-
applyMemberToObject
Applies an object value to a target object via a "field" name (setter/field).- Type Parameters:
T- the target object type.- Parameters:
name- the field/setter name - this can be a member name or an alias.value- the value to apply/convert.targetObject- the target object to set stuff on.
-
convertBoolean
Converts a boolean to another type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).b- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertNumber
Converts a numeric value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).n- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertCharacter
Converts a character value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).c- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertDate
Converts a date value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).d- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertEnum
Converts an enum value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).e- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertString
Converts a string value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).s- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertArray
Converts an array value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).array- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertCharArray
Converts a char array value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).charArray- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertByteArray
Converts a byte array value to a target type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).byteArray- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertOtherArray
Converts a totally different array type.- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).array- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-
convertIterable
Converts an iterable to another type (like an array).- Type Parameters:
T- the target value type.- Parameters:
memberName- the name of the member being converted (for logging).iter- the value to convert.targetType- the target type.- Returns:
- the resultant type.
-