vendredi 6 mars 2015

Fluent Interface to Build a Directed Cyclic Graph?

I have created a set of classes to represent a directed cyclic graph for representing BPM processes, based on JUNG's DirectedSparseGraph class, which provides only basic graph manipulation methods to add and find vertices and edges.


The challenge I am facing is to create a builder that provides a fluent interface able to create a graph that includes complex branching, cycles, and multiple end nodes (see examples below).


Parallel Branches


Parallel Branches


Merging Branches


Merging Branches


Cycles


Cycle


Complex


Complex


My current implementation (see example below) is resorting to aliasing the vertex where a fork occurs (e.g., vertex "B" in Parallel Branches), and then I refer to the alias when adding a new branch to that vertex. My builder also includes something similar to allow for the merging of branches and cycles. Aliases were introduced because vertex names are not unique in BPM graphs. I want a more elegant fluent interface to quickly build graphs, free from those references.



Graph graph = GraphBuilder.newGraph()
.addVertex("A")
.edgeName("")
.addVertex("B", "b-fork")
.edgeName("")
.addVertex("C")
.edgeName("")
.addVertex("E")
.addBranch("b-fork")
.edgeName("")
.addVertex("D")
.edgeName("")
.addVertex("F")
.build();

Aucun commentaire:

Enregistrer un commentaire