summaryrefslogtreecommitdiff
path: root/opendc-core
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-08 13:18:57 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-08 13:20:16 +0200
commitc4816f18fa1ab4528a6966d636c3bfd7eac7b82a (patch)
treec50adf394f6355349c63a8af1b67cdc08394966c /opendc-core
parent62c113b3bae2f5701b057ce45043cbdf50346e67 (diff)
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.
Diffstat (limited to 'opendc-core')
-rw-r--r--opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt2
-rw-r--r--opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt8
-rw-r--r--opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Node.kt16
3 files changed, 9 insertions, 17 deletions
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<Unit
init {
topology.forEach { node ->
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<Node<*>> = nodes.iterator()
internal inner class AdjacencyListNode<out T: Entity<*>>(override val id: Int, override val label: T): Node<T> {
- internal var ingoingEdges: MutableSet<Edge<*>> = HashSet()
- internal var outgoingEdges: MutableSet<Edge<*>> = HashSet()
-
- override fun ingoingEdges(): Set<Edge<*>> = ingoingEdges
- override fun outgoingEdges(): Set<Edge<*>> = outgoingEdges
+ override var ingoingEdges: MutableSet<Edge<*>> = HashSet()
+ override var outgoingEdges: MutableSet<Edge<*>> = 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<out T: Entity<*>>: Component<T> {
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<Edge<*>>
+ val ingoingEdges: Set<Edge<*>>
/**
- * 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<Edge<*>>
+ val outgoingEdges: Set<Edge<*>>
/**
* The [Entity] this node represents within a logical topology of a cloud network.
@@ -67,7 +63,7 @@ interface Node<out T: Entity<*>>: Component<T> {
* @return The entities of all edges whose destination is this node and have the given tag.
*/
inline fun <reified T> 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 <reified T> Node<*>.ingoing(tag: String) =
* @return The entities of all edges whose source is this node and have the given tag.
*/
inline fun <reified T> 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()