Class PropertyPath<P>
- java.lang.Object
-
- org.joda.beans.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 anIterable. The suffix[<mapKey>]accesses the specified numeric index of anMap.- Since:
- 2.11.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Optional<P>get(Bean bean)Gets a value by path from the specified bean.inthashCode()static <P> PropertyPath<P>of(String propertyPath, Class<P> resultType)Obtains an instance from the path.StringpropertyPath()Gets the property path.Class<P>resultType()Gets the result type.StringtoString()
-
-
-
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 nullresultType- 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,MapandOptional. 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
-
-