Skip to content

Commit ef12bfe

Browse files
committed
Minor improvement to workflow creation
1 parent 80bc9ba commit ef12bfe

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/java/com/adventofcode/flashk/day19/Workflow.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public Workflow(String input) {
2727
String rulesString = StringUtils.substringBetween(input, "{", "}");
2828
String[] rulesArray = rulesString.split(",");
2929
rules = Arrays.stream(rulesArray).map(Rule::new).collect(Collectors.toList());
30+
31+
// TODO minor improvement
32+
// some workflows lead always to the same output workflow, in that case
33+
// rules can be directely bypassed.
34+
boolean sameWorkflows = true;
35+
String workflowName = rules.get(0).getDestinationWorkflow();
36+
for(Rule rule : rules) {
37+
if(!rule.getDestinationWorkflow().equals(workflowName)) {
38+
sameWorkflows = false;
39+
}
40+
}
41+
42+
if(sameWorkflows) {
43+
rules.clear();
44+
rules.add(new Rule(workflowName));
45+
}
3046
}
3147

3248
public String run(Part part) {

0 commit comments

Comments
 (0)