Class Promises.IterateOverBuilder<V,E extends Exception>
- Type Parameters:
V- The expected result valueE- Exception that may occur - considerNeverThrowsException
- Enclosing class:
- Promises
IterateOverBuilder provides a mechanism for iterating over a stream or
iterable of promise suppliers in search of the first to match the supplied
predicate. If no predicate is supplied then find matches on the first
non-null result by default.
The supplied promises may not yet be resolved. If a promise yields a result that does not satisfy the
predicate then the next is tried in sequence. Once a satisfying result is found, remaining promises in
the stream are ignored (will not be resolved by this process, as they will not be requested from their
supplier).
The resulting Promise refers to an Optional containing the result of the first of the supplied
promises to complete with a result satisfying the predicate. The promise's Optional
will be empty if none completed with a satisfactory result.
By default, the promise will be completed with the first failure to occur (in the sequence). The iteration can
be configured to continue on failure, in which case subsequent promises will be tried
to obtain a value. Should a value still not be found then the resulting promise will complete with the original
failure (first failure).
-
Method Summary
Modifier and TypeMethodDescriptionConfigure whether the iteration should fail immediately on any failure, or should proceed to try the next element in sequence.Configure thePredicateto match against when iterating.get()Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate.Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate.orElseGetAsync(Supplier<Promise<V, E>> defaultValue) Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate.
-
Method Details
-
findFirst
Configure thePredicateto match against when iterating. A match terminates the iteration.If no
predicateis supplied then find matches on the firstnon-nullresult by default.- Parameters:
predicate- The predicate- Returns:
- This instance
-
continueOnFailure
Configure whether the iteration should fail immediately on any failure, or should proceed to try the next element in sequence. This provides the opportunity to source a value later in the sequence. If no value is sourced following a failure then the promise will complete with the original failure.- Returns:
- This instance
-
get
Get the result of the iteration, returning aPromisewith anoptionalresult matching the configured predicate. If no promise yielded a match then the result is anempty Optional.- Returns:
- A promise of an optional result that matches the predicate, or empty
- See Also:
-
orElse
Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate. If no promise yielded a match then thedefaultValueis used instead.- Parameters:
defaultValue- The value to use should no promise yield a result- Returns:
- A promise of a result that matches the predicate, or the
defaultValue - See Also:
-
orElseGet
Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate. If no promise yielded a match then the supplieddefaultValueis used instead.- Parameters:
defaultValue-Supplierof the value to use should no promise yield a result- Returns:
- A promise of a result that matches the predicate, or the supplied
defaultValue - See Also:
-
orElseGetAsync
Get the result of the iteration, returning aPromisewith the actual result matching the configured predicate. If no promise yielded a match then the supplieddefaultValuepromise is used instead.- Parameters:
defaultValue-Supplierof a promise of the value to use should no promise yield a result- Returns:
- A promise of a result that matches the predicate, or the supplied
defaultValuepromise - See Also:
-