Interface PropertyPath
- All Superinterfaces:
Iterable<PropertyPath>, Streamable<PropertyPath>, Supplier<Stream<PropertyPath>>
- All Known Subinterfaces:
TypedPropertyPath<T,P>
PropertyPath within a domain class.
Property paths allow to navigate nested properties such as address.city.name and provide metadata for each
segment of the path. Paths are represented in dot-path notation and are resolved from an owning type, for example:
PropertyPath.from("address.city.name", Person.class);
Paths are cached on a best-effort basis using a weak reference cache to avoid repeated introspection if GC pressure
permits.
A typed variant of PropertyPath is available as TypedPropertyPath through
of(PropertyReference) to leverage method references for a type-safe usage across application code.
- Author:
- Oliver Gierke, Christoph Strobl, Mark Paluch, Mariusz MÄ…czkowski, Johannes Englmeier
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic PropertyPathstatic PropertyPathfrom(String source, TypeInformation<?> type) default PropertyPathReturns the leaf property of thePropertyPath.default Class<?> Returns the type of the leaf property of the currentPropertyPath.Returns the owning type of thePropertyPath.Returns the current property path segment (i.e. first part oftoDotPath()).default Class<?> getType()Returns the actual type of the property at this segment.Returns the type information for the property at this segment.default booleanhasNext()Returns true if the property path contains further segments or false if the path ends at this segment.default booleanReturns whether the current property path segment is a collection.iterator()Returns anIterator of PropertyPaththat iterates over all property path segments.default PropertyPathReturns thePropertyPathfor the path nested under the current property.@Nullable PropertyPathnext()Returns the nextPropertyPathsegment in the property path chain.static <T,P> TypedPropertyPath <T, P> of(PropertyReference<T, P> property) Syntax sugar to create aTypedPropertyPathfrom a method reference to a Java beans property.static <T,P> TypedPropertyPath <T, P> ofMany(PropertyReference<T, ? extends Iterable<P>> property) Syntax sugar to create aTypedPropertyPathfrom a method reference to a Java beans collection property.default StringReturns thePropertyPathin dot notation.Methods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
of
Syntax sugar to create aTypedPropertyPathfrom a method reference to a Java beans property.This method returns a resolved
TypedPropertyPathby introspecting the given method reference.- Type Parameters:
T- owning type.P- property type.- Parameters:
property- the method reference referring to a Java beans property.- Returns:
- the typed property path.
- Since:
- 4.1
-
ofMany
Syntax sugar to create aTypedPropertyPathfrom a method reference to a Java beans collection property.This method returns a resolved
TypedPropertyPathby introspecting the given method reference.- Type Parameters:
T- owning type.P- property type.- Parameters:
property- the method reference referring to a property.- Returns:
- the typed property path.
- Since:
- 4.1
-
getOwningType
TypeInformation<?> getOwningType()Returns the owning type of thePropertyPath.- Returns:
- the owningType will never be null.
-
getSegment
String getSegment()Returns the current property path segment (i.e. first part oftoDotPath()).For example:
PropertyPath.from("address.city.name", Person.class).getSegment();results inaddress.- Returns:
- the current property path segment.
-
getLeafProperty
Returns the leaf property of thePropertyPath. Either this property if the path ends here or the last property in the chain.- Returns:
- leaf property.
-
getLeafType
Returns the type of the leaf property of the currentPropertyPath.- Returns:
- will never be null.
- See Also:
-
getType
-
getTypeInformation
TypeInformation<?> getTypeInformation()Returns the type information for the property at this segment.- Returns:
- the type information for the property at this segment.
-
isCollection
default boolean isCollection()Returns whether the current property path segment is a collection.- Returns:
- true if the current property path segment is a collection.
- See Also:
-
next
@Nullable PropertyPath next()Returns the nextPropertyPathsegment in the property path chain.PropertyPath.from("address.city.name", Person.class).next().toDotPath();results in the output:city.name.- Returns:
- the next
PropertyPathor null if the path does not contain further segments. - See Also:
-
hasNext
default boolean hasNext()Returns true if the property path contains further segments or false if the path ends at this segment.- Returns:
- true if the property path contains further segments or false if the path ends at this segment.
-
toDotPath
Returns thePropertyPathin dot notation.- Returns:
- the
PropertyPathin dot notation.
-
nested
Returns thePropertyPathfor the path nested under the current property.- Parameters:
path- must not be null or empty.- Returns:
- will never be null.
-
iterator
Iterator<PropertyPath> iterator()Returns anIterator of PropertyPaththat iterates over all property path segments. For example:PropertyPath path = PropertyPath.from("address.city.name", Person.class); path.forEach(p -> p.toDotPath());results in the dot paths:address.city.name (this object) city.name (next() object) name (next().next() object)
- Specified by:
iteratorin interfaceIterable<PropertyPath>
-
from
Extracts thePropertyPathchain from the given sourceStringandTypeInformation.
Uses(?:[%s]?([%s]*?[^%s]+))by default and(?:[%s]?([%s]*?[^%s]+))forquotedliterals.Separate parts of the path may be separated by
"."or by"_"or by camel case. When the match to properties is ambiguous longer property names are preferred. So foruserAddressCitythe interpretationuserAddress.cityis preferred overuser.address.city.- Parameters:
source- a String denoting the property path, must not be null.type- the owning type of the property path, must not be null.- Returns:
- a new
PropertyPathguaranteed to be not null.
-
from
Extracts thePropertyPathchain from the given sourceStringandTypeInformation.
Uses(?:[%s]?([%s]*?[^%s]+))by default and(?:[%s]?([%s]*?[^%s]+))forquotedliterals.Separate parts of the path may be separated by
"."or by"_"or by camel case. When the match to properties is ambiguous longer property names are preferred. So foruserAddressCitythe interpretationuserAddress.cityis preferred overuser.address.city.- Parameters:
source- a String denoting the property path, must not be null.type- the owning type of the property path, must not be null.- Returns:
- a new
PropertyPathguaranteed to be not null.
-