Package com.vladsch.plugin.util
Class OneTimeConsumerRunnable<T>
- java.lang.Object
-
- com.vladsch.plugin.util.AwtValueRunnable<T>
-
- com.vladsch.plugin.util.OneTimeConsumerRunnable<T>
-
- All Implemented Interfaces:
Cancellable,CancellableConsumerRunnable<T>,java.util.function.Consumer<T>
public class OneTimeConsumerRunnable<T> extends AwtValueRunnable<T> implements CancellableConsumerRunnable<T>
Used to create a task that can be run at most once and the run can be cancelled before it has run, in which case further attempts to run it will do nothing.Can also specify that it should run on the AWT thread, otherwise it will run on the application thread
Useful for triggering actions after a delay that may need to be run before the delay triggers
-
-
Field Summary
-
Fields inherited from interface com.vladsch.plugin.util.CancellableConsumerRunnable
NULL
-
-
Constructor Summary
Constructors Constructor Description OneTimeConsumerRunnable(@NotNull java.lang.String id, boolean awtThread, java.util.function.Consumer<T> command)OneTimeConsumerRunnable(@NotNull java.lang.String id, @NotNull java.util.function.Consumer<T> command)OneTimeConsumerRunnable(@NotNull java.util.function.Consumer<T> command)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(T value)booleancancel()Cancels the scheduled task run if it has not run yetbooleancanRun()Tests whether it has run or been cancelled@NotNull java.lang.StringgetId()-
Methods inherited from class com.vladsch.plugin.util.AwtValueRunnable
getCommand, isAwtThread
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vladsch.plugin.util.CancellableConsumerRunnable
isNotNull, isNull
-
-
-
-
Constructor Detail
-
OneTimeConsumerRunnable
public OneTimeConsumerRunnable(@NotNull @NotNull java.util.function.Consumer<T> command)
-
OneTimeConsumerRunnable
public OneTimeConsumerRunnable(@NotNull @NotNull java.lang.String id, @NotNull @NotNull java.util.function.Consumer<T> command)
-
OneTimeConsumerRunnable
public OneTimeConsumerRunnable(@NotNull @NotNull java.lang.String id, boolean awtThread, java.util.function.Consumer<T> command)
-
-
Method Detail
-
cancel
public boolean cancel()
Cancels the scheduled task run if it has not run yet- Specified by:
cancelin interfaceCancellable- Specified by:
cancelin interfaceCancellableConsumerRunnable<T>- Returns:
- true if cancelled, false if it has already run
-
canRun
public boolean canRun()
Tests whether it has run or been cancelled- Specified by:
canRunin interfaceCancellable- Specified by:
canRunin interfaceCancellableConsumerRunnable<T>- Returns:
- true if cancelled, false if it has already run
-
accept
public void accept(T value)
- Specified by:
acceptin interfacejava.util.function.Consumer<T>- Overrides:
acceptin classAwtValueRunnable<T>
-
getId
@NotNull public @NotNull java.lang.String getId()
- Specified by:
getIdin interfaceCancellableConsumerRunnable<T>
-
-