public class TypeUtil extends Object
Note: This class is not a part of the public API and is subject to change. Do not use it in your own code
Modifier and Type | Method and Description |
---|---|
static Class<?> |
getElementType(Type value)
Retrieves the
Class<?> object that represents either the parameter type of supported collection or the
array type. |
static Class<?> |
getRawType(Type value)
Retrieves the
Class reference that signifies the "raw" part of a parametrized type entity. |
static boolean |
isArrayOfType(Type value,
Class<?> sample)
Gets whether the provided
Type represents a Java array of the provided type |
static boolean |
isArrayOfType(Type value,
Predicate<Class<?>> sample)
Gets whether the provided
Type represents a Java array of the provided type |
static boolean |
isEmpty(Object value)
Gets whether the given value can be considered an "empty" object.
|
static boolean |
isMapOfValueType(Type value,
Class<?> sample)
Retrieves whether the provided
Type represents a parametrized Map type, and its parameter type
corresponds to the given argument |
static boolean |
isSlingRequestAdapter(org.apache.sling.models.factory.ModelFactory modelFactory,
Type type)
Gets whether the given
type is a SlingHttpServletRequest adapter |
static boolean |
isSupportedCollection(Type value,
boolean strict)
|
static boolean |
isSupportedCollectionOfType(Type value,
Class<?> sample,
boolean strict)
Retrieves whether the provided
Type of Java class member is a parametrized collection type, and its
parameter type matches the list of allowed value types |
static boolean |
isSupportedCollectionOfType(Type value,
Predicate<Class<?>> sample,
boolean strict)
Retrieves whether the provided
Type of Java class member is a parametrized collection type, and its
parameter type matches the list of allowed value types |
static boolean |
isSupportedCollectionOrArray(Type value,
boolean strict)
Gets whether the provided
Type object represents either a collection of type Collection ,
List or Set , or else an array |
static boolean |
isSupportedCollectionOrArrayOfType(Type value,
Class<?> sample,
boolean strict)
Gets whether the provided
Type object represents either a collection of type Collection ,
List or Set , or else an array of elements having the provided type |
static boolean |
isSupportedCollectionOrArrayOfType(Type value,
Predicate<Class<?>> sample,
boolean strict)
Gets whether the provided
Type object represents either a collection of type Collection ,
List or Set , or else an array of elements having the provided type |
public static Class<?> getElementType(Type value)
Class<?>
object that represents either the parameter type of supported collection or the
array type. If the passed type
cannot be treated as either array or collection, null
is returnedvalue
- Type
reference that matches a Java class memberClass
objectpublic static Class<?> getRawType(Type value)
Class
reference that signifies the "raw" part of a parametrized type entity. E.g., for the
List<String>
type, the List
is returned. If the given value is not a parametrized one, the type
itself is returnedvalue
- Type
reference that matches a Java class memberClass
object. Null
is returned if casting the type to Class
is not
possible (e.g., an empty value is provided)public static boolean isArrayOfType(Type value, Class<?> sample)
Type
represents a Java array of the provided typevalue
- Type
reference that matches a Java class membersample
- Class
object that the array type must matchpublic static boolean isArrayOfType(Type value, Predicate<Class<?>> sample)
Type
represents a Java array of the provided typevalue
- Type
reference that matches a Java class membersample
- A routine that tests whether the array/collection element matches the requirementpublic static boolean isEmpty(Object value)
null
, or
an empty array, iterable, or mapvalue
- Arbitrary objectpublic static boolean isMapOfValueType(Type value, Class<?> sample)
Type
represents a parametrized Map
type, and its parameter type
corresponds to the given argumentvalue
- Type
reference that matches a Java class membersample
- Class
object that the value type of the map must matchpublic static boolean isSlingRequestAdapter(org.apache.sling.models.factory.ModelFactory modelFactory, Type type)
type
is a SlingHttpServletRequest
adaptermodelFactory
- ModelFactory
instancetype
- Type of injectablepublic static boolean isSupportedCollection(Type value, boolean strict)
value
- Type
objectstrict
- If set to true
, the value
must be exactly Collection
, List
or
Set
. This flag is useful, e.g., when checking an injection target field for compliance.
Otherwise, the value just needs to be assignable to a collection typepublic static boolean isSupportedCollectionOfType(Type value, Class<?> sample, boolean strict)
Type
of Java class member is a parametrized collection type, and its
parameter type matches the list of allowed value typesvalue
- Type
reference that matches a Java class membersample
- Class
object representing the parameter typestrict
- If set to true
, the value
must be exactly Collection
, List
or
Set
. Otherwise, the value just needs to be assignable to a collection typepublic static boolean isSupportedCollectionOfType(Type value, Predicate<Class<?>> sample, boolean strict)
Type
of Java class member is a parametrized collection type, and its
parameter type matches the list of allowed value typesvalue
- Type
reference that matches a Java class membersample
- A routine that tests whether the array/collection element matches the requirementstrict
- If set to true
, the value
must be exactly Collection
, List
or
Set
. Otherwise, the value just needs to be assignable to a collection typepublic static boolean isSupportedCollectionOrArray(Type value, boolean strict)
Type
object represents either a collection of type Collection
,
List
or Set
, or else an arrayvalue
- Type
objectstrict
- If set to true
, and value
is a collection type, the value
must be exactly
Collection
, List
or Set
. Otherwise, the value just needs to be assignable
to a collection type. This flag does not have meaning if value
is not a collection typepublic static boolean isSupportedCollectionOrArrayOfType(Type value, Class<?> sample, boolean strict)
Type
object represents either a collection of type Collection
,
List
or Set
, or else an array of elements having the provided typevalue
- Type
objectsample
- Class
object that the array/collection type must matchstrict
- If set to true
, and value
is a collection type, the value
must be exactly
Collection
, List
or Set
. Otherwise, the value just needs to be assignable
to a collection type. This flag does not have meaning if value
is not a collection typepublic static boolean isSupportedCollectionOrArrayOfType(Type value, Predicate<Class<?>> sample, boolean strict)
Type
object represents either a collection of type Collection
,
List
or Set
, or else an array of elements having the provided typevalue
- Type
objectsample
- A routine that tests whether the array/collection element matches the requirementstrict
- If set to true
, and value
is a collection type, the value
must be exactly
Collection
, List
or Set
. Otherwise, the value just needs to be assignable
to a collection type. This flag does not have meaning if value
is not a collection typeCopyright © 2024 Exadel, Inc.. All rights reserved.