From 314c68fb4b4202538cfdb21aa2a56b2aa3aad6fb Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 8 Sep 2017 12:57:12 +0200 Subject: Allow easier construction of graph via TopologyBuilder This change allows for easier construction of a topology. --- .../src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt | 8 ++++++++ opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'opendc-core') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt index 5752eb89..20cbdb0c 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt @@ -30,6 +30,14 @@ package nl.atlarge.opendc.topology * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ interface TopologyBuilder { + /** + * Construct a [Topology] from the given block and return it. + * + * @param block The block to construct the topology. + * @return The topology that has been built. + */ + fun construct(block: MutableTopology.() -> Unit): Topology = build().apply(block) + /** * Build a [Topology] instance from the current state of this builder. * diff --git a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt index 50e22734..6d67c941 100644 --- a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt @@ -35,7 +35,7 @@ internal class SmokeTest { @Test fun smoke() { val builder = AdjacencyListTopologyBuilder() - val topology = builder.build().apply { + val topology = builder.construct { val rack = node(Rack()) val n = 100 // Create n machines in the rack -- cgit v1.2.3