Class ClassUtils

java.lang.Object
me.datafox.dfxengine.utils.ClassUtils

public class ClassUtils extends Object
Utilities for classes and reflection.
  • Constructor Details Link icon

    • ClassUtils Link icon

      public ClassUtils()
  • Method Details Link icon

    • getSuperclassesFor Link icon

      public static <T> Stream<Class<? super T>> getSuperclassesFor(Class<? super T> aClass)
      Type Parameters:
      T - type of the class
      Parameters:
      aClass - class
      Returns:
      Stream of the class and all superclasses and superinterfaces of the class
    • getConstructorsWithAnnotation Link icon

      public static <T> List<Constructor<T>> getConstructorsWithAnnotation(Class<T> aClass, Class<? extends Annotation> annotation)
      Type Parameters:
      T - type of the class
      Parameters:
      aClass - class
      annotation - annotation
      Returns:
      List of all declared constructors of the class with the annotation
    • getFieldsWithAnnotation Link icon

      public static <T> List<Field> getFieldsWithAnnotation(Class<T> aClass, Class<? extends Annotation> annotation)
      Type Parameters:
      T - type of the class
      Parameters:
      aClass - class
      annotation - annotation
      Returns:
      List of all declared fields of the class with the annotation
    • getMethodsWithAnnotation Link icon

      public static <T> List<Method> getMethodsWithAnnotation(Class<T> aClass, Class<? extends Annotation> annotation)
      Type Parameters:
      T - type of the class
      Parameters:
      aClass - class
      annotation - annotation
      Returns:
      List of all declared methods of the class with the annotation
    • getAnnotationFromArray Link icon

      public static <T extends Annotation> Optional<T> getAnnotationFromArray(Annotation[] arr, Class<T> annotationType)
      Type Parameters:
      T - type of the annotation
      Parameters:
      arr - array of annotations
      annotationType - annotation type
      Returns:
      Optional containing the first annotation in the array matching the type, or empty if no matches are found
    • filterInstanceAndCast Link icon

      public static <T, C> Stream<C> filterInstanceAndCast(T input, Class<C> aClass)
      Type Parameters:
      T - type of the input
      C - type to be cast to
      Parameters:
      input - object to be checked
      aClass - Class
      Returns:
      Stream of the object cast to the specified Class, or an empty Stream if the object cannot be cast to the specified Class
    • filterInstanceAndCast Link icon

      public static <T, C> Function<T,Stream<C>> filterInstanceAndCast(Class<C> aClass)
      Type Parameters:
      T - type of the input
      C - type to be cast to
      Parameters:
      aClass - Class
      Returns:
      Function that returns a Stream of the object cast to the specified Class, or an empty Stream if the object cannot be cast to the specified Class