RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
SequentialGroup.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.command3;
6
7import static org.wpilib.util.ErrorMessages.requireNonNullParam;
8
9import java.util.ArrayList;
10import java.util.HashSet;
11import java.util.List;
12import java.util.Set;
13
24public final class SequentialGroup implements Command {
25 private final String m_name;
26 private final List<Command> m_commands = new ArrayList<>();
27 private final Set<Mechanism> m_requirements = new HashSet<>();
28 private final int m_priority;
29
36 SequentialGroup(String name, List<Command> commands) {
37 requireNonNullParam(name, "name", "SequentialGroup");
38 requireNonNullParam(commands, "commands", "SequentialGroup");
39 for (int i = 0; i < commands.size(); i++) {
40 requireNonNullParam(commands.get(i), "commands[" + i + "]", "SequentialGroup");
41 }
42
43 m_name = name;
44 m_commands.addAll(commands);
45
46 for (var command : commands) {
47 m_requirements.addAll(command.requirements());
48 }
49
50 m_priority =
51 commands.stream().mapToInt(Command::priority).max().orElse(Command.DEFAULT_PRIORITY);
52 }
53
54 @Override
55 public void run(Coroutine coroutine) {
56 for (var command : m_commands) {
57 coroutine.await(command);
58 }
59 }
60
61 @Override
62 public String name() {
63 return m_name;
64 }
65
66 @Override
67 public Set<Mechanism> requirements() {
68 return m_requirements;
69 }
70
71 @Override
72 public int priority() {
73 return m_priority;
74 }
75
76 @Override
77 public String toString() {
78 return "SequentialGroup[name=" + m_name + "]";
79 }
80
81 // package-private for testing
82 List<Command> getCommands() {
83 return m_commands;
84 }
85}
ForkResult await(Command command)