Blame view

src/main/kotlin/application/model/VesselGenerator.kt 1.06 KB
b350f9dfe   lsagona   import vessels an...
1
2
3
  package application.model
  
  import java.io.File
3b26be8f9   lsagona   controle the time...
4
  import java.time.ZoneOffset
53f01ecc3   lsagona   display message o...
5
  import java.util.*
b350f9dfe   lsagona   import vessels an...
6

3b26be8f9   lsagona   controle the time...
7
8
  fun createVesselCollection(file: File): SortedMap<String, Vessel> {
      val messages: ArrayList<Message> = arrayListOf()
f39d90e60   lsagona   Select/deselect MMSI
9
      val vessels: SortedMap<String, Vessel> = sortedMapOf()
3b26be8f9   lsagona   controle the time...
10
11
      var maxTime: Long = 0
      var minTime: Long = Long.MAX_VALUE
b350f9dfe   lsagona   import vessels an...
12
13
14
15
16
17
  
      file.forEachLine {
          val arrayMessage = it.split(",")
          if (arrayMessage[0].toIntOrNull() !== null) {
              val message = Message(arrayMessage)
              messages.add(message)
3b26be8f9   lsagona   controle the time...
18
              if (!vessels.containsKey(message.mmsi.value)) {
513c0341c   lsagona   add chart
19
                  vessels[message.mmsi.value] = Vessel(message.mmsi.value!!)
b350f9dfe   lsagona   import vessels an...
20
              }
3b26be8f9   lsagona   controle the time...
21
22
23
24
25
26
27
28
              val time = message.time.value.toEpochSecond(ZoneOffset.UTC)
              vessels[message.mmsi.value]?.messages?.set(time, message)
              if (time > maxTime) {
                  maxTime = time
              }
              if (time < minTime){
                  minTime = time
              }
b350f9dfe   lsagona   import vessels an...
29
          }
b350f9dfe   lsagona   import vessels an...
30
      }
3b26be8f9   lsagona   controle the time...
31
32
      Vessel.maxTime = maxTime
      Vessel.minTime = minTime
b350f9dfe   lsagona   import vessels an...
33
34
      return vessels
  }