Package com.remondis.propertypath.api
Interface Get<I,O,E extends java.lang.Exception>
-
- Type Parameters:
I- The type to evaluate a property path on.O- The type of the property value.E- The exception type that may be thrown by the property path.
- All Known Subinterfaces:
GetAndApply<I,O,T,E>
- All Known Implementing Classes:
GetAndApplyImpl,GetImpl
public interface Get<I,O,E extends java.lang.Exception>This class represents a getter that can be evaluated on a real object instance of a matching type. The getter returns instances ofOptional. If the value of the evaluated property path is present, it can be accessed throughOptional.get(). If the property path does not have a value, an emptyOptionalis returned.A property path is a chain of get-calls. If a getter returns
nullthe property path does not have a value. The same is true for lists and maps that are eithernullor do not contain a specified index or key. The null-checks are performed by the library an must not be implemented in the property path.Important information
Once the builder creates a
Getinstance, this instance can and should be reused. This library creates proxy classes which is a time consuming operation that is only neccessary once. So cache theGetinstance as long as possible.Implementation hints
The implementation is expected to provide a validObject.equals(Object)method. Two getters are considered equal if their types, property paths and the respective argument values are equal. The optional transform function cannot be compared, so this must be excluded from the equals/hashCode computation.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <X> GetAndApply<I,O,X,E>andApply(java.util.function.Function<O,X> mapping)Specifies a mapping function that is applied if the getter returned a non-null value.java.util.Optional<O>from(I object)Evaluates the property path on the specified object.OfromOrDefault(I object, O defaultValue)Evaluates the property path on the specified object.java.lang.StringtoPath()java.lang.StringtoString(boolean detailed)
-
-
-
Method Detail
-
from
java.util.Optional<O> from(I object) throws E extends java.lang.Exception
Evaluates the property path on the specified object.
-
fromOrDefault
O fromOrDefault(I object, O defaultValue) throws E extends java.lang.Exception
Evaluates the property path on the specified object. If a value is present it will be returned, otherwise the specified default value is returned.- Parameters:
object- The object to evaluate the property path on.defaultValue- The default value to return in case the property path does not have a value.- Returns:
- If a value is present it will be returned, otherwise the specified default value is returned.
- Throws:
E- May be thrown by the property path.E extends java.lang.Exception
-
andApply
<X> GetAndApply<I,O,X,E> andApply(java.util.function.Function<O,X> mapping)
Specifies a mapping function that is applied if the getter returned a non-null value. The mapping function can be used for calculations or type conversions.- Type Parameters:
X- The new return type of the getter after applying the mapping function.- Parameters:
mapping- The mapping function - only applied if the getter has a non-null return value.- Returns:
- Returns a new object for further configuration.
-
toString
java.lang.String toString(boolean detailed)
- Returns:
- Returns a detailed string if specified, otherwise a shorter string is returned.
-
toPath
java.lang.String toPath()
- Returns:
- Returns a JSON-like property path. Example: a.b.cs[0].d
-
-