Class ClassLoadingUtil

java.lang.Object
ru.progrm_jarvis.javacommons.classloading.ClassLoadingUtil

public final class ClassLoadingUtil extends Object
General purpose utility for Class-related operations.
  • Method Details

    • getClass

      public static <T> Optional<Class<? extends T>> getClass(@NonNull @NonNull String className, boolean loadIfNeeded, @NonNull @NonNull ClassLoader classLoader)
      Attempts to find a class by the given name wrapping it in an Optional.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      classLoader - class-loader to use for lookup
      Returns:
      optional containing the class if it was found or an empty one otherwise
    • getClass

      public static <T> Optional<Class<? extends T>> getClass(@NonNull @NonNull String className, boolean loadIfNeeded)
      Attempts to find a class by the given name using current class-loader wrapping it in an Optional.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      Returns:
      optional containing the class if it was found or an empty one otherwise
    • getClass

      public static <T> Optional<Class<? extends T>> getClass(@NonNull @NonNull String className)
      Attempts to find a class by the given name using current class-loader wrapping it in an Optional. This will load the class if needed.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      Returns:
      optional containing the class if it was found or an empty one otherwise
    • getNullableClass

      public static <T> Class<? extends T> getNullableClass(@NonNull @NonNull String className, boolean loadIfNeeded, @NonNull @NonNull ClassLoader classLoader)
      Attempts to find a class by the given name.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      classLoader - class-loader to use for lookup
      Returns:
      the class if it was found or null
    • getNullableClass

      public static <T> Class<? extends T> getNullableClass(@NonNull @NonNull String className, boolean loadIfNeeded)
      Attempts to find a class by the given name using current class-loader.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      Returns:
      the class if it was found or null
    • getNullableClass

      public static <T> Class<? extends T> getNullableClass(@NonNull @NonNull String className)
      Attempts to find a class by the given name using current class-loader. This will load the class if needed.
      Type Parameters:
      T - type of the class
      Parameters:
      className - name of the class to search for
      Returns:
      the class if it was found or null
    • isClassAvailable

      public static boolean isClassAvailable(@NonNull @NonNull String className, boolean loadIfNeeded, @NonNull @NonNull ClassLoader classLoader)
      Checks if the class is available.
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      classLoader - class-loader to use for lookup
      Returns:
      true if the class is available and false otherwise
    • isClassAvailable

      public static boolean isClassAvailable(@NonNull @NonNull String className, boolean loadIfNeeded)
      Checks if the class is available using current class-loader.
      Parameters:
      className - name of the class to search for
      loadIfNeeded - flag indicating whether the class should be loaded if it is available but not loaded yet
      Returns:
      true if the class is available and false otherwise
    • isClassAvailable

      public static boolean isClassAvailable(@NonNull @NonNull String className)
      Checks if the class is available using current class-loader. This will load the class if needed.
      Parameters:
      className - name of the class to search for
      Returns:
      true if the class is available and false otherwise