diff options
| -rw-r--r-- | opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt | 24 | ||||
| -rw-r--r-- | opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt | 2 |
2 files changed, 23 insertions, 3 deletions
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 bdf60056..50f8fa0c 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 @@ -48,13 +48,33 @@ internal class AdjacencyListTopology: MutableTopology { private val nodes: MutableList<Node<*>> = ArrayList() /** + * Returns the size of the collection. + */ + override val size: Int = nodes.size + + /** + * Checks if the specified element is contained in this collection. + */ + override fun contains(element: Node<*>): Boolean = nodes.contains(element) + + /** + * Checks if all elements in the specified collection are contained in this collection. + */ + override fun containsAll(elements: Collection<Node<*>>): Boolean = nodes.containsAll(elements) + + /** + * Returns `true` if the collection is empty (contains no elements), `false` otherwise. + */ + override fun isEmpty(): Boolean = nodes.isEmpty() + + /** * Create a [Node] in this [Topology] for the given [Entity]. * * @param entity The entity to create a node for. * @return The node created for the given entity. */ override fun <T : Entity<*>> node(entity: T): Node<T> { - val node = AdjacencyListNode(nextId.incrementAndGet(), entity) + val node = AdjacencyListNode(nextId.getAndIncrement(), entity) nodes.add(node) return node } @@ -82,7 +102,7 @@ internal class AdjacencyListTopology: MutableTopology { /** * Returns an iterator over the elements of this object. */ - override fun iterator(): Iterator<Node<*>> = nodes.iterator() + 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() diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt index d8f966d1..5d88334c 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Topology.kt @@ -32,4 +32,4 @@ package nl.atlarge.opendc.topology * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface Topology: Iterable<Node<*>> +interface Topology: Set<Node<*>> |
