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
FieldsModifier 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 newTypeInformationfor the givenMethodParameter.static TypeInformation<?>fromReturnTypeOf(Method method) Returns aTypeInformationfor the givenMethod.static TypeInformation<?>fromReturnTypeOf(Method method, Class<?> type) Returns aTypeInformationfor the given method as declared on the given type.Transparently returns theMapvalue 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 forCollections or the key type forMaps.Will return the type of the value in case the underlying type is aMap.List<TypeInformation<?>>getParameterTypes(Constructor<?> constructor) Returns theTypeInformations for the parameters of the givenConstructor.List<TypeInformation<?>>getParameterTypes(Method method) Returns theTypeInformations for the parameters of the givenMethod.getProperty(String property) Returns the property information for the property with the given name.Returns aTypeInformationto represent theTypeInformationof the raw type of the current instance.default TypeInformation<?>Transparently returns theMapvalue 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 forCollections, the key type forMaps or the single generic type if available.default TypeInformation<?>Will return the type of the value in case the underlying type is aMapor throwIllegalStateExceptionif the map value type cannot be resolved.default TypeInformation<?>getRequiredProperty(String property) Returns the property information for the property with the given name or throwIllegalArgumentExceptionif the type information cannot be resolved.default TypeInformation<?>getRequiredSuperTypeInformation(Class<?> superType) Returns theTypeInformationfor the given raw super type.getReturnType(Method method) Returns aTypeInformationfor the return type of the givenMethod.getSuperTypeInformation(Class<?> superType) Returns theTypeInformationfor the given raw super type.getType()Returns the type of the property.List<TypeInformation<?>>Returns theTypeInformationfor the type arguments of the currentTypeInformation.default TypeInformation<?>Returns the user type of the property if proxied.booleanisAssignableFrom(TypeInformation<?> target) Returns if the currentTypeInformationcan be safely assigned to the given one.booleanReturns whether the type can be considered a collection, which means it's a container of elements, e.g. aCollectionandArrayor anything implementingIterable.booleanisMap()Returns whether the property is aMap.default booleanisSubTypeOf(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 newTypeInformationfor the givenClass.static TypeInformation<?>of(ResolvableType type) Creates a newTypeInformationfrom the givenResolvableType.default TypeInformation<? extends S>specialize(TypeInformation<?> type) Specializes the given (raw)TypeInformationusing the context of the current potentially parameterized type, basically turning the given raw type into a parameterized one.Returns theTypeDescriptorequivalent of thisTypeInformation.
-
Field Details
-
COLLECTION
-
LIST
-
SET
-
MAP
-
OBJECT
-
-
Method Details
-
of
Creates a newTypeInformationfrom the givenResolvableType.- Parameters:
type- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
of
Creates a newTypeInformationfor the givenClass.- Parameters:
type- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
fromReturnTypeOf
Returns aTypeInformationfor the givenMethod.- Parameters:
method- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
fromReturnTypeOf
Returns aTypeInformationfor 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 newTypeInformationfor the givenMethodParameter.- Parameters:
parameter- must not be null.- Returns:
- will never be null.
- Since:
- 3.0
-
getParameterTypes
Returns theTypeInformations 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 throwIllegalArgumentExceptionif 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. aCollectionandArrayor anything implementingIterable. If this returns true you can expectgetComponentType()to return a non-null value.- Returns:
-
getComponentType
Returns the component type forCollections or the key type forMaps.- Returns:
-
getRequiredComponentType
Returns the component type forCollections, the key type forMaps or the single generic type if available. ThrowsIllegalStateExceptionif 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 aMapor throwIllegalStateExceptionif the map value type cannot be resolved.- Returns:
- Throws:
IllegalStateException- if the map value type cannot be resolved, usually due to the currentMaptype 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 aTypeInformationto represent theTypeInformationof the raw type of the current instance.- Returns:
-
getActualType
Transparently returns theMapvalue 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
MaporCollection.
-
getRequiredActualType
Transparently returns theMapvalue 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 rawMaporCollectionand no value or component type is available.- Since:
- 2.0
-
getReturnType
Returns aTypeInformationfor 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 theTypeInformations for the parameters of the givenMethod.- Parameters:
method- must not be null.- Returns:
-
getSuperTypeInformation
Returns theTypeInformationfor the given raw super type.- Parameters:
superType- must not be null.- Returns:
- the
TypeInformationfor the given raw super type or null in case the currentTypeInformationdoes not implement the given type.
-
getRequiredSuperTypeInformation
Returns theTypeInformationfor the given raw super type.- Parameters:
superType- must not be null.- Returns:
- the
TypeInformationfor the given raw super type. - Throws:
IllegalArgumentException- in case the currentTypeInformationdoes not implement the given type.- Since:
- 2.0
-
isAssignableFrom
Returns if the currentTypeInformationcan 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 theTypeInformationfor the type arguments of the currentTypeInformation.- Returns:
-
specialize
Specializes the given (raw)TypeInformationusing 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 theTypeDescriptorequivalent of thisTypeInformation.- Returns:
- will never be null.
- Since:
- 2.7
-