dongjoon-hyun commented on code in PR #51509:
URL: https://github.com/apache/spark/pull/51509#discussion_r2209176334
##########
common/utils/src/main/scala/org/apache/spark/util/SparkClassUtils.scala:
##########
@@ -136,6 +137,33 @@ private[spark] trait SparkClassUtils {
}
}
}
+
+ /**
+ * Gets a list of all interfaces implemented by the given class and its
superclasses.
+ */
+ def getAllInterfaces(cls: Class[_]): List[Class[_]] = {
+ if (cls == null) {
+ return null
+ }
+ val interfacesFound = LinkedHashSet[Class[_]]()
+ getAllInterfacesHelper(cls, interfacesFound)
+ interfacesFound.toList
+ }
+
+ private def getAllInterfacesHelper(
+ clazz: Class[_],
+ interfacesFound: LinkedHashSet[Class[_]]): Unit = {
+ var currentClass = clazz
+ while (currentClass != null) {
+ val interfaces = currentClass.getInterfaces
+ for (i <- interfaces) {
+ if (interfacesFound.add(i)) {
+ getAllInterfacesHelper(i, interfacesFound)
+ }
+ }
+ currentClass = currentClass.getSuperclass
+ }
+ }
Review Comment:
Technically, this is a Scala version of
https://github.com/apache/commons-lang/blob/3abb3a25509bcf0a6e631e2b7bef1a8f30b299c6/src/main/java/org/apache/commons/lang3/ClassUtils.java#L352-L361
https://github.com/apache/commons-lang/blob/3abb3a25509bcf0a6e631e2b7bef1a8f30b299c6/src/main/java/org/apache/commons/lang3/ClassUtils.java#L369-L381
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]