Package org.springframework.data.util
Interface TypeInformation<S>
- All Known Implementing Classes:
ClassTypeInformation
public interface TypeInformation<S>
Interface to access property types and resolving generics on the way. Starting with a
ClassTypeInformation
you can traverse properties using getProperty(String)
to access type information.- Author:
- Oliver Gierke, Mark Paluch, Alessandro Nistico, Johannes Englmeier, Christoph Strobl
-
Field Summary
Modifier and TypeFieldDescriptionstatic final TypeInformation<Collection>
static final TypeInformation<List>
static final TypeInformation<Map>
static final TypeInformation<Object>
static final TypeInformation<Set>
-
Method Summary
Modifier and TypeMethodDescriptionstatic TypeInformation<?>
fromMethodParameter
(MethodParameter parameter) Returns a newTypeInformation
for the givenMethodParameter
.static TypeInformation<?>
fromReturnTypeOf
(Method method) Returns aTypeInformation
for the givenMethod
.static TypeInformation<?>
fromReturnTypeOf
(Method method, Class<?> type) Returns aTypeInformation
for the given method as declared on the given type.Transparently returns theMap
value type if the type is aMap
, returns the component type if the typeisCollectionLike()
or the simple type if none of this applies.Returns the component type forCollection
s or the key type forMap
s.Will return the type of the value in case the underlying type is aMap
.List<TypeInformation<?>>
getParameterTypes
(Constructor<?> constructor) Returns theTypeInformation
s for the parameters of the givenConstructor
.List<TypeInformation<?>>
getParameterTypes
(Method method) Returns theTypeInformation
s for the parameters of the givenMethod
.getProperty
(String property) Returns the property information for the property with the given name.Returns aTypeInformation
to represent theTypeInformation
of the raw type of the current instance.default TypeInformation<?>
Transparently returns theMap
value type if the type is aMap
, returns the component type if the typeisCollectionLike()
or the simple type if none of this applies.default TypeInformation<?>
Returns the component type forCollection
s, the key type forMap
s or the single generic type if available.default TypeInformation<?>
Will return the type of the value in case the underlying type is aMap
or throwIllegalStateException
if the map value type cannot be resolved.default TypeInformation<?>
getRequiredProperty
(String property) Returns the property information for the property with the given name or throwIllegalArgumentException
if the type information cannot be resolved.default TypeInformation<?>
getRequiredSuperTypeInformation
(Class<?> superType) Returns theTypeInformation
for the given raw super type.getReturnType
(Method method) Returns aTypeInformation
for the return type of the givenMethod
.getSuperTypeInformation
(Class<?> superType) Returns theTypeInformation
for the given raw super type.getType()
Returns the type of the property.List<TypeInformation<?>>
Returns theTypeInformation
for the type arguments of the currentTypeInformation
.default TypeInformation<?>
Returns the user type of the property if proxied.boolean
isAssignableFrom
(TypeInformation<?> target) Returns if the currentTypeInformation
can be safely assigned to the given one.boolean
Returns whether the type can be considered a collection, which means it's a container of elements, e.g. aCollection
andArray
or anything implementingIterable
.boolean
isMap()
Returns whether the property is aMap
.default boolean
isSubTypeOf
(Class<?> type) Returns whether the current type is a subtype of the given one, i.e. whether it's assignable but not the same one.static <S> TypeInformation<S>
Creates a newTypeInformation
for the givenClass
.static TypeInformation<?>
of
(ResolvableType type) Creates a newTypeInformation
from the givenResolvableType
.default TypeInformation<? extends S>
specialize
(TypeInformation<?> type) Specializes the given (raw)TypeInformation
using the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one.Returns theTypeDescriptor
equivalent of thisTypeInformation
.
-
Field Details
-
COLLECTION
-
LIST
-
SET
-
MAP
-
OBJECT
-
-
Method Details
-
of
Creates a newTypeInformation
from the givenResolvableType
.- Parameters:
type
- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
of
Creates a newTypeInformation
for the givenClass
.- Parameters:
type
- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
fromReturnTypeOf
Returns aTypeInformation
for the givenMethod
.- Parameters:
method
- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
fromReturnTypeOf
Returns aTypeInformation
for the given method as declared on the given type.- Parameters:
method
- must not be null.type
- can be null.- Returns:
- will never be null.
- Since:
- 3.0
-
fromMethodParameter
Returns a newTypeInformation
for the givenMethodParameter
.- Parameters:
parameter
- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
getParameterTypes
Returns theTypeInformation
s for the parameters of the givenConstructor
.- Parameters:
constructor
- must not be null.- Returns:
-
getProperty
Returns the property information for the property with the given name. Supports property traversal through dot notation.- Parameters:
property
-- Returns:
-
getRequiredProperty
Returns the property information for the property with the given name or throwIllegalArgumentException
if the type information cannot be resolved. Supports property traversal through dot notation.- Parameters:
property
-- Returns:
- Throws:
IllegalArgumentException
- if the type information cannot be resolved.- Since:
- 2.0
-
isCollectionLike
boolean isCollectionLike()Returns whether the type can be considered a collection, which means it's a container of elements, e.g. aCollection
andArray
or anything implementingIterable
. If this returns true you can expectgetComponentType()
to return a non-null value.- Returns:
-
getComponentType
Returns the component type forCollection
s or the key type forMap
s.- Returns:
-
getRequiredComponentType
Returns the component type forCollection
s, the key type forMap
s or the single generic type if available. ThrowsIllegalStateException
if the component value type cannot be resolved.- Returns:
- Throws:
IllegalStateException
- if the component type cannot be resolved, e.g. if a raw type is used or the type is not generic in the first place.- Since:
- 2.0
-
isMap
boolean isMap()Returns whether the property is aMap
. If this returns true you can expectgetComponentType()
as well asgetMapValueType()
to return something not null.- Returns:
-
getMapValueType
Will return the type of the value in case the underlying type is aMap
.- Returns:
-
getRequiredMapValueType
Will return the type of the value in case the underlying type is aMap
or throwIllegalStateException
if the map value type cannot be resolved.- Returns:
- Throws:
IllegalStateException
- if the map value type cannot be resolved, usually due to the currentMap
type being a raw one.- Since:
- 2.0
-
getType
Returns the type of the property. Will resolve generics and the generic context of- Returns:
-
getUserTypeInformation
Returns the user type of the property if proxied.- Returns:
- the unpacked (if proxied) type of the property.
- Since:
- 2.6
- See Also:
-
getRawTypeInformation
TypeInformation<?> getRawTypeInformation()Returns aTypeInformation
to represent theTypeInformation
of the raw type of the current instance.- Returns:
-
getActualType
Transparently returns theMap
value type if the type is aMap
, returns the component type if the typeisCollectionLike()
or the simple type if none of this applies.- Returns:
- the map value, collection component type or the current type, null it the current type is a raw
Map
orCollection
.
-
getRequiredActualType
Transparently returns theMap
value type if the type is aMap
, returns the component type if the typeisCollectionLike()
or the simple type if none of this applies.- Returns:
- Throws:
IllegalArgumentException
- if the current type is a rawMap
orCollection
and no value or component type is available.- Since:
- 2.0
-
getReturnType
Returns aTypeInformation
for the return type of the givenMethod
. Will potentially resolve generics information against the current types type parameter bindings.- Parameters:
method
- must not be null.- Returns:
-
getParameterTypes
Returns theTypeInformation
s for the parameters of the givenMethod
.- Parameters:
method
- must not be null.- Returns:
-
getSuperTypeInformation
Returns theTypeInformation
for the given raw super type.- Parameters:
superType
- must not be null.- Returns:
- the
TypeInformation
for the given raw super type or null in case the currentTypeInformation
does not implement the given type.
-
getRequiredSuperTypeInformation
Returns theTypeInformation
for the given raw super type.- Parameters:
superType
- must not be null.- Returns:
- the
TypeInformation
for the given raw super type. - Throws:
IllegalArgumentException
- in case the currentTypeInformation
does not implement the given type.- Since:
- 2.0
-
isAssignableFrom
Returns if the currentTypeInformation
can be safely assigned to the given one. Mimics semantics ofClass.isAssignableFrom(Class)
but takes generics into account. Thus it will allow to detect that aList<Long>
is assignable toList<? extends Number>
.- Parameters:
target
-- Returns:
-
getTypeArguments
List<TypeInformation<?>> getTypeArguments()Returns theTypeInformation
for the type arguments of the currentTypeInformation
.- Returns:
-
specialize
Specializes the given (raw)TypeInformation
using the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one. Will return the given type as is if no generics are involved.- Parameters:
type
- must not be null.- Returns:
- will never be null.
-
isSubTypeOf
Returns whether the current type is a subtype of the given one, i.e. whether it's assignable but not the same one.- Parameters:
type
- must not be null.- Returns:
- Since:
- 2.2
-
toTypeDescriptor
TypeDescriptor toTypeDescriptor()Returns theTypeDescriptor
equivalent of thisTypeInformation
.- Returns:
- will never be null.
- Since:
- 2.7
-