I have two lists that hold WorkflowCommands and WorkflowInstanceCommands.
public List<WorkflowCommand> workflowList = new ArrayList<>();
public List<WorkflowInstanceCommand> workflowInstanceList = new ArrayList<>();
public class WorkflowCommand {
int id;
String name;
String author;
int version;
@Override
public String toString() {
return "WorkflowCommand{" +
"id=" + id +
", name='" + name + '\'' +
", author='" + author + '\'' +
", version=" + version +
'}';
}
}
public class WorkflowInstanceCommand {
long id;
int workflowId;
String assignee;
String step;
String status;
@Override
public String toString() {
return "WorkflowInstanceCommand{" +
"id=" + id +
", workflowId=" + workflowId +
", assignee='" + assignee + '\'' +
", step='" + step + '\'' +
", status='" + status + '\'' +
'}';
}
}
Need to print out above two results
Find all the workflows with their according Workflow instances.
Find all workflows having running instances and the number of those Workflow instances.
Code for first query:
workflowList.forEach(w -> {
System.out.println("==workflow data=="+w);
workflowInstanceList.stream()
.filter(wi -> w.getId() == wi.getWorkflowId())
.forEach(System.out::println);
});
Code for second query:
workflowList.forEach(w -> {
List<WorkflowInstanceCommand> instanceCommands = workflowInstanceList.stream()
.filter(wi -> w.getId() == wi.getWorkflowId())
.filter(wi -> wi.getStatus().equals("RUNNING"))
.collect(Collectors.toList());
System.out.println("==workflow data=="+w+"===size=="+instanceCommands.size());
instanceCommands.forEach(System.out::println);
});
Is there any other efficient way of doing it?