VesselGenerator.kt
757 Bytes
package application.model
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
fun createVesselCollection(file: File) : SortedMap<String, Vessel> {
val messages : ArrayList<Message> = arrayListOf()
val vessels: SortedMap<String, 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.value)){
vessels[message.mmsi.value] = Vessel(message.mmsi.value!!)
}
vessels[message.mmsi.value]?.messages?.set(message.time.value, message)
}
}
return vessels
}