Class PropertyPath<P>

  • Type Parameters:
    P - the type of the result

    public final class PropertyPath<P>
    extends Object
    A multi-stage property path.

    This accepts a dot-separated path and queries the bean. Each dot-separated part of the path is resolved to a meta-property. Thus the path "foo.bar.baz" is equivalent to bean.getFoo().getBar().getBaz(). The path lookup works even if the methods are not public.

    Each part of the path may contain a suffix, such as [<iterableIndex>] or [<mapKey>]. The suffix [<iterableIndex>] accesses the specified numeric index of an Iterable. The suffix [<mapKey>] accesses the specified numeric index of an Map.

    Since:
    2.11.0
    • Method Detail

      • of

        public static <P> PropertyPath<P> of​(String propertyPath,
                                             Class<P> resultType)
        Obtains an instance from the path.
        Type Parameters:
        P - the type of the result
        Parameters:
        propertyPath - the path, not null
        resultType - the result type, not null
        Returns:
        the path
        Throws:
        IllegalArgumentException - if the path has an invalid format
      • get

        public Optional<P> get​(Bean bean)
        Gets a value by path from the specified bean.

        This uses the path to query the bean. There is special handling for Iterable, Map and Optional. If the path does not match the structure within the bean, optional empty is returned. If the path finds any nulls, empty lists or empty maps, optional empty is returned.

        Parameters:
        bean - the bean to start from, not null
        Returns:
        the value, empty if the value is null or the path fails to evaluate correctly
      • propertyPath

        public String propertyPath()
        Gets the property path.
        Returns:
        the property path
      • resultType

        public Class<P> resultType()
        Gets the result type.
        Returns:
        the result type
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object