Package org.fuin.ddd4j.ddd
Class MethodExecutor
- java.lang.Object
-
- org.fuin.ddd4j.ddd.MethodExecutor
-
@ThreadSafe public final class MethodExecutor extends Object
Lightweight utility class to execute a method using reflection.
-
-
Constructor Summary
Constructors Constructor Description MethodExecutor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodfindDeclaredAnnotatedMethod(@NotNull Object obj, @NotNull Class<? extends Annotation> annotationType, Class<?>... expectedArgumentTypes)Finds a declared method on the instance or it's parents that has an annotation and optional parameters.List<Method>getDeclaredMethodsIncludingSuperClasses(@NotNull Class<?> clasz, @NotNull Class<?>... stopParents)Returns a list of declared methods from classes and super classes.<T> Tinvoke(@NotNull Method method, @NotNull Object target, Object... args)Invokes a method with any number of arguments.<T> TinvokeDeclaredAnnotatedMethod(@NotNull Object obj, @NotNull Class<? extends Annotation> annotationType, Class<?>[] argumentTypes, Object[] arguments)Finds a declared method that has an annotation and optional parameters.booleansame(Class<?>[] expected, Class<?>[] actual)Verifies if both arrays have the same length and types.
-
-
-
Method Detail
-
invokeDeclaredAnnotatedMethod
public final <T> T invokeDeclaredAnnotatedMethod(@NotNull @NotNull Object obj, @NotNull @NotNull Class<? extends Annotation> annotationType, Class<?>[] argumentTypes, Object[] arguments)Finds a declared method that has an annotation and optional parameters.- Type Parameters:
T- Type of the return value.- Parameters:
obj- Object to inspect.annotationType- Expected annotation type.argumentTypes- Expected argument types, empty array ornull.arguments- Arguments, empty array ornull. Must be the same size as 'argumentTypes'.- Returns:
- Value returned by the method or
null.
-
findDeclaredAnnotatedMethod
public final Method findDeclaredAnnotatedMethod(@NotNull @NotNull Object obj, @NotNull @NotNull Class<? extends Annotation> annotationType, Class<?>... expectedArgumentTypes)
Finds a declared method on the instance or it's parents that has an annotation and optional parameters. The class- Parameters:
obj- Object to inspect.annotationType- Expected annotation type.expectedArgumentTypes- Expected argument types, empty array ornull.- Returns:
- Method or
nullif any of the expected parameters does not match.
-
getDeclaredMethodsIncludingSuperClasses
public final List<Method> getDeclaredMethodsIncludingSuperClasses(@NotNull @NotNull Class<?> clasz, @NotNull @NotNull Class<?>... stopParents)
Returns a list of declared methods from classes and super classes. The given stop classes will not be inspected.- Parameters:
clasz- Class to inspect.stopParents- Parent classes to stop inspection or null to stop atObject.- Returns:
- List of methods.
-
invoke
public final <T> T invoke(@NotNull @NotNull Method method, @NotNull @NotNull Object target, Object... args)Invokes a method with any number of arguments.- Type Parameters:
T- Type of the return value.- Parameters:
method- Method to call.target- Object that contains the method.args- Arguments, empty array ornull.- Returns:
- Value returned by the method or
null.
-
-