-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc4e857
commit 2836ca7
Showing
2 changed files
with
71 additions
and
0 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
43 changes: 43 additions & 0 deletions
43
acropolis-report/src/main/kotlin/org/ephyra/acropolis/report/impl/ReportRunner.kt
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,12 +1,55 @@ | ||
package org.ephyra.acropolis.report.impl | ||
|
||
import org.ephyra.acropolis.report.api.IReportRunner | ||
import org.ephyra.acropolis.report.api.model.Graph | ||
import org.ephyra.acropolis.report.api.model.GraphContainer | ||
import org.ephyra.acropolis.report.api.model.Node | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
private class ReportRunner : IReportRunner { | ||
override fun run(graphContainer: GraphContainer) { | ||
println("Running report") | ||
buildNodeDepth(graphContainer.graph) | ||
|
||
|
||
} | ||
|
||
fun buildNodeDepth(graph: Graph): HashMap<Node, Int> { | ||
val startNode = pickStartNode(graph) | ||
|
||
val depths = HashMap<Node, Int>() | ||
depths[startNode] = 0 | ||
|
||
nodeDepth(startNode, graph, depths, 1) | ||
|
||
return depths | ||
} | ||
|
||
fun nodeDepth(currentNode: Node, graph: Graph, depths: HashMap<Node, Int>, depth: Int) { | ||
val connected = graph.findNodesConnectedFrom(currentNode) | ||
|
||
// Remove all the nodes which are already numbered. | ||
connected.removeAll(depths.keys) | ||
|
||
// Number each of the connected nodes. | ||
connected.forEach { con -> | ||
depths[con] = depth | ||
} | ||
|
||
// Now apply the same process to each of the nodes we just numbered. | ||
connected.forEach { con -> | ||
nodeDepth(con, graph, depths, depth + 1) | ||
} | ||
} | ||
|
||
fun pickStartNode(graph: Graph): Node { | ||
val sourceNodes = graph.findSourceNodes() | ||
return if (sourceNodes.isEmpty()) { | ||
graph.firstNode() | ||
} | ||
else { | ||
sourceNodes.first() | ||
} | ||
} | ||
} |