mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Improve command decorator names (#1945)
This commit is contained in:
@@ -99,26 +99,10 @@ public interface Command {
|
||||
* @param condition the interrupt condition
|
||||
* @return the command with the interrupt condition added
|
||||
*/
|
||||
default Command interruptOn(BooleanSupplier condition) {
|
||||
default Command withInterrupt(BooleanSupplier condition) {
|
||||
return new ParallelRaceGroup(this, new WaitUntilCommand(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorates this command with a runnable to run after the command finishes.
|
||||
*
|
||||
* <p>Note: This decorator works by composing this command within a CommandGroup. The command
|
||||
* cannot be used independently after being decorated, or be re-decorated with a different
|
||||
* decorator, unless it is manually cleared from the list of grouped commands with
|
||||
* {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
|
||||
* further decorated without issue.
|
||||
*
|
||||
* @param toRun the Runnable to run
|
||||
* @return the decorated command
|
||||
*/
|
||||
default Command whenFinished(Runnable toRun) {
|
||||
return new SequentialCommandGroup(this, new InstantCommand(toRun));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorates this command with a runnable to run before this command starts.
|
||||
*
|
||||
@@ -135,6 +119,22 @@ public interface Command {
|
||||
return new SequentialCommandGroup(new InstantCommand(toRun), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorates this command with a runnable to run after the command finishes.
|
||||
*
|
||||
* <p>Note: This decorator works by composing this command within a CommandGroup. The command
|
||||
* cannot be used independently after being decorated, or be re-decorated with a different
|
||||
* decorator, unless it is manually cleared from the list of grouped commands with
|
||||
* {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be
|
||||
* further decorated without issue.
|
||||
*
|
||||
* @param toRun the Runnable to run
|
||||
* @return the decorated command
|
||||
*/
|
||||
default Command andThen(Runnable toRun) {
|
||||
return new SequentialCommandGroup(this, new InstantCommand(toRun));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorates this command with a set of commands to run after it in sequence. Often more
|
||||
* convenient/less-verbose than constructing a new {@link SequentialCommandGroup} explicitly.
|
||||
|
||||
@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.Notifier;
|
||||
/**
|
||||
* A command that starts a notifier to run the given runnable periodically in a separate thread.
|
||||
* Has no end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or
|
||||
* {@link Command#interruptOn(BooleanSupplier)} to give it one.
|
||||
* {@link Command#withInterrupt(BooleanSupplier)} to give it one.
|
||||
*
|
||||
* <p>WARNING: Do not use this class unless you are confident in your ability to make the executed
|
||||
* code thread-safe. If you do not know what "thread-safe" means, that is a good sign that
|
||||
|
||||
@@ -14,7 +14,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
|
||||
/**
|
||||
* A command that runs a Runnable continuously. Has no end condition as-is;
|
||||
* either subclass it or use {@link Command#withTimeout(double)} or
|
||||
* {@link Command#interruptOn(BooleanSupplier)} to give it one. If you only wish
|
||||
* {@link Command#withInterrupt(BooleanSupplier)} to give it one. If you only wish
|
||||
* to execute a Runnable once, use {@link InstantCommand}.
|
||||
*/
|
||||
public class RunCommand extends CommandBase {
|
||||
|
||||
@@ -15,7 +15,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
|
||||
* A command that runs a given runnable when it is initalized, and another runnable when it ends.
|
||||
* Useful for running and then stopping a motor, or extending and then retracting a solenoid.
|
||||
* Has no end condition as-is; either subclass it or use {@link Command#withTimeout(double)} or
|
||||
* {@link Command#interruptOn(BooleanSupplier)} to give it one.
|
||||
* {@link Command#withInterrupt(BooleanSupplier)} to give it one.
|
||||
*/
|
||||
public class StartEndCommand extends CommandBase {
|
||||
protected final Runnable m_onInit;
|
||||
|
||||
Reference in New Issue
Block a user