Skip to content
Snippets Groups Projects
Commit 2d0b2246 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Add a isAssignableFromAny test for class objects

parent fba585c2
No related branches found
No related tags found
1 merge request!50Add a isAssignableFromAny test for class objects
LambdaUtils.java 6a7260eca3f4c0f44e97a26cfeacb8801d00bf6c GREEN
LambdaUtils.java 6fed9bb62eba3f7af6ebd7821fb22df6fcc507f8 YELLOW
......@@ -300,6 +300,20 @@ public class LambdaUtils {
return collection.stream().findFirst();
}
/**
* Checks whether the given object inherits from any of the given Classes, i.e. the check
* {@link Class#isAssignableFrom(Class)} is performed for each given class on the given Object.
*
* @param types
* collection of classes to check inheritance.
* @param testType
* type to check whether it inherits from any of the given classes.
* @return see above.
*/
public static boolean isAssignableFromAny(Collection<Class<?>> types, Class<?> testType) {
return types.stream().anyMatch(t -> t.isAssignableFrom(testType));
}
/**
* Checks whether the given object inherits from any of the given Classes, i.e. the check
* {@link Class#isAssignableFrom(Class)} is performed for each given class on the given Object.
......@@ -311,7 +325,7 @@ public class LambdaUtils {
* @return see above.
*/
public static boolean isAssignableFromAny(Collection<Class<?>> types, Object element) {
return types.stream().anyMatch(t -> t.isAssignableFrom(element.getClass()));
return isAssignableFromAny(types, element.getClass());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment