Class ClassUtil
java.lang.Object
ru.progrm_jarvis.javacommons.classloading.ClassUtil
Utility for class-related stuff.
-
Method Summary
Modifier and TypeMethodDescriptionclassDigger(boolean interfaces) Creates a class-digger for use withRecursions APIwhich digs the class hierarchy.Creates a class-digger for use withRecursions APIwhich digs the class hierarchy including super-classes and parent interfaces.Creates a class-digger for use withRecursions APIwhich digs the class hierarchy only including super-classes.static Class<?>integrateType(@NotNull Class<?> original, @NotNull Class<?> target) Integrates the original type with the target making so that target type should be assignable from integrated one (i.e., attempting to make the original type a sub-class of the target type)static booleanisPrimitiveWrapper(Class<?> clazz) Checks if the given class is a primitive wrapper.static @NotNull Class<?>toNonPrimitive(@NotNull Class<?> originalClass) Either returns a primitive-wrapper class for the given one if it is primitive or the provided class otherwise.static Class<?>toPrimitive(@NotNull Class<?> primitiveWrapperClass) Gets a primitive class for the given primitive-wrapper class.static @NotNull Class<?>toPrimitiveWrapper(@NotNull Class<?> primitiveClass) Gets a primitive-wrapper class for the given primitive class.
-
Method Details
-
isPrimitiveWrapper
Checks if the given class is a primitive wrapper.- Parameters:
clazz- class to check- Returns:
trueif the class is a primitive wrapper andfalseotherwise
-
toPrimitiveWrapper
@NotNull public static @NotNull Class<?> toPrimitiveWrapper(@NotNull @NotNull Class<?> primitiveClass) Gets a primitive-wrapper class for the given primitive class.- Parameters:
primitiveClass- primitive class whose wrapper is needed- Returns:
- primitive-wrapper class for the given primitive class
- Throws:
IllegalArgumentException- if the given class is not primitive
-
toNonPrimitive
Either returns a primitive-wrapper class for the given one if it is primitive or the provided class otherwise.- Parameters:
originalClass- class whose wrapper should be returned on demand- Returns:
- primitive-wrapper class for the given class if it is primitive or the provided class otherwise
-
toPrimitive
Gets a primitive class for the given primitive-wrapper class.- Parameters:
primitiveWrapperClass- primitive-wrapper class whose wrapper is needed- Returns:
- primitive class for the given primitive-wrapper class
- Throws:
IllegalArgumentException- if the given class is not a primitive-wrapper
-
integrateType
public static Class<?> integrateType(@NotNull @NotNull Class<?> original, @NotNull @NotNull Class<?> target) Integrates the original type with the target making so that target type should be assignable from integrated one (i.e., attempting to make the original type a sub-class of the target type)
This method performs primitive-to-wrapper conversion in oder to attempt integration.
- Parameters:
original- original type which should be integrated to the target typetarget- target type to which the original type should be integrated- Returns:
- result of type integration, my be the same as original type
- Throws:
IllegalArgumentException- if original type cannot be integrated to the target type
-
classDigger
@NotNull public static @NotNull Function<? super @NotNull Class<?>,@NotNull Stream<? extends @NotNull Class<?>>> classDigger(boolean interfaces) Creates a class-digger for use withRecursions APIwhich digs the class hierarchy.- Parameters:
interfaces- whether interfaces should be considered- Returns:
- digger which returns a
streamof super-classes and implemented interfaces (optionally) of the provided class
-
classDiggerWithoutInterfaces
@NotNull public static @NotNull Function<? super @NotNull Class<?>,@NotNull Stream<? extends @NotNull Class<?>>> classDiggerWithoutInterfaces()Creates a class-digger for use withRecursions APIwhich digs the class hierarchy only including super-classes.- Returns:
- digger which returns a
streamof super-classes of the provided class
-
classDiggerWithInterfaces
@NotNull public static @NotNull Function<? super @NotNull Class<?>,@NotNull Stream<? extends @NotNull Class<?>>> classDiggerWithInterfaces()Creates a class-digger for use withRecursions APIwhich digs the class hierarchy including super-classes and parent interfaces.- Returns:
- digger which returns a
streamof super-classes and implemented interfaces of the provided class
-