fix probability collection loading

This commit is contained in:
dfsek
2021-07-05 15:25:05 -07:00
parent dea12d3056
commit d2298240ed
5 changed files with 25 additions and 49 deletions

View File

@@ -0,0 +1,37 @@
package com.dfsek.terra.api.util;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.stream.Stream;
public class ReflectionUtil {
public static Field[] getFields(@NotNull Class<?> type) {
Field[] result = type.getDeclaredFields();
Class<?> parentClass = type.getSuperclass();
if(parentClass != null) {
result = Stream.concat(Arrays.stream(result), Arrays.stream(getFields(parentClass))).toArray(Field[]::new);
}
return result;
}
public static Method[] getMethods(@NotNull Class<?> type) {
Method[] result = type.getDeclaredMethods();
Class<?> parentClass = type.getSuperclass();
if(parentClass != null) {
result = Stream.concat(Arrays.stream(result), Arrays.stream(getMethods(parentClass))).toArray(Method[]::new);
}
return result;
}
public static <T extends Annotation> void ifAnnotationPresent(AnnotatedElement element, Class<? extends T> annotation, Consumer<T> operation) {
T a = element.getAnnotation(annotation);
if(a != null) operation.accept(a);
}
}