-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Commands.java Add looseSequence() method #6639
Changes from all commits
7a8cd5b
8b36b83
d5d39d3
0f28942
5c858d3
59e77bb
c1576a2
1fb1c9a
0082985
5963974
4272774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,24 @@ public static Command sequence(Command... commands) { | |
return new SequentialCommandGroup(commands); | ||
} | ||
|
||
/** | ||
* Runs individual commands in a series without grouped behavior. | ||
* | ||
* <p>Each command is run independently by proxy. The requirements of | ||
* each command are reserved only for the duration of that command and | ||
* are not reserved for an entire group process as they are in a | ||
* grouped sequence. | ||
* | ||
* <p>disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. | ||
* | ||
* @param commands the commands to include in the series | ||
* @return the command to run the series of commands | ||
* @see #sequence(Command...) use sequence() to invoke group sequence behavior | ||
*/ | ||
public static Command disjointSequence(Command... commands) { | ||
return sequence(proxyAll(commands)); | ||
} | ||
|
||
/** | ||
* Runs a group of commands in series, one after the other. Once the last command ends, the group | ||
* is restarted. | ||
|
@@ -236,6 +254,26 @@ public static Command repeatingSequence(Command... commands) { | |
return sequence(commands).repeatedly(); | ||
} | ||
|
||
/** | ||
* Runs individual commands in a series without grouped behavior; once the last command ends, the series is restarted. | ||
* | ||
* <p>Each command is run independently by proxy. The requirements of | ||
* each command are reserved only for the duration of that command and | ||
* are not reserved for an entire group process as they are in a | ||
* grouped sequence. | ||
* | ||
* <p>disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. | ||
* | ||
* @param commands the commands to include in the series | ||
* @return the command to run the series of commands repeatedly | ||
* @see #repeatingSequence(Command...) use sequenceRepeatedly() to invoke repeated group sequence behavior | ||
* @see #disjointSequence(Command...) use disjointSequence() for no repeating behavior | ||
*/ | ||
public static Command repeatingDisjointSequence(Command... commands) { | ||
throw new IllegalArgumentException("Not Supported - RepeatCommand bug prevents correct use of Proxy"); | ||
// return disjointSequence(commands).repeatedly(); | ||
} | ||
|
||
/** | ||
* Runs a group of commands at the same time. Ends once all commands in the group finish. | ||
* | ||
|
@@ -246,6 +284,26 @@ public static Command repeatingSequence(Command... commands) { | |
public static Command parallel(Command... commands) { | ||
return new ParallelCommandGroup(commands); | ||
} | ||
|
||
/** | ||
* Runs individual commands at the same time without grouped behavior and ends once all commands finish. | ||
* | ||
* <p>Each command is run independently by proxy. The requirements of | ||
* each command are reserved only for the duration of that command and | ||
* are not reserved for an entire group process as they are in a | ||
* grouped parallel. | ||
* | ||
* <p>disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. | ||
* | ||
* @param commands the commands to run in parallel | ||
* @return the command to run the commands in parallel | ||
* @see #parallel(Command...) use parallel() to invoke group parallel behavior | ||
*/ | ||
public static Command disjointParallel(Command... commands) { | ||
new ParallelCommandGroup(commands); // check parallel constraints | ||
for (Command cmd : commands) CommandScheduler.getInstance().removeComposedCommand(cmd); | ||
return parallel(proxyAll(commands)); | ||
} | ||
|
||
/** | ||
* Runs a group of commands at the same time. Ends once any command in the group finishes, and | ||
|
@@ -259,6 +317,22 @@ public static Command race(Command... commands) { | |
return new ParallelRaceGroup(commands); | ||
} | ||
|
||
/** | ||
* Runs a group of commands at the same time. Ends once any command in the group finishes, and | ||
* cancels the others. | ||
* | ||
* <p>disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. | ||
* | ||
* @param commands the commands to include | ||
* @return the command group | ||
* @see ParallelRaceGroup | ||
*/ | ||
public static Command disjointRace(Command... commands) { | ||
new ParallelRaceGroup(commands); // check parallel constraints | ||
for (Command cmd : commands) CommandScheduler.getInstance().removeComposedCommand(cmd); | ||
return race(proxyAll(commands)); | ||
} | ||
|
||
/** | ||
* Runs a group of commands at the same time. Ends once a specific command finishes, and cancels | ||
* the others. | ||
|
@@ -273,6 +347,56 @@ public static Command deadline(Command deadline, Command... otherCommands) { | |
return new ParallelDeadlineGroup(deadline, otherCommands); | ||
} | ||
|
||
/** | ||
* Runs individual commands at the same time without grouped behavior; when the deadline command ends the otherCommands are cancelled. | ||
* | ||
* <p>Each otherCommand is run independently by proxy. The requirements of | ||
* each command are reserved only for the duration of that command and are | ||
* not reserved for an entire group process as they are in a grouped deadline. | ||
* | ||
* <p>disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. | ||
* | ||
* @param deadline the deadline command | ||
* @param otherCommands the other commands to include and will be cancelled when the deadline ends | ||
* @return the command to run the deadline command and otherCommands | ||
* @see #deadline(Command, Command...) use deadline() to invoke group parallel deadline behavior | ||
* @throws IllegalArgumentException if the deadline command is also in the otherCommands argument | ||
*/ | ||
public static Command disjointDeadline(Command deadline, Command... otherCommands) { | ||
new ParallelDeadlineGroup(deadline, otherCommands); // check parallel deadline constraints | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as |
||
CommandScheduler.getInstance().removeComposedCommand(deadline); | ||
for (Command cmd : otherCommands) { | ||
CommandScheduler.getInstance().removeComposedCommand(cmd); | ||
} | ||
if ( ! deadline.getRequirements().isEmpty()) { | ||
deadline = deadline.asProxy(); | ||
} | ||
return deadline(deadline, proxyAll(otherCommands)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe but doing that here doesn't help. If the If the The Proxy for the deadline as a grouped command has to be added when that group is made (not when used or referenced later) because after its creation later additional wrapping groupings don't know about the inner groups. This points out again that the Proxy has to be carefully considered minimally applying it starting from the inner commands to the outer commands. Edit after more thought that I might not understand the objective of this disjoint work and I gave a somewhat wrong answer above. I have mostly been thinking about the disjoint of a single group. The Likely this results in a lot of redundant and inefficient wrappings (of wrappings of wrappings). So we're back to "hand-tuning" the requirements by judicious addition of So yes - proxy everything if that's the objective and I now assume it is. |
||
} | ||
|
||
/** | ||
* Maps an array of commands by adding proxy to every element that has requirements using {@link Command#asProxy()}. | ||
* | ||
* <p>This is useful to ensure that default commands of subsystems within a command group are | ||
* still triggered despite command groups requiring the union of their members' requirements | ||
* | ||
* @param commands an array of commands | ||
* @return an array of commands to run by proxy if a command has requirements | ||
*/ | ||
public static Command[] proxyAll(Command... commands) { | ||
Command[] out = new Command[commands.length]; | ||
for (int i = 0; i < commands.length; i++) { | ||
if (commands[i].getRequirements().isEmpty()) { | ||
out[i] = commands[i]; | ||
} | ||
else { | ||
out[i] = commands[i].asProxy(); | ||
} | ||
} | ||
return out; | ||
} | ||
} | ||
|
||
private Commands() { | ||
throw new UnsupportedOperationException("This is a utility class"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should implement the check for disjoint requirements separately (probably in a private static convenience method)- It's self-documenting and (more importantly) will not register the commands as composed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that my proposed validation that has a side-effect of registering the commands that then must be unregistered is a bit stinky but it appears to save duplicating a lot of code. Tracing the
deadline
validation, which may be the worst case, needs most of the following code pasted here fromParallelDeadlineGroup.java
andCommandScheduler.java
.