mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[commands] SelectCommand: Fix leakage and multiple composition bug (#5571)
This commit is contained in:
@@ -27,6 +27,9 @@ public class SelectCommand extends Command {
|
||||
private boolean m_runsWhenDisabled = true;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
private final Command m_defaultCommand =
|
||||
new PrintCommand("SelectCommand selector value does not correspond to any command!");
|
||||
|
||||
/**
|
||||
* Creates a new SelectCommand.
|
||||
*
|
||||
@@ -37,6 +40,7 @@ public class SelectCommand extends Command {
|
||||
m_commands = requireNonNullParam(commands, "commands", "SelectCommand");
|
||||
m_selector = requireNonNullParam(selector, "selector", "SelectCommand");
|
||||
|
||||
CommandScheduler.getInstance().registerComposedCommands(m_defaultCommand);
|
||||
CommandScheduler.getInstance()
|
||||
.registerComposedCommands(commands.values().toArray(new Command[] {}));
|
||||
|
||||
@@ -51,12 +55,7 @@ public class SelectCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (!m_commands.containsKey(m_selector.get())) {
|
||||
m_selectedCommand =
|
||||
new PrintCommand("SelectCommand selector value does not correspond to any command!");
|
||||
} else {
|
||||
m_selectedCommand = m_commands.get(m_selector.get());
|
||||
}
|
||||
m_selectedCommand = m_commands.getOrDefault(m_selector.get(), m_defaultCommand);
|
||||
m_selectedCommand.initialize();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user