Skip to content
Snippets Groups Projects
Commit 4afc2683 authored by Simon Barner's avatar Simon Barner
Browse files

Add isDirectlyDerived(), a predicate whether a given {@code type} is directly...

Add isDirectlyDerived(), a predicate whether a given {@code type} is directly derived from a given {@code superType}, or whether the {@code type} implements the {@code superType} interface.
refs 2950
parent 4a8e3e31
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ import org.apache.commons.lang.WordUtils; ...@@ -28,7 +28,7 @@ import org.apache.commons.lang.WordUtils;
* @author doebber * @author doebber
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 0BCFE18A0C3A2F20A258EEB72B7AD343 * @ConQAT.Rating YELLOW Hash: 15E009EC41779E81E68F52D2958BC419
*/ */
public class JavaUtils { public class JavaUtils {
...@@ -87,4 +87,28 @@ public class JavaUtils { ...@@ -87,4 +87,28 @@ public class JavaUtils {
return buffer.toString(); return buffer.toString();
} }
/**
* Predicate whether a given {@code type} is directly derived from a given {@code superType}, or
* whether the {@code type} implements the {@code superType} interface.
*
* @param type
* Type to for which to check if it is directly derived from the given
* {@code superType}.
* @param superType
* Super-type which should be tested for the given {@code type}.
*
* @return {@code true} iff a given {@code type} is directly derived from a given
* {@code superType}, or if the {@code type} implements the {@code superType} interface.
*/
public static boolean isDirectlyDerived(Class<?> type, Class<?> superType) {
for(Class<?> iFace : type.getInterfaces()) {
if(iFace.equals(superType)) {
return true;
}
}
Class<?> typeSuperClass = type.getSuperclass();
return typeSuperClass != null && typeSuperClass.equals(superType);
}
} }
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