Class PropertyPath

java.lang.Object
org.springframework.data.mapping.PropertyPath
All Implemented Interfaces:
Iterable<PropertyPath>, Supplier<Stream<PropertyPath>>, Streamable<PropertyPath>

public class PropertyPath extends Object implements Streamable<PropertyPath>
Abstraction of a PropertyPath of a domain class.
Author:
Oliver Gierke, Christoph Strobl, Mark Paluch, Mariusz MÄ…czkowski, Johannes Englmeier
  • Method Details

    • getOwningType

      public TypeInformation<?> getOwningType()
      Returns the owning type of the PropertyPath.
      Returns:
      the owningType will never be null.
    • getSegment

      public String getSegment()
      Returns the first part of the PropertyPath. For example:
       PropertyPath.from("a.b.c", Some.class).getSegment();
       
      results in a.
      Returns:
      the name will never be null.
    • getLeafProperty

      public PropertyPath getLeafProperty()
      Returns the leaf property of the PropertyPath.
      Returns:
      will never be null.
    • getLeafType

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

      public Class<?> getType()
      Returns the actual type of the property. Will return the plain resolved type for simple properties, the component type for any Iterable or the value type of a Map.
      Returns:
      the actual type of the property.
    • getTypeInformation

      public TypeInformation<?> getTypeInformation()
    • next

      @Nullable public PropertyPath next()
      Returns the PropertyPath path that results from removing the first element of the current one. For example:
       PropertyPath.from("a.b.c", Some.class).next().toDotPath();
       
      results in the output: b.c
      Returns:
      the next nested PropertyPath or null if no nested PropertyPath available.
      See Also:
    • hasNext

      public boolean hasNext()
      Returns whether there is a nested PropertyPath. If this returns true you can expect next() to return a non- null value.
      Returns:
    • toDotPath

      public String toDotPath()
      Returns the PropertyPath in dot notation.
      Returns:
      the PropertyPath in dot notation.
    • isCollection

      public boolean isCollection()
      Returns whether the PropertyPath is actually a collection.
      Returns:
      true whether the PropertyPath is actually a collection.
    • nested

      public 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

      public Iterator<PropertyPath> iterator()
      Returns an Iterator<PropertyPath> that iterates over all the partial property paths with the same leaf type but decreasing length. For example:
       PropertyPath propertyPath = PropertyPath.from("a.b.c", Some.class);
       propertyPath.forEach(p -> p.toDotPath());
       
      results in the dot paths: *
       a.b.c
       b.c
       c
       
      Specified by:
      iterator in interface Iterable<PropertyPath>
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • from

      public static PropertyPath from(String source, Class<?> type)
      Extracts the PropertyPath chain from the given source String and TypeInformation.
      Uses SPLITTER by default and SPLITTER_FOR_QUOTED 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

      public static PropertyPath from(String source, TypeInformation<?> type)
      Extracts the PropertyPath chain from the given source String and TypeInformation.
      Uses SPLITTER by default and SPLITTER_FOR_QUOTED 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object