Package org.goplanit.utils.reflection
Class ReflectionUtils
- java.lang.Object
-
- org.goplanit.utils.reflection.ReflectionUtils
-
public class ReflectionUtils extends Object
Reflection specific utility functions- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectcreateInstance(String className, Object... constructorParameters)Create an instance of given class name and provided constructor parametersstatic <T> TcreateTypedInstance(String className, Object... constructorParameters)delegates tocreateInstance(String, Object...)only casts result to type providedstatic Map<String,Object>declaredFieldsNameValueMap(Object settingsClazzInstance, Function<Integer,Boolean> modifierFilter)Collect all declared fields of instance in Map in name, value formatstatic <K,V>
Map<K,V>declaredFieldsToMap(Object settingsClazzInstance, Function<Field,K> keyFunction, BiFunction<Field,Object,V> valueFunction, Function<Integer,Boolean> modifierFilter)Collect all declared fields of instance in Map based on functions passed instatic Class<?>[]getParameterTypes(Object[] parameters)Method that constructs the parameter types that go with the passed in parameters.
-
-
-
Method Detail
-
getParameterTypes
public static Class<?>[] getParameterTypes(Object[] parameters)
Method that constructs the parameter types that go with the passed in parameters.- Parameters:
parameters- the parameters- Returns:
- parameter class types
-
createTypedInstance
public static <T> T createTypedInstance(String className, Object... constructorParameters) throws PlanItException
delegates tocreateInstance(String, Object...)only casts result to type provided- Type Parameters:
T- type of the created instance- Parameters:
className- of the class to be instantiatedconstructorParameters- parameters for constructor- Returns:
- created instance
- Throws:
PlanItException- when error occurs during instantiation
-
createInstance
public static Object createInstance(String className, Object... constructorParameters)
Create an instance of given class name and provided constructor parameters- Parameters:
className- of the class to be instantiatedconstructorParameters- parameters for constructor- Returns:
- created instance
-
declaredFieldsNameValueMap
public static Map<String,Object> declaredFieldsNameValueMap(Object settingsClazzInstance, Function<Integer,Boolean> modifierFilter)
Collect all declared fields of instance in Map in name, value format- Parameters:
settingsClazzInstance- to collect frommodifierFilter- applied to the fields of the class, when false we exclude the field, when true we keep it- Returns:
- map with entries, or empty if none could be found or something went wrong
-
declaredFieldsToMap
public static <K,V> Map<K,V> declaredFieldsToMap(Object settingsClazzInstance, Function<Field,K> keyFunction, BiFunction<Field,Object,V> valueFunction, Function<Integer,Boolean> modifierFilter)
Collect all declared fields of instance in Map based on functions passed in- Type Parameters:
K- key in result mapV- value in result map- Parameters:
settingsClazzInstance- to collect fromkeyFunction- transforms field to key entry in mapvalueFunction- transforms field to value entry in mapmodifierFilter- applied to the fields of the class, when false we exclude the field, when true we keep it- Returns:
- map with entries, or empty if none could be found or something went wrong
-
-