Interface PropertyPath

All Superinterfaces:
Iterable<PropertyPath>, Streamable<PropertyPath>, Supplier<Stream<PropertyPath>>
All Known Subinterfaces:
TypedPropertyPath<T,P>

public interface PropertyPath extends Streamable<PropertyPath>
Abstraction of a 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 Details

    • of

      static <T,P> TypedPropertyPath<T,P> of(PropertyReference<T,P> property)
      Syntax sugar to create a TypedPropertyPath from a method reference to a Java beans property.

      This method returns a resolved TypedPropertyPath by 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

      static <T,P> TypedPropertyPath<T,P> ofMany(PropertyReference<T, ? extends Iterable<P>> property)
      Syntax sugar to create a TypedPropertyPath from a method reference to a Java beans collection property.

      This method returns a resolved TypedPropertyPath by 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 the PropertyPath.
      Returns:
      the owningType will never be null.
    • getSegment

      String getSegment()
      Returns the current property path segment (i.e. first part of toDotPath()).

      For example:

      PropertyPath.from("address.city.name", Person.class).getSegment();
      
      results in address.
      Returns:
      the current property path segment.
    • getLeafProperty

      default PropertyPath getLeafProperty()
      Returns the leaf property of the PropertyPath. Either this property if the path ends here or the last property in the chain.
      Returns:
      leaf property.
    • getLeafType

      default Class<?> getLeafType()
      Returns the type of the leaf property of the current PropertyPath.
      Returns:
      will never be null.
      See Also:
    • getType

      default Class<?> getType()
      Returns the actual type of the property at this segment. Will return the plain resolved type for simple properties, the component type for any Iterable or the value type of Map properties.
      Returns:
      the actual type of the property.
      See Also:
    • 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 next PropertyPath segment in the property path chain.
      PropertyPath.from("address.city.name", Person.class).next().toDotPath();
      
      results in the output: city.name.
      Returns:
      the next PropertyPath or 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

      default String toDotPath()
      Returns the PropertyPath in dot notation.
      Returns:
      the PropertyPath in dot notation.
    • nested

      default PropertyPath nested(String path)
      Returns the PropertyPath for 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 an Iterator of PropertyPath that 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:
      iterator in interface Iterable<PropertyPath>
    • from

      static PropertyPath from(String source, Class<?> type)
      Extracts the PropertyPath chain from the given source String and TypeInformation.
      Uses (?:[%s]?([%s]*?[^%s]+)) by default and (?:[%s]?([%s]*?[^%s]+)) for quoted literals.

      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 for userAddressCity the interpretation userAddress.city is preferred over user.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 PropertyPath guaranteed to be not null.
    • from

      static PropertyPath from(String source, TypeInformation<?> type)
      Extracts the PropertyPath chain from the given source String and TypeInformation.
      Uses (?:[%s]?([%s]*?[^%s]+)) by default and (?:[%s]?([%s]*?[^%s]+)) for quoted literals.

      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 for userAddressCity the interpretation userAddress.city is preferred over user.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 PropertyPath guaranteed to be not null.