A powerful yet easy to use dependency graph written in Java 8
This class implements a dependency graph using a strongly connected Directed Acyclic Graph (DAG) and allows sorting of its nodes in topological order.
- The graph fully implements Java 8's Collection interface
- It provides a standard Iterator and can be easily traversed in a simple for-each loop
- Calling method getTopology will not destroy the graph so the same graph instance can be safely reused after a topological sort operation
- It can optionally be instantiated to be thread-safe adding some overhead due to use of ReentrantReadWriteLock
- It is capable of detecting cycles (or circular dependencies) and for each cycle list all participant nodes (see method findCycles)
- Method findShortestPathBetween(a, b) will do extactly what it says using simple unweighted BFS (breadth-first search)
- Implement new method iteratePathsBetween(a, b) returning a standard Iterator where each next entry will be a Collection of graph nodes representing one valid path between nodes a and b