mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[commands] Fix compose-while-scheduled issue and test all compositions (#5581)
This commit is contained in:
@@ -585,7 +585,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
*/
|
||||
public void registerComposedCommands(Command... commands) {
|
||||
var commandSet = Set.of(commands);
|
||||
requireNotComposed(commandSet);
|
||||
requireNotComposedOrScheduled(commandSet);
|
||||
var exception = new Exception("Originally composed at:");
|
||||
exception.fillInStackTrace();
|
||||
for (var command : commands) {
|
||||
@@ -617,7 +617,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires that the specified command hasn't been already added to a composition.
|
||||
* Requires that the specified command hasn't already been added to a composition.
|
||||
*
|
||||
* @param commands The commands to check
|
||||
* @throws IllegalArgumentException if the given commands have already been composed.
|
||||
@@ -635,7 +635,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires that the specified commands not have been already added to a composition.
|
||||
* Requires that the specified commands have not already been added to a composition.
|
||||
*
|
||||
* @param commands The commands to check
|
||||
* @throws IllegalArgumentException if the given commands have already been composed.
|
||||
@@ -644,6 +644,34 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
requireNotComposed(commands.toArray(Command[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires that the specified command hasn't already been added to a composition, and is not
|
||||
* currently scheduled.
|
||||
*
|
||||
* @param command The command to check
|
||||
* @throws IllegalArgumentException if the given command has already been composed or scheduled.
|
||||
*/
|
||||
public void requireNotComposedOrScheduled(Command command) {
|
||||
if (isScheduled(command)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Commands that have been scheduled individually may not be added to a composition!");
|
||||
}
|
||||
requireNotComposed(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires that the specified commands have not already been added to a composition, and are not
|
||||
* currently scheduled.
|
||||
*
|
||||
* @param commands The commands to check
|
||||
* @throws IllegalArgumentException if the given commands have already been composed or scheduled.
|
||||
*/
|
||||
public void requireNotComposedOrScheduled(Collection<Command> commands) {
|
||||
for (var command : commands) {
|
||||
requireNotComposedOrScheduled(command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given command has been composed.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user