All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lsd.core.builders.MessageBuilder.kt Maven / Gradle / Ivy

The newest version!
package com.lsd.core.builders

import com.lsd.core.IdGenerator
import com.lsd.core.domain.Message
import com.lsd.core.domain.MessageType
import com.lsd.core.domain.Participant
import com.lsd.core.domain.ParticipantType.PARTICIPANT
import java.time.Duration
import java.time.Instant

private val idGenerator = IdGenerator(isDeterministic = false)

class MessageBuilder {
    private var message =
        Message(id = idGenerator.next(), from = PARTICIPANT.called(""), to = PARTICIPANT.called(""), label = "")

    fun id(id: String) = also { message = message.copy(id = id) }
    fun from(from: String) = also { message = message.copy(from = PARTICIPANT.called(from)) }
    fun from(from: Participant) = also { message = message.copy(from = from) }
    fun to(to: String) = also { message = message.copy(to = PARTICIPANT.called(to)) }
    fun to(to: Participant) = also { message = message.copy(to = to) }
    fun label(label: String) = also { message = message.copy(label = label) }
    fun data(data: Any) = also { message = message.copy(data = data) }
    fun colour(colour: String) = also { message = message.copy(colour = colour) }
    fun type(type: MessageType) = also { message = message.copy(type = type) }
    fun duration(duration: Duration) = also { message = message.copy(duration = duration) }
    fun created(instant: Instant) = also { message = message.copy(created = instant) }
    fun build(): Message = message

    companion object {
        @JvmStatic
        fun messageBuilder(): MessageBuilder = MessageBuilder()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy