mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[commands] Make Java SelectCommand generic (#5849)
This allows users to use any type of map and selector without needing to explicitly match Map<Object, Command>
This commit is contained in:
@@ -141,8 +141,8 @@ class RobotDisabledCommandTest extends CommandTestBase {
|
||||
MockCommandHolder command4Holder = new MockCommandHolder(false);
|
||||
Command command4 = command4Holder.getMock();
|
||||
|
||||
Command runWhenDisabled = new SelectCommand(Map.of(1, command1, 2, command2), () -> 1);
|
||||
Command dontRunWhenDisabled = new SelectCommand(Map.of(1, command3, 2, command4), () -> 1);
|
||||
Command runWhenDisabled = new SelectCommand<>(Map.of(1, command1, 2, command2), () -> 1);
|
||||
Command dontRunWhenDisabled = new SelectCommand<>(Map.of(1, command3, 2, command4), () -> 1);
|
||||
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
scheduler.schedule(runWhenDisabled, dontRunWhenDisabled);
|
||||
|
||||
@@ -13,7 +13,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SelectCommandTest extends CommandTestBase implements MultiCompositionTestBase<SelectCommand> {
|
||||
class SelectCommandTest extends CommandTestBase
|
||||
implements MultiCompositionTestBase<SelectCommand<Integer>> {
|
||||
@Test
|
||||
void selectCommandTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
@@ -25,8 +26,8 @@ class SelectCommandTest extends CommandTestBase implements MultiCompositionTestB
|
||||
MockCommandHolder command3Holder = new MockCommandHolder(true);
|
||||
Command command3 = command3Holder.getMock();
|
||||
|
||||
SelectCommand selectCommand =
|
||||
new SelectCommand(
|
||||
SelectCommand<String> selectCommand =
|
||||
new SelectCommand<>(
|
||||
Map.ofEntries(
|
||||
Map.entry("one", command1),
|
||||
Map.entry("two", command2),
|
||||
@@ -61,8 +62,8 @@ class SelectCommandTest extends CommandTestBase implements MultiCompositionTestB
|
||||
MockCommandHolder command3Holder = new MockCommandHolder(true);
|
||||
Command command3 = command3Holder.getMock();
|
||||
|
||||
SelectCommand selectCommand =
|
||||
new SelectCommand(
|
||||
SelectCommand<String> selectCommand =
|
||||
new SelectCommand<>(
|
||||
Map.ofEntries(
|
||||
Map.entry("one", command1),
|
||||
Map.entry("two", command2),
|
||||
@@ -88,8 +89,8 @@ class SelectCommandTest extends CommandTestBase implements MultiCompositionTestB
|
||||
MockCommandHolder command3Holder = new MockCommandHolder(true, system3, system4);
|
||||
Command command3 = command3Holder.getMock();
|
||||
|
||||
SelectCommand selectCommand =
|
||||
new SelectCommand(
|
||||
SelectCommand<String> selectCommand =
|
||||
new SelectCommand<>(
|
||||
Map.ofEntries(
|
||||
Map.entry("one", command1),
|
||||
Map.entry("two", command2),
|
||||
@@ -108,11 +109,11 @@ class SelectCommandTest extends CommandTestBase implements MultiCompositionTestB
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectCommand compose(Command... members) {
|
||||
var map = new HashMap<Object, Command>();
|
||||
public SelectCommand<Integer> compose(Command... members) {
|
||||
var map = new HashMap<Integer, Command>();
|
||||
for (int i = 0; i < members.length; i++) {
|
||||
map.put(i, members[i]);
|
||||
}
|
||||
return new SelectCommand(map, () -> 0);
|
||||
return new SelectCommand<>(map, () -> 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user