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 thePredicate
to match against when iterating.get()
Get the result of the iteration, returning aPromise
with the actual result matching the configured predicate.Get the result of the iteration, returning aPromise
with the actual result matching the configured predicate.orElseGetAsync
(Supplier<Promise<V, E>> defaultValue) Get the result of the iteration, returning aPromise
with the actual result matching the configured predicate.
-
Method Details
-
findFirst
Configure thePredicate
to match against when iterating. A match terminates the iteration.If no
predicate
is supplied then find matches on the firstnon-null
result 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 aPromise
with anoptional
result 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 aPromise
with the actual result matching the configured predicate. If no promise yielded a match then thedefaultValue
is 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 aPromise
with the actual result matching the configured predicate. If no promise yielded a match then the supplieddefaultValue
is used instead.- Parameters:
defaultValue
-Supplier
of 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 aPromise
with the actual result matching the configured predicate. If no promise yielded a match then the supplieddefaultValue
promise is used instead.- Parameters:
defaultValue
-Supplier
of 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
defaultValue
promise - See Also:
-