本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.getAllSuperclasses方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.getAllSuperclasses方法的具体用法?Java ClassUtils.getAllSuperclasses怎么用?Java ClassUtils.getAllSuperclasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.ClassUtils
的用法示例。
在下文中一共展示了ClassUtils.getAllSuperclasses方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConfigInstancesFromServiceAnnotations
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* Returns the ConfigInstances classes from the annotation on the given Service class ,
* including the ConfigInstances annotated on any of its super classes.
* NOTE: Only the super classes that are subclass of Service are inspected.
*/
private static Stream<Class<? extends ConfigInstance>> getConfigInstancesFromServiceAnnotations(Class<? extends Service> serviceClass) {
List<Class<?>> classHierarchy = ClassUtils.getAllSuperclasses(serviceClass);
classHierarchy.add(serviceClass);
return classHierarchy.stream()
.filter(Service.class::isAssignableFrom)
.filter(clazz -> clazz.isAnnotationPresent(RestartConfigs.class))
.map(clazz -> {
RestartConfigs annotation = clazz.getDeclaredAnnotation(RestartConfigs.class);
if (annotation.value().length == 0) {
throw new IllegalStateException(String.format(
"%s has a %s annotation with no ConfigInstances given as argument.",
clazz.getSimpleName(), RestartConfigs.class.getSimpleName()));
}
return annotation;
})
.map(RestartConfigs::value)
.flatMap(Arrays::stream)
.distinct();
}
示例2: getGroups
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static List<String> getGroups(Class klass) {
Set<String> set = new LinkedHashSet<>();
addGroupsToList(klass, set);
List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass);
for(Class<?> superClass : allSuperclasses) {
if(!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) {
addGroupsToList(superClass, set);
}
}
if(set.isEmpty()) {
set.add(""); // the default empty group
}
return new ArrayList<>(set);
}
示例3: getAllSuperclasses
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* 递归返回所有的SupperClasses,包含Object.class
*/
public static List<Class<?>> getAllSuperclasses(final Class<?> cls) {
return ClassUtils.getAllSuperclasses(cls);
}
示例4: isSubclass
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* <p>
* isSubclass
* </p>
*
* @param superclass
* a {@link java.lang.reflect.Type} object.
* @param subclass
* a {@link java.lang.reflect.Type} object.
* @return a boolean.
*/
public static boolean isSubclass(Type superclass, Type subclass) {
List<Class<?>> superclasses = ClassUtils.getAllSuperclasses((Class<?>) subclass);
List<Class<?>> interfaces = ClassUtils.getAllInterfaces((Class<?>) subclass);
if (superclasses.contains(superclass) || interfaces.contains(superclass)) {
return true;
}
return false;
}