T - the type of the values that the consumer can acceptpublic class SingleUseConsumer<T> extends java.lang.Object implements Consumer<T>
Consumer implementation that allows the delegate Consumer to only be called once. Should be used in
combination with Registration.cancelAfterUse() to ensure that this Consumer's Registration is cancelled as soon after its use as possible.| Constructor and Description |
|---|
SingleUseConsumer()
Used to create anonymous subclasses.
|
SingleUseConsumer(Consumer<T> delegate)
Create a single-use
Consumer using the given delgate. |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(T t)
Execute the logic of the action, accepting the given parameter.
|
protected void |
doAccept(T t) |
static <T> Consumer<T> |
once(Consumer<T> delegate)
Static helper method for creating
SingleUseConsumer SingleUseConsumers in code with a little less noise. |
public SingleUseConsumer()
public static <T> Consumer<T> once(Consumer<T> delegate)
SingleUseConsumer SingleUseConsumers in code with a little less noise.T - Type of the Consumer's argument.delegate - The delegate Consumer to invoke.Consumer that will only be invoked once, then cancelled.public final void accept(T t)
Consumerprotected void doAccept(T t)