VesselGenerator.kt 721 Bytes
package application.model

import java.io.File
import java.util.*
import kotlin.collections.ArrayList

fun createVesselCollection(file: File) : SortedMap<Int, Vessel> {
    val messages : ArrayList<Message> = arrayListOf()
    val vessels: SortedMap<Int, Vessel> = sortedMapOf()

    file.forEachLine {
        val arrayMessage = it.split(",")
        if (arrayMessage[0].toIntOrNull() !== null) {
            val message = Message(arrayMessage)
            messages.add(message)
            if (!vessels.containsKey(message.mmsi)){
                vessels[message.mmsi] = Vessel(message.mmsi!!)
            }
            vessels[message.mmsi]?.messages?.set(message.time, message)
        }

    }

    return vessels
}