public interface Object_To_Target<T> extends IsTransformer<Object,T>
Converts an Object to a target type with several settings, for instance for null value and false value.
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
convert(Object value,
Class<T> clazz)
Type safe casting or conversion from Object to target class, special processing for Object[] and Collections.
|
static <T> T |
convert(Object value,
Class<T> clazz,
T nullValue,
T falseValue)
Type safe casting or conversion from Object to target class, special processing for Object[] and Collections.
|
static <T> T |
convert(Object value,
Class<T> clazz,
T nullValue,
T falseValue,
boolean collFirst)
Type safe casting or conversion from Object to target class, with optional special processing for Object[] and Collections.
|
static <T> Object_To_Target<T> |
create(Class<T> clazz,
T nullValue,
T falseValue,
boolean collFirst)
Creates a transformer that takes an Object and returns a target type.
|
Class<T> |
getClazzT()
Returns the class for of the target type.
|
boolean |
getCollFirstFlag()
Returns a flag that say if, when the transform object is a collection, only the first non-null element should be used as return value.
|
T |
getFalseValue()
Returns the false value for the transformation, used in case no test succeeds.
|
T |
getNullValue()
Returns the null value for the transformation, used if a null test succeeds
|
default T |
transform(Object obj)
Type safe transformation from Object to target class, with optional special processing for
Object[] and Collection. |
apply, transformClass<T> getClazzT()
Returns the class for of the target type.
nullT getNullValue()
Returns the null value for the transformation, used if a null test succeeds
null (then null is the null value)T getFalseValue()
Returns the false value for the transformation, used in case no test succeeds.
null (then null is the false value)boolean getCollFirstFlag()
Returns a flag that say if, when the transform object is a collection, only the first non-null element should be used as return value.
falsedefault T transform(Object obj)
Type safe transformation from Object to target class, with optional special processing for Object[] and Collection.
The conversion is done in the following sequence:
If value is null, the nullValue will be returned.
If the requested class is an object array (getClazzT()==Object[]),
then the return is value (if value is an Object[])
or Collection.toArray() (if value is a Collection).
In all other cases the process proceeds
If collFist is set to true and value is a Collection, the first value of this collection will be used for the further process
Now another null test returning nullValue if value is null
Next test if the getClazzT() is an instance of value.class. If true, value will be returned
Next try for some standard type conversions for value, namely
If getClazzT() is an instance of Boolean and value is true or on (case insensitive), then return Boolean(true)
If getClazzT() is an instance of Boolean and value is false or off (case insensitive), then return Boolean(false)
If getClazzT() is an instance of Integer then try to return Integer.valueOf(value.toString)
If getClazzT() is an instance of Double then try to return Double.valueOf(value.toString)
If getClazzT() is an instance of Long then try to return Long.valueOf(value.toString)
The last option is to return valueFalse to indicate that no test was successful
This method does suppress warnings for “unchecked” castings, because a casting from any concrete return type to T is unsafe.
Because all actual castings follow an explicit type check, this suppression should have not negative impact (i.e. there are no ClassCastException).
transform in interface Transformer<Object,T>obj - input object for conversionT if a conversion was successful, nullValue if null was tested successfully, falseValue in all other casesstatic <T> Object_To_Target<T> create(Class<T> clazz, T nullValue, T falseValue, boolean collFirst)
Creates a transformer that takes an Object and returns a target type.
T - target type for the transformationclazz - the requested type of the return value, required for initializationnullValue - the value to be used if a null test succeedsfalseValue - the value to be used in case no test succeedscollFirst - if set true, collections will be processed and the first element returned, no special collection processing otherwiseT if a conversion was successful, nullValue if null was tested successfully, falseValue in all other casesstatic <T> T convert(Object value, Class<T> clazz)
Type safe casting or conversion from Object to target class, special processing for Object[] and Collections.
This is a convenient method for convert(Object, Class, Object, Object, boolean) with both return values set to null and
the last argument set to true (i.e. special processing of collections).
T - type of the return objectvalue - the value that should be convertedclazz - the requested type of the return value, needed for initializationT if a conversion was successful, nullValue if null was tested successfully, falseValue in all other casesconvert(Object, Class, Object, Object, boolean)static <T> T convert(Object value, Class<T> clazz, T nullValue, T falseValue)
Type safe casting or conversion from Object to target class, special processing for Object[] and Collections.
This is a convenient method for convert(Object, Class, Object, Object, boolean) with the last
argument set to true (i.e. special processing of collections).
T - type of the return objectvalue - the value that should be convertedclazz - the requested type of the return value, needed for initializationnullValue - the value to be used if a null test succeedsfalseValue - the value to be used in case no test succeedsT if a conversion was successful, nullValue if null was tested successfully, falseValue in all other casesconvert(Object, Class, Object, Object, boolean)static <T> T convert(Object value, Class<T> clazz, T nullValue, T falseValue, boolean collFirst)
Type safe casting or conversion from Object to target class, with optional special processing for Object[] and Collections.
T - type of the return objectvalue - the value that should be convertedclazz - the requested type of the return value, needed for initializationnullValue - the value to be used if a null test succeedsfalseValue - the value to be used in case no test succeedscollFirst - if set true, collections will be processed and the first element returned, no special collection processing otherwiseT if a conversion was successful, nullValue if null was tested successfully, falseValue in all other casescreate(java.lang.Class<T>, T, T, boolean)Copyright © 2016–2017. All rights reserved.