-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupLoggingCommand.java
More file actions
69 lines (58 loc) · 2.24 KB
/
GroupLoggingCommand.java
File metadata and controls
69 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package frc.robot.utils.logging;
import edu.wpi.first.wpilibj2.command.Command;
import java.util.ArrayList;
import java.util.List;
/**
* Base class for logged grouped commands (parallel, race, sequential...)
*/
public abstract class GroupLoggingCommand extends LoggingCommand {
// A copy of the children (since we can't access them from the regular groups)
private final List<LoggingCommand> childLoggingCommands;
/**
* Constructor for logged group command.
*
* @param namePrefix the prefix for the name (comes in front of hte group name)
* @param underlying the group command that is wrapped by this command
*/
public GroupLoggingCommand(String namePrefix, String commandName, Command underlying) {
super(namePrefix, commandName, underlying);
childLoggingCommands = new ArrayList<>();
}
/**
* A special constructor to allow for the creation of the command when we can't create the underlying up front.
* It is assumed that the {@link #setUnderlying(Command)} method is called immediately following the construction.
*/
protected GroupLoggingCommand(String namePrefix, String commandName) {
super(namePrefix, commandName);
childLoggingCommands = new ArrayList<>();
}
public final void addLoggingCommands(List<LoggingCommand> commands) {
childLoggingCommands.addAll(commands);
}
@Override
public void setName(String name) {
// Do not change the logging name for this command (it is fixed)
getUnderlying().setName(name);
}
@Override
public void appendNamePrefix(String prefix) {
// Change the name for this command
super.appendNamePrefix(prefix);
// Change the name for the children
appendChildrenPrefix(prefix);
}
@Override
public String toString() {
return getFullyQualifiedName();
}
// For testing
public List<LoggingCommand> getChildLoggingCommands() {
return childLoggingCommands;
}
private void appendChildrenPrefix(String prefix) {
// Recursively change the prefix for all child commands
for (LoggingCommand loggingCommand : childLoggingCommands) {
loggingCommand.appendNamePrefix(prefix);
}
}
}