Package org.springframework.data.util
Interface TypeInformation<S>
- All Known Implementing Classes:
ClassTypeInformation
,ParentTypeAwareTypeInformation
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
-
Method Summary
Modifier and TypeMethodDescriptionTransparently 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 aClassTypeInformation
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 sub type of the given one, i.e. whether it's assignable but not the same one.TypeInformation<? extends S>
specialize
(ClassTypeInformation<?> type) Specializes the given (raw)ClassTypeInformation
using the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one.
-
Method Details
-
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
ClassTypeInformation<?> getRawTypeInformation()Returns aClassTypeInformation
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)ClassTypeInformation
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 sub type 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
-