Skip to content

Commit 31d3b31

Browse files
NOBUG: add overloaded methods with List of commands for CommandRequest (#275)
1 parent 96f3583 commit 31d3b31

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

src/main/java/io/iworkflow/core/command/CommandRequest.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ public abstract class CommandRequest {
2929
* @return the command request
3030
*/
3131
public static CommandRequest forAllCommandCompleted(final BaseCommand... commands) {
32+
return forAllCommandCompleted(Arrays.asList(commands));
33+
}
34+
35+
/**
36+
* forAllCommandCompleted will wait for all the commands to complete
37+
*
38+
* @param commands all the commands
39+
* @return the command request
40+
*/
41+
public static CommandRequest forAllCommandCompleted(final List<BaseCommand> commands) {
3242
return ImmutableCommandRequest.builder()
33-
.addAllCommands(Arrays.asList(commands))
43+
.addAllCommands(commands)
3444
.commandWaitingType(CommandWaitingType.ALL_COMPLETED)
3545
.build();
3646
}
@@ -42,8 +52,18 @@ public static CommandRequest forAllCommandCompleted(final BaseCommand... command
4252
* @return the command request
4353
*/
4454
public static CommandRequest forAnyCommandCompleted(final BaseCommand... commands) {
55+
return forAnyCommandCompleted(Arrays.asList(commands));
56+
}
57+
58+
/**
59+
* forAnyCommandCompleted will wait for any the commands to complete
60+
*
61+
* @param commands all the commands
62+
* @return the command request
63+
*/
64+
public static CommandRequest forAnyCommandCompleted(final List<BaseCommand> commands) {
4565
return ImmutableCommandRequest.builder()
46-
.addAllCommands(Arrays.asList(commands))
66+
.addAllCommands(commands)
4767
.commandWaitingType(CommandWaitingType.ANY_COMPLETED)
4868
.build();
4969
}
@@ -58,8 +78,19 @@ public static CommandRequest forAnyCommandCompleted(final BaseCommand... command
5878
* @return the command request
5979
*/
6080
public static CommandRequest forAnyCommandCombinationCompleted(final List<List<String>> commandCombinationLists, final BaseCommand... commands) {
61-
final List<BaseCommand> allSingleCommands = getAllSingleCommands(commands);
62-
final List<String> allNonEmptyCommandsIds = allSingleCommands.stream()
81+
return forAnyCommandCombinationCompleted(commandCombinationLists, Arrays.asList(commands));
82+
}
83+
/**
84+
* This will wait for any combination to complete.
85+
* Using this requires every command has a commandId when created.
86+
* Functionally this one can cover both forAllCommandCompleted, forAnyCommandCompleted. So the other two are like "shortcuts" of it.
87+
*
88+
* @param commandCombinationLists a list of different combinations, each combination is a list of String as CommandIds
89+
* @param commands all the commands
90+
* @return the command request
91+
*/
92+
public static CommandRequest forAnyCommandCombinationCompleted(final List<List<String>> commandCombinationLists, final List<BaseCommand> commands) {
93+
final List<String> allNonEmptyCommandsIds = commands.stream()
6394
.filter(command -> command.getCommandId().isPresent())
6495
.map(command -> command.getCommandId().get())
6596
.collect(Collectors.toList());
@@ -75,13 +106,8 @@ public static CommandRequest forAnyCommandCombinationCompleted(final List<List<S
75106
});
76107
return ImmutableCommandRequest.builder()
77108
.commandCombinations(combinations)
78-
.addAllCommands(allSingleCommands)
109+
.addAllCommands(commands)
79110
.commandWaitingType(CommandWaitingType.ANY_COMBINATION_COMPLETED)
80111
.build();
81112
}
82-
83-
private static List<BaseCommand> getAllSingleCommands(final BaseCommand... commands) {
84-
85-
return new ArrayList<>(Arrays.asList(commands));
86-
}
87113
}

0 commit comments

Comments
 (0)