Skip to content

Commit

Permalink
add total count in OSMDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Sep 23, 2023
1 parent bfed74e commit ea35455
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.vonforst.evmap.api.openstreetmap

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.ToJson
import com.squareup.moshi.rawType
Expand Down Expand Up @@ -38,15 +36,18 @@ internal class OSMConverterFactory(val moshi: Moshi) : Converter.Factory() {

val instantAdapter = moshi.adapter(Instant::class.java)
val osmChargingStationAdapter = moshi.adapter(OSMChargingStation::class.java)
val longAdapter = moshi.adapter(Long::class.java)
return Converter<ResponseBody, OSMDocument> { body ->
val reader = JsonReader.of(body.source())
reader.beginObject()

var timestamp: Instant? = null
var doc: Sequence<OSMChargingStation>? = null
var count: Long? = null
while (reader.hasNext()) {
when (reader.nextName()) {
"timestamp" -> timestamp = instantAdapter.fromJson(reader)!!
"count" -> count = longAdapter.fromJson(reader)!!
"elements" -> {
doc = sequence {
reader.beginArray()
Expand All @@ -60,7 +61,7 @@ internal class OSMConverterFactory(val moshi: Moshi) : Converter.Factory() {
}
}
}
OSMDocument(timestamp!!, doc!!)
OSMDocument(timestamp!!, count!!, doc!!)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private val SOCKET_TYPES = immutableListOf(

data class OSMDocument(
val timestamp: Instant,
val count: Long,
val elements: Sequence<OSMChargingStation>
)

Expand Down

0 comments on commit ea35455

Please sign in to comment.