Class MultiSelect<T>
- java.lang.Object
-
- io.smallrye.mutiny.groups.MultiSelect<T>
-
-
Constructor Summary
Constructors Constructor Description MultiSelect(Multi<T> upstream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Multi<T>
distinct()
Selects all the distinct items from the upstream.Multi<T>
distinct(java.util.Comparator<? super T> comparator)
Selects all the distinct items from the upstream.Multi<T>
first()
Select the first item from theMulti
.Multi<T>
first(long n)
Selects the firstn
items from theMulti
.Multi<T>
first(java.time.Duration duration)
Selects the first items for the given duration.Multi<T>
first(java.util.function.Predicate<? super T> predicate)
Selects the first items while the given predicate returnstrue
.Multi<T>
last()
Select the last item from theMulti
.Multi<T>
last(int n)
Selects the lastn
items from theMulti
.Multi<T>
when(java.util.function.Function<? super T,Uni<java.lang.Boolean>> predicate)
Selects the items where the given function produced aUni
emittingtrue
.Multi<T>
where(java.util.function.Predicate<? super T> predicate)
Selects the items where the given predicate returnstrue
.Multi<T>
where(java.util.function.Predicate<? super T> predicate, int limit)
Likewhen(Function)
, but select at mostlimit
items.
-
-
-
Method Detail
-
first
public Multi<T> first()
Select the first item from theMulti
.If the upstream
Multi
contains more than one item, the others are dropped. If the upstream emits a failure before emitting an item, the producedMulti
emits the same failure. If the upstream completes without emitting an item first, the producedMulti
is empty.- Returns:
- the resulting
Multi
-
last
public Multi<T> last()
Select the last item from theMulti
.If the upstream
Multi
contains more than one item, the others are dropped, only the last one is emitted by the producedMulti
. If the upstream emits a failure, the producedMulti
emits the same failure. If the upstream completes without emitting an item first, the producedMulti
is empty.- Returns:
- the resulting
Multi
-
first
public Multi<T> first(long n)
Selects the firstn
items from theMulti
.If the upstream
Multi
contains more than n items, the others are dropped. If the upstreamMulti
emits less than n items, all the items are emitted by the producedMulti
. If the upstream emits a failure before emitting n items, the producedMulti
emits the same failure after having emitted the first items. If the upstream completes without emitting an item first, the producedMulti
is empty.
-
last
public Multi<T> last(int n)
Selects the lastn
items from theMulti
.If the upstream
Multi
contains more than n items, the others are dropped. If the upstreamMulti
emits less than n items, all the items are emitted by the producedMulti
. If the upstream emits a failure, the producedMulti
emits the same failure after. No items will be emitted by the producedMulti
. If the upstream completes without emitting an item first, the producedMulti
is empty.
-
first
public Multi<T> first(java.util.function.Predicate<? super T> predicate)
Selects the first items while the given predicate returnstrue
. It calls the predicates for each items, until the predicate returnsfalse
. Each item for which the predicates returnedtrue
is emitted by the producedMulti
. As soon as the predicate returnsfalse
for an item, it stops emitting the item and sends the completion event. The last checked item is not emitted.If the upstream
Multi
is empty, the producedMulti
is empty. If the upstreamMulti
is emitting a failure, while the predicate has not returnedfalse
yet, the failure is emitted by the producedMulti
. If the predicates throws an exception while testing an item, the producedMulti
emits that exception as failure. No more items will be tested or emitted. If the predicates returnstrue
for each items from upstream, all the items are selected. Once the predicate returnsfalse
, it cancels the subscription to the upstream, and completes the producedMulti
.- Parameters:
predicate
- the predicate to test the items, must not benull
- Returns:
- the resulting
Multi
-
first
public Multi<T> first(java.time.Duration duration)
Selects the first items for the given duration. It selects each items emitted after the subscription for the given duration.If the upstream
Multi
is empty, the producedMulti
is empty. If the upstreamMulti
is emitting a failure, before the duration expires, the failure is emitted by the producedMulti
. If the upstream completes before the given duration, all the items are selected.Once the duration expires, it cancels the subscription to the upstream, and completes the produced
Multi
.- Parameters:
duration
- the duration, must not benull
, must be strictly positive.- Returns:
- the resulting
Multi
-
where
public Multi<T> where(java.util.function.Predicate<? super T> predicate)
Selects the items where the given predicate returnstrue
. It calls the predicates for each items. Each item for which the predicates returnedtrue
is emitted by the producedMulti
. Others are dropped.If the upstream
Multi
is empty, the producedMulti
is empty. If the upstreamMulti
is emitting a failure, the failure is emitted by the producedMulti
. If the predicates throws an exception while testing an item, the producedMulti
emits that exception as failure. No more items will be tested or emitted. If the predicates returnstrue
for each items from upstream, all the items are selected. The producedMulti
completes when the upstream completes.- Parameters:
predicate
- the predicate to test the items, must not benull
- Returns:
- the resulting
Multi
- See Also:
when(Function)
-
where
public Multi<T> where(java.util.function.Predicate<? super T> predicate, int limit)
Likewhen(Function)
, but select at mostlimit
items.- Parameters:
predicate
- the predicate to test the items, must not benull
limit
- the maximum number of item to select, must be positive. 0 would produce an emptyMulti
- Returns:
- the resulting
Multi
- See Also:
when(Function)
-
when
public Multi<T> when(java.util.function.Function<? super T,Uni<java.lang.Boolean>> predicate)
Selects the items where the given function produced aUni
emittingtrue
. This method is the asynchronous version ofwhere(Predicate)
. Instead of a synchronous predicate, it accepts a function producingUni
. It calls the function for every item, and depending of the producedUni
, it emits the item downstream or drops it. If the returnedUni
producestrue
, the item is selected and emitted by the producedMulti
, otherwise the item is dropped. The item is only emitted whenUni
produced for that item emitstrue
.If the upstream
Multi
is empty, the producedMulti
is empty. If the upstreamMulti
is emitting a failure, the failure is emitted by the producedMulti
. If the function throws an exception while testing an item, the producedMulti
emits that exception as failure. No more items will be tested or emitted. If the function produced anull
Uni, the producedMulti
emits anNullPointerException
as failure. No more items will be tested or emitted. If the function produced a failing Uni, the producedMulti
emits that failure. No more items will be tested or emitted. If the function produced aUni
emittingnull
, the producedMulti
emits a failure. No more items will be tested or emitted. If the function accepts all the items from the upstream, all the items are selected. The producedMulti
completes when the upstream completes.This method preserves the item orders.
- Parameters:
predicate
- the function to test the items, must not benull
, must not producednull
- Returns:
- the resulting
Multi
-
distinct
public Multi<T> distinct()
Selects all the distinct items from the upstream. This methods usesObject.hashCode()
to compare items.Do NOT call this method on unbounded upstream, as it would lead to an
OutOfMemoryError
.If the comparison throws an exception, the produced
Multi
fails. The producedMulti
completes when the upstream sends the completion event.- Returns:
- the resulting
Multi
. - See Also:
MultiSkip.repetitions()
,distinct(Comparator)
-
distinct
public Multi<T> distinct(java.util.Comparator<? super T> comparator)
Selects all the distinct items from the upstream. This methods uses the given comparator to compare the items.Do NOT call this method on unbounded upstream, as it would lead to an
OutOfMemoryError
.If the comparison throws an exception, the produced
Multi
fails. The producedMulti
completes when the upstream sends the completion event.Unlike
distinct()
which uses aHashSet
internally, this variant uses aTreeSet
initialized with the given comparator. If the comparator isnull
, it uses aHashSet
as backend.- Parameters:
comparator
- the comparator used to compare items. Ifnull
, it will uses the item'shashCode
method.- Returns:
- the resulting
Multi
. - See Also:
MultiSkip.repetitions()
-
-