forked from Team254/FRC-2019-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParallelAction.java
46 lines (38 loc) · 1.01 KB
/
ParallelAction.java
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
package com.team254.frc2019.auto.actions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Composite action, running all sub-actions at the same time All actions are started then updated until all actions
* report being done.
*/
public class ParallelAction implements Action {
private final ArrayList<Action> mActions;
public ParallelAction(List<Action> actions) {
mActions = new ArrayList<>(actions);
}
public ParallelAction(Action... actions) {
this(Arrays.asList(actions));
}
@Override
public void start() {
mActions.forEach(Action::start);
}
@Override
public void update() {
mActions.forEach(Action::update);
}
@Override
public boolean isFinished() {
for (Action action : mActions) {
if (!action.isFinished()) {
return false;
}
}
return true;
}
@Override
public void done() {
mActions.forEach(Action::done);
}
}