diff --git a/collektive-dsl/src/commonMain/kotlin/it/unibo/collektive/networking/OutboundEnvelope.kt b/collektive-dsl/src/commonMain/kotlin/it/unibo/collektive/networking/OutboundEnvelope.kt index 2661560c7..575252bf4 100644 --- a/collektive-dsl/src/commonMain/kotlin/it/unibo/collektive/networking/OutboundEnvelope.kt +++ b/collektive-dsl/src/commonMain/kotlin/it/unibo/collektive/networking/OutboundEnvelope.kt @@ -30,13 +30,6 @@ interface OutboundEnvelope { */ fun addData(path: Path, data: SharedData, dataSharingMethod: DataSharingMethod) - /** - * Extract the message for the [receiverId] through the given [factory]. - * - * One the [OutboundEnvelope] is created, this method extracts the message to send to the [receiverId]. - */ - fun prepareMessageFor(receiverId: ID, factory: MessageFactory = InMemoryMessageFactory()): Message - /** * Returns `true` if the envelope is empty. */ @@ -47,6 +40,13 @@ interface OutboundEnvelope { */ fun isNotEmpty(): Boolean + /** + * Extract the message for the [receiverId] through the given [factory]. + * + * One the [OutboundEnvelope] is created, this method extracts the message to send to the [receiverId]. + */ + fun prepareMessageFor(receiverId: ID, factory: MessageFactory = InMemoryMessageFactory()): Message + /** * Utilities for [OutboundEnvelope]. */ @@ -56,6 +56,7 @@ interface OutboundEnvelope { */ internal operator fun invoke(senderId: ID, expectedSize: Int): OutboundEnvelope = object : OutboundEnvelope { + private val defaults: MutableMap> = LinkedHashMap(expectedSize * 2) private val overrides: MutableMap>>> = LinkedHashMap(expectedSize * 2) @@ -79,6 +80,10 @@ interface OutboundEnvelope { } } + override fun isEmpty(): Boolean = defaults.isEmpty() + + override fun isNotEmpty(): Boolean = defaults.isNotEmpty() + override fun prepareMessageFor(receiverId: ID, factory: MessageFactory): Message { val overridesForId = overrides[receiverId].orEmpty() val payloads = when { @@ -87,10 +92,6 @@ interface OutboundEnvelope { } return factory(senderId, payloads) } - - override fun isEmpty(): Boolean = defaults.isEmpty() - - override fun isNotEmpty(): Boolean = defaults.isNotEmpty() } } }