From 2d0b2246912ebbad53f54fcdf0c82587bd12eca5 Mon Sep 17 00:00:00 2001
From: Alexander Diewald <diewald@fortiss.org>
Date: Tue, 16 Apr 2019 18:14:16 +0200
Subject: [PATCH] Add a isAssignableFromAny test for class objects

Issue-Ref: 3708
Issue-Url: https://af3-developer.fortiss.org/issues/3708
Signed-off-by: Alexander Diewald <diewald@fortiss.org>
---
 .../src/org/fortiss/tooling/common/util/.ratings |  2 +-
 .../fortiss/tooling/common/util/LambdaUtils.java | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/.ratings b/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/.ratings
index 5c036a37e..f558f34c5 100644
--- a/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/.ratings
+++ b/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/.ratings
@@ -1 +1 @@
-LambdaUtils.java 6a7260eca3f4c0f44e97a26cfeacb8801d00bf6c GREEN
+LambdaUtils.java 6fed9bb62eba3f7af6ebd7821fb22df6fcc507f8 YELLOW
diff --git a/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/LambdaUtils.java b/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/LambdaUtils.java
index 6a7260eca..6fed9bb62 100644
--- a/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/LambdaUtils.java
+++ b/org.fortiss.tooling.common/src/org/fortiss/tooling/common/util/LambdaUtils.java
@@ -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());
 	}
 
 	/**
-- 
GitLab