public class TypeUtils extends Object
Constructor and Description |
---|
TypeUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> Function<Class<?>,Class<? extends T>> |
asSubclass(Class<T> supertype)
Function that casts classes to specified types.
|
static Function<Object,Class<?>> |
extractClass()
Function that gets the class for its argument.
|
static Function<Object,Class<?>> |
extractClass(boolean acceptNull)
Function that gets the class for its argument.
|
static <T> Function<T,Class<? extends T>> |
extractClass(Class<T> supertype)
Function that gets the class for its argument.
|
static <T> Function<T,Class<? extends T>> |
extractClass(Class<T> supertype,
boolean acceptNull)
Function that gets the class for its argument.
|
static <T> Set<Class<? extends T>> |
findTypes(Iterable<? extends T> objects,
Class<T> parent)
Build the set of types implemented by the objects' classes.
|
static Predicate<Class<?>> |
isSubclass(Class<?> cls) |
static Predicate<Class<?>> |
subtypePredicate(Class<?> parent)
A predicate that accepts classes which are subtypes of (assignable to) the parent class.
|
static Set<Class<?>> |
typeClosure(Class<?> type)
Return the supertype closure of a type (the type and all its transitive
supertypes).
|
public static <T> Set<Class<? extends T>> findTypes(Iterable<? extends T> objects, Class<T> parent)
objects
- A collection of objects. This iterable may be fast (returning a modified
version of the same object).parent
- The parent type of interest.public static Set<Class<?>> typeClosure(Class<?> type)
type
- The type.public static <T> Function<Class<?>,Class<? extends T>> asSubclass(Class<T> supertype)
supertype
- A class known to be a valid supertype for any argument.public static <T> Function<T,Class<? extends T>> extractClass(Class<T> supertype, boolean acceptNull)
supertype
- A class known to be a valid supertype for any argument.acceptNull
- Whether nulls are accepted & passed through. If false
, the function
will never return null
.public static <T> Function<T,Class<? extends T>> extractClass(Class<T> supertype)
supertype
- A class known to be a valid supertype for any argument.public static Function<Object,Class<?>> extractClass()
public static Function<Object,Class<?>> extractClass(boolean acceptNull)
public static Predicate<Class<?>> subtypePredicate(Class<?> parent)
parent
- The parent class.true
when applied to a subtype of parent
.
That is, it implements paret.isAssignableFrom(type)
.