Package com.google.mu.util
Class Funnel<T>
java.lang.Object
com.google.mu.util.Funnel<T>
- Type Parameters:
T
- the output type
Deprecated.
too niche
A funnel that dispatches a sequence of inputs through arbitrary batch conversions while
maintaining first-in-first-out order. For example, the following code can either batch load users
from a user store, or batch load from third party user store, or else create a dummy user
immediately without conversion:
Funnel<User> funnel = new Funnel<>();
Funnel.Batch<Long, User> userStoreBatch = funnel.through(userStore::loadUsers);
Funnel.Batch<ThirdPartyUser, User> thirdPartyBatch = funnel.through(thirdPartyClient::loadUsers);
for (UserDto dto : users) {
if (dto.hasUserId()) {
userStoreBatch.accept(dto.getUserId());
} else if (dto.hasThirdParty()) {
thirdPartyBatch.accept(dto.getThirdParty());
} else {
funnel.add(createDummyUser(dto));
}
}
List<User> users = funnel.run();
Elements flow out of the funnel in the same order as they enter, regardless of which
Funnel.Batch
converted them, or if they were directly added
into the funnel without
conversion.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.Addselement
to the funnel.run()
Deprecated.Runs all batch conversions and returns conversion results together with elementsadded
as is, in encounter order.<F> Funnel.Batch
<F, T> through
(Function<? super List<F>, ? extends Collection<? extends T>> converter) Deprecated.Returns aFunnel.Batch
accepting elements that, whenrun()
is called, will be converted together in a batch throughconverter
.
-
Constructor Details
-
Funnel
public Funnel()Deprecated.
-
-
Method Details
-
through
public <F> Funnel.Batch<F,T> through(Function<? super List<F>, ? extends Collection<? extends T>> converter) Deprecated.Returns aFunnel.Batch
accepting elements that, whenrun()
is called, will be converted together in a batch throughconverter
. -
add
Deprecated.Addselement
to the funnel. -
run
Deprecated.Runs all batch conversions and returns conversion results together with elementsadded
as is, in encounter order.
-