From c4816f18fa1ab4528a6966d636c3bfd7eac7b82a Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 8 Sep 2017 13:18:57 +0200 Subject: Make edges a property of a node This change converts the ingoingEdges() and outgoingEdges() to a property in Kotlin. This better conveys the meaning of the attribute and is more in line with a Kotlin design. --- .../nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt | 2 +- .../kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt | 8 ++------ .../src/main/kotlin/nl/atlarge/opendc/topology/Node.kt | 16 ++++++---------- 3 files changed, 9 insertions(+), 17 deletions(-) (limited to 'opendc-core/src/main') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt index c5740210..dc3c0d0f 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt @@ -72,7 +72,7 @@ class OmegaSimulator(override val topology: Topology) : Simulator, Iterator resolve(node) - node.outgoingEdges().forEach { resolve(it) } + node.outgoingEdges.forEach { resolve(it) } } registry.values.forEach { context -> diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt index 50f8fa0c..28154695 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt @@ -105,13 +105,9 @@ internal class AdjacencyListTopology: MutableTopology { override fun iterator(): MutableIterator> = nodes.iterator() internal inner class AdjacencyListNode>(override val id: Int, override val label: T): Node { - internal var ingoingEdges: MutableSet> = HashSet() - internal var outgoingEdges: MutableSet> = HashSet() - - override fun ingoingEdges(): Set> = ingoingEdges - override fun outgoingEdges(): Set> = outgoingEdges + override var ingoingEdges: MutableSet> = HashSet() + override var outgoingEdges: MutableSet> = HashSet() override fun toString(): String = label.toString() - internal fun validate(instance: AdjacencyListTopology) = this@AdjacencyListTopology == instance } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt index c21fd088..ee1cde9b 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt @@ -39,18 +39,14 @@ interface Node>: Component { val id: Int /** - * Return the set of ingoing edges of this node. - * - * @return All edges whose destination is this node. + * The set of ingoing edges of this node. */ - fun ingoingEdges(): Set> + val ingoingEdges: Set> /** - * Return the set of outgoing edges of this node. - * - * @return All edges whose source is this node. + * The set of outgoing edges of this node. */ - fun outgoingEdges(): Set> + val outgoingEdges: Set> /** * The [Entity] this node represents within a logical topology of a cloud network. @@ -67,7 +63,7 @@ interface Node>: Component { * @return The entities of all edges whose destination is this node and have the given tag. */ inline fun Node<*>.ingoing(tag: String) = - ingoingEdges().filter { it.tag == tag }.map { it.to.entity as T }.toSet() + ingoingEdges.filter { it.tag == tag }.map { it.to.entity as T }.toSet() /** @@ -78,4 +74,4 @@ inline fun Node<*>.ingoing(tag: String) = * @return The entities of all edges whose source is this node and have the given tag. */ inline fun Node<*>.outgoing(tag: String) = - outgoingEdges().filter { it.tag == tag }.map { it.to.entity as T }.toSet() + outgoingEdges.filter { it.tag == tag }.map { it.to.entity as T }.toSet() -- cgit v1.2.3