Class ClassLoadingUtil
java.lang.Object
ru.progrm_jarvis.javacommons.classloading.ClassLoadingUtil
General purpose utility for
Class-related operations.-
Method Summary
Modifier and TypeMethodDescriptionAttempts to find a class by the given name using current class-loader wrapping it in anOptional.Attempts to find a class by the given name using current class-loader wrapping it in anOptional.getClass(@NonNull String className, boolean loadIfNeeded, @NonNull ClassLoader classLoader) Attempts to find a class by the given name wrapping it in anOptional.static <T> Class<? extends T>getNullableClass(@NonNull String className) Attempts to find a class by the given name using current class-loader.static <T> Class<? extends T>getNullableClass(@NonNull String className, boolean loadIfNeeded) Attempts to find a class by the given name using current class-loader.static <T> Class<? extends T>getNullableClass(@NonNull String className, boolean loadIfNeeded, @NonNull ClassLoader classLoader) Attempts to find a class by the given name.static booleanisClassAvailable(@NonNull String className) Checks if the class is available using current class-loader.static booleanisClassAvailable(@NonNull String className, boolean loadIfNeeded) Checks if the class is available using current class-loader.static booleanisClassAvailable(@NonNull String className, boolean loadIfNeeded, @NonNull ClassLoader classLoader) Checks if the class is available.
-
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 anOptional.- Type Parameters:
T- type of the class- Parameters:
className- name of the class to search forloadIfNeeded- flag indicating whether the class should be loaded if it is available but not loaded yetclassLoader- 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 anOptional.- Type Parameters:
T- type of the class- Parameters:
className- name of the class to search forloadIfNeeded- 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
Attempts to find a class by the given name using current class-loader wrapping it in anOptional. 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 forloadIfNeeded- flag indicating whether the class should be loaded if it is available but not loaded yetclassLoader- 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 forloadIfNeeded- 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
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 forloadIfNeeded- flag indicating whether the class should be loaded if it is available but not loaded yetclassLoader- class-loader to use for lookup- Returns:
trueif the class is available andfalseotherwise
-
isClassAvailable
Checks if the class is available using current class-loader.- Parameters:
className- name of the class to search forloadIfNeeded- flag indicating whether the class should be loaded if it is available but not loaded yet- Returns:
trueif the class is available andfalseotherwise
-
isClassAvailable
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:
trueif the class is available andfalseotherwise
-