RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
SequentialGroupBuilder.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
5
package
org.wpilib.command3;
6
7
import
static
org.wpilib.util.ErrorMessages.requireNonNullParam;
8
9
import
java.util.ArrayList;
10
import
java.util.Arrays;
11
import
java.util.List;
12
import
java.util.function.BooleanSupplier;
13
import
java.util.stream.Collectors;
14
import
org.wpilib.annotation.NoDiscard;
15
22
@
NoDiscard
23
public
class
SequentialGroupBuilder
{
24
private
final
List<Command> m_steps =
new
ArrayList<>();
25
private
BooleanSupplier m_endCondition;
26
31
public
SequentialGroupBuilder
() {}
32
39
public
SequentialGroupBuilder
andThen
(
Command
next) {
40
requireNonNullParam(next,
"next"
,
"SequentialGroupBuilder.andThen"
);
41
42
m_steps.add(next);
43
return
this
;
44
}
45
53
public
SequentialGroupBuilder
andThen
(
Command
... nextCommands) {
54
requireNonNullParam(nextCommands,
"nextCommands"
,
"SequentialGroupBuilder.andThen"
);
55
for
(
int
i = 0; i < nextCommands.length; i++) {
56
requireNonNullParam(
57
nextCommands[i],
"nextCommands["
+ i +
"]"
,
"SequentialGroupBuilder.andThen"
);
58
}
59
60
m_steps.addAll(Arrays.asList(nextCommands));
61
return
this
;
62
}
63
73
public
SequentialGroupBuilder
until
(BooleanSupplier endCondition) {
74
m_endCondition = endCondition;
75
return
this
;
76
}
77
84
public
Command
named
(String name) {
85
return
named
(name,
false
);
86
}
87
88
private
Command
named
(String name,
boolean
useAutomaticName) {
89
var seq =
new
SequentialGroup
(name, m_steps);
90
if
(m_endCondition ==
null
) {
91
// No custom end condition, return the group as is
92
return
seq;
93
}
94
95
var out =
96
new
ParallelGroupBuilder
()
97
.optional(seq, Command.waitUntil(m_endCondition).named(
"Until Condition"
));
98
// We have a custom end condition, so we need to wrap the group in a race
99
return
useAutomaticName ? out.withAutomaticName() : out.named(name);
100
}
101
108
public
Command
withAutomaticName
() {
109
return
named
(m_steps.stream().map(
Command::name
).collect(Collectors.joining(
" -> "
)),
true
);
110
}
111
}
org.wpilib.command3.ParallelGroupBuilder.ParallelGroupBuilder
ParallelGroupBuilder()
Definition
ParallelGroupBuilder.java:32
org.wpilib.command3.SequentialGroupBuilder.SequentialGroupBuilder
SequentialGroupBuilder()
Definition
SequentialGroupBuilder.java:31
org.wpilib.command3.SequentialGroupBuilder.until
SequentialGroupBuilder until(BooleanSupplier endCondition)
Definition
SequentialGroupBuilder.java:73
org.wpilib.command3.SequentialGroupBuilder.andThen
SequentialGroupBuilder andThen(Command... nextCommands)
Definition
SequentialGroupBuilder.java:53
org.wpilib.command3.SequentialGroupBuilder.andThen
SequentialGroupBuilder andThen(Command next)
Definition
SequentialGroupBuilder.java:39
org.wpilib.command3.SequentialGroupBuilder.withAutomaticName
Command withAutomaticName()
Definition
SequentialGroupBuilder.java:108
org.wpilib.command3.SequentialGroupBuilder.named
Command named(String name)
Definition
SequentialGroupBuilder.java:84
org.wpilib.command3.SequentialGroup
Definition
SequentialGroup.java:24
org.wpilib.annotation.NoDiscard
Definition
NoDiscard.java:20
org.wpilib.command3.Command
Definition
Command.java:98
org.wpilib.command3.Command.name
String name()
org
wpilib
command3
SequentialGroupBuilder.java
Generated by
1.18.0