public final class TypeUtils extends Object
Particularly of interest is generateCompatibleTypeLists(Set, Class[]),
which generates a collection of type lists which can be derived from the input type
list. This is usful for method matching, since Java reflection doesn't take into account
autoboxing, casting or auto widening, let alone type conversions.
Types that are candidates for Autoboxing:
java.lang.Booleanjava.lang.Characterjava.lang.Bytejava.lang.Shortjava.lang.Integerjava.lang.Longjava.lang.Floatjava.lang.Double
For types that are candidates for common conversion, please see ValueConversionHelper.
| Constructor and Description |
|---|
TypeUtils() |
| Modifier and Type | Method and Description |
|---|---|
static @Nullable Class<?> |
autobox(Class<?> c)
Emulates Java's Autoboxing feature; tries to convert a type to its (un)wrapped counter version.
|
static @NotNull Class<?>[] |
collectTypes(Object[] objects)
Creates a new array of class objects harvested from an array of objects.
|
static boolean |
containsAnnotation(Annotation[] myListOfAnnotations,
Class<? extends Annotation> annotationClass) |
static boolean |
containsAnnotation(List<Annotation> myListOfAnnotations,
Class<? extends Annotation> annotationClass) |
static <T extends Annotation> |
findAnnotation(Annotation[] myListOfAnnotations,
Class<T> annotationClass) |
static <T extends Annotation> |
findAnnotation(Collection<Annotation> myListOfAnnotations,
Class<T> annotationClass) |
static @NotNull List<Class<?>[]> |
generateCompatibleTypeLists(Set<LookupMode> lookupMode,
Class<?>... inputTypelist)
Initializes the list with type-arrays and starts generating beginning from index 0.
|
static boolean |
isPackage(String name)
Validates whether a string represents a valid package.
|
static boolean |
isTypeListCompatible(Class<?>[] inputTypeList,
Class<?>[] targetTypeList,
Set<LookupMode> lookupMode) |
static @NotNull Class<?> |
widestNumberClass(Number... numbers)
Returns the smallest class that can hold all of the specified numbers.
|
@NotNull public static @NotNull Class<?>[] collectTypes(Object[] objects)
NOTE: this method will never return primitive classes (such as double.class, as you can't put primitive values into an array of Objects (they will be autoboxes by the JVM).
objects - The array of objects to harvest classtypes from.public static boolean isTypeListCompatible(Class<?>[] inputTypeList, Class<?>[] targetTypeList, Set<LookupMode> lookupMode)
@NotNull public static @NotNull List<Class<?>[]> generateCompatibleTypeLists(Set<LookupMode> lookupMode, Class<?>... inputTypelist)
lookupMode - Flag indicating the search steps that need to be done.inputTypelist - The list with original user specified types.@Nullable public static @Nullable Class<?> autobox(Class<?> c)
c - The datatype to convert (autobox).@NotNull public static @NotNull Class<?> widestNumberClass(Number... numbers)
numbers - The list with numbers that all should fit in the Number container.Number container that is just large enough for all specified numbers.public static boolean isPackage(String name)
name - The string representing a list of packages.public static boolean containsAnnotation(List<Annotation> myListOfAnnotations, Class<? extends Annotation> annotationClass)
findAnnotation(Collection, Class)public static boolean containsAnnotation(Annotation[] myListOfAnnotations, Class<? extends Annotation> annotationClass)
findAnnotation(Annotation[], Class)@Nullable public static <T extends Annotation> T findAnnotation(Collection<Annotation> myListOfAnnotations, Class<T> annotationClass)
findAnnotation(Annotation[], Class)@Nullable public static <T extends Annotation> T findAnnotation(Annotation[] myListOfAnnotations, Class<T> annotationClass)
Copyright © 2011–2019. All rights reserved.