-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: cmoulliard <[email protected]>
- Loading branch information
1 parent
0359e7d
commit a9d80bc
Showing
8 changed files
with
69 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.snowdrop.visitorpattern; | ||
|
||
public abstract class AbstractRun implements Visitable { | ||
|
||
public AbstractRun() {} | ||
|
||
@Override | ||
public abstract AbstractRun accept(Visitor visitor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 16 additions & 6 deletions
22
src/main/java/dev/snowdrop/visitorpattern/ResourceVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
package dev.snowdrop.visitorpattern; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
public class ResourceVisitor implements Visitor { | ||
|
||
@Override | ||
public void visit(PipelineRun pipelineRun) { | ||
System.out.println("Processing PipelineRun: " + pipelineRun.getName()); | ||
// Logic to process PipelineRun | ||
public AbstractRun visit(PipelineRun pipelineRun) { | ||
System.out.println("Processing PipelineRun ..."); | ||
Configurator cfg = pipelineRun.getConfig(); | ||
pipelineRun.setActions(cfg.getJob().getActions()); | ||
pipelineRun.setName(cfg.getName()); | ||
return pipelineRun; | ||
} | ||
|
||
@Override | ||
public void visit(TaskRun taskRun) { | ||
System.out.println("Processing TaskRun: " + taskRun.getName()); | ||
// Logic to process TaskRun | ||
public TaskRun visit(TaskRun taskRun) { | ||
System.out.println("Processing TaskRun ..."); | ||
Configurator cfg = taskRun.getConfig(); | ||
taskRun.setSteps(cfg.getJob().getActions().stream() | ||
.map(action -> new Step(action.getName())) | ||
.collect(Collectors.toList())); | ||
taskRun.setName(cfg.getName()); | ||
return taskRun; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package dev.snowdrop.visitorpattern; | ||
|
||
public interface Visitable { | ||
void accept(Visitor visitor); | ||
AbstractRun accept(Visitor visitor); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package dev.snowdrop.visitorpattern; | ||
|
||
public interface Visitor { | ||
void visit(PipelineRun pipelineRun); | ||
void visit(TaskRun taskRun); | ||
AbstractRun visit(PipelineRun pipelineRun); | ||
AbstractRun visit(TaskRun taskRun); | ||
} | ||
|