--- a/java/sql-dk/src/info/globalcode/sql/dk/Functions.java Sat Aug 15 11:52:38 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/Functions.java Sat Aug 15 13:21:26 2015 +0200
@@ -24,9 +24,13 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
import java.util.Map;
/**
@@ -164,4 +168,21 @@
return result.toString();
}
}
+
+ /**
+ * @param <P> type of the last parent
+ * @param <T> type of the examined class
+ * @param type examined class
+ * @param lastParent the last parent type to stop at
+ * @return list of types starting with <code>type</code> and ending with <code>lastParent</code>
+ */
+ public static <P, T extends P> List<Class<? extends P>> getClassHierarchy(Class<T> type, Class<P> lastParent) {
+ List<Class<? extends P>> hierarchy = new ArrayList<>();
+
+ for (Class current = type; current != null && lastParent.isAssignableFrom(current); current = current.getSuperclass()) {
+ hierarchy.add(current);
+ }
+
+ return hierarchy;
+ }
}