Package org.eclnt.util.valuemgmt
Class PojoManager
java.lang.Object
org.eclnt.util.valuemgmt.PojoManager
Useful methods around dealing with Pojo objects in a generic way.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface for checking of to transfer a property value inside methodtransferPojoIntoPojo(Object, Object, boolean, ICheckIfToTransferPropertyValue, boolean)
.static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
calculateHashForListOfPojos
(List<?> beanList) static String
calculateHashForPojo
(Object bean) Calculates hash code by iterating through properties of bean and calculates the hash code of each individual property - then calculates the whole hash code using the functionObjects.hash(Object...)
.static String
calculateHashForPojo
(Object bean, boolean withDrillDown) comparePojosOfSameClass
(Object fromBean, Object toBean) static <OBJTYPE> OBJTYPE
createPojoFromMapData
(Class<OBJTYPE> clazz, Map<String, ?> map, boolean withError) static <OBJTYPE> OBJTYPE
createPojoFromStringMapData
(Class<OBJTYPE> clazz, Map<String, String> map, boolean withError) Creates object and transfers the String values in the Map into the object properties.static Object
getPropertyValue
(Object bean, String propertyName) static Object
getPropertyValue
(Object bean, String propertyName, boolean withError) static void
setPropertyValue
(Object bean, String propertyName, Object value) static void
setPropertyValue
(Object bean, String propertyName, Object value, boolean withError) static void
transferObjectMapDataIntoPojo
(Map<String, ?> map, Object bean, boolean withError) Transfers the data contained within the map into the corresponding set-ter methods of the "bean" that is passed as parameter.transferPojoIntoMap
(Object bean) Transfers all simple data type properties of the bean into a map.static void
transferPojoIntoPojo
(Object fromBean, Object bean, boolean withError) Convenience method fortransferPojoIntoPojo(Object, Object, boolean, boolean, boolean)
setting parameters "simpleDataTypeOnly" to false, and "notNullOnly" to false.static void
transferPojoIntoPojo
(Object fromBean, Object bean, boolean simpleDataTypesOnly, boolean notNullOnly, boolean withError) Transfers properties from the "fromBean" into the "bean".static void
transferPojoIntoPojo
(Object fromBean, Object bean, boolean simpleDataTypesOnly, PojoManager.ICheckIfToTransferPropertyValue checker, boolean withError) static void
transferStringMapDataIntoPojo
(Map<String, String> map, Object bean, boolean withError) Transfers data from map into bean.static void
transferStringMapDataIntoPojoChangesOnly
(Map<String, String> map, Object bean, boolean withError) Extension oftransferStringMapDataIntoPojo(Map, Object, boolean, boolean)
: before calling the set-ter to transfer the value, the get-ter is called to check if the current value is different to the value of the map.
-
Constructor Details
-
PojoManager
public PojoManager()
-
-
Method Details
-
calculateHashForPojo
Calculates hash code by iterating through properties of bean and calculates the hash code of each individual property - then calculates the whole hash code using the functionObjects.hash(Object...)
. -
calculateHashForPojo
-
calculateHashForListOfPojos
-
transferPojoIntoMap
Transfers all simple data type properties of the bean into a map. The key of the map is the name of the property. -
transferPojoIntoPojo
Convenience method fortransferPojoIntoPojo(Object, Object, boolean, boolean, boolean)
setting parameters "simpleDataTypeOnly" to false, and "notNullOnly" to false. -
transferPojoIntoPojo
public static void transferPojoIntoPojo(Object fromBean, Object bean, boolean simpleDataTypesOnly, boolean notNullOnly, boolean withError) Transfers properties from the "fromBean" into the "bean". Properties are checked for same name and assignable type.- Parameters:
notNullOnly
- If the "fromBean" has a null-value for a property, then this null-value is only set into the other bean if this parameter is set to true. Idea behind: you may decide to only take over properties from the "fromBean" into the "bean" if they are not-null.withError
- In case some error happens (e.g. when calling the set-ter method of the "bean") then in case of "true" an Error will be thrown - otherwise the error will be ignored.
-
createPojoFromMapData
-
transferObjectMapDataIntoPojo
Transfers the data contained within the map into the corresponding set-ter methods of the "bean" that is passed as parameter. The type of the data must match - there is no type conversion. -
createPojoFromStringMapData
public static <OBJTYPE> OBJTYPE createPojoFromStringMapData(Class<OBJTYPE> clazz, Map<String, String> map, boolean withError) Creates object and transfers the String values in the Map into the object properties. Implicit conversions from String to the corresponding property data type are executed. -
transferStringMapDataIntoPojo
public static void transferStringMapDataIntoPojo(Map<String, String> map, Object bean, boolean withError) Transfers data from map into bean. The string is converted into a proper data type before. The conversion is done using the simple data type management of the ValueManager class:ValueManager.convertStringIntoObject(String, Class)
. -
transferStringMapDataIntoPojoChangesOnly
public static void transferStringMapDataIntoPojoChangesOnly(Map<String, String> map, Object bean, boolean withError) Extension oftransferStringMapDataIntoPojo(Map, Object, boolean, boolean)
: before calling the set-ter to transfer the value, the get-ter is called to check if the current value is different to the value of the map. Only if there's a difference then the set-ter is called.
Sometimes the set-ter of a pojo does more than just setting its internal member: it may e.g. register some change within the object. So, here the set-ter is only called when the corresponding property really is to be changed. The comparison is done using the normal "equals" method of objects. -
transferPojoIntoPojo
public static void transferPojoIntoPojo(Object fromBean, Object bean, boolean simpleDataTypesOnly, PojoManager.ICheckIfToTransferPropertyValue checker, boolean withError) -
setPropertyValue
-
setPropertyValue
-
getPropertyValue
-
getPropertyValue
-
comparePojosOfSameClass
public static List<PojoManager.PojoPropertyChangeInfo> comparePojosOfSameClass(Object fromBean, Object toBean)
-