Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PipelineNodesGraph {
- // nested groovy trait, same as nested interface in java
- static trait NodeVisitor {
- void enter(GraphNode node) {}
- void visit(GraphNode node) {}
- void exit(GraphNode node) {}
- }
- static class CycleDetector implements NodeVisitor {
- // ... graph cycles detecting implementation ...
- }
- private List<Node> findCycle() {
- def cycleDetector = new CycleDetector()
- def cycle = []
- try {
- traverseDepthFirst([cycleDetector])
- } catch (CyclicConnectionException e) {
- cycle = e.cycle
- }
- return cycle
- }
- }
- class NodeBuildingVisitor implements NodeVisitor {
- void visit(GraphNode graphNode) {
- if (!graphNode.node.assembled) {
- graphNode.node.assemble()
- }
- }
- }
- class Pipeline {
- void build() {
- // build all nodes
- def graph = new PipelineNodesGraph(nodes, links)
- def buildVisitor = new NodeBuildingVisitor(this)
- graph.traverseDepthFirst([buildVisitor])
- assert nodes.every { it.assembled }
- }
- }
Add Comment
Please, Sign In to add comment