bson.StandardBSONCodecProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baku Show documentation
Show all versions of baku Show documentation
helps you focus your REST API back-end on the business logic
package com.github.fluidsonic.baku
import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KClass
internal class StandardBSONCodecProvider(
providers: Iterable>
) : BSONCodecProvider {
private val codecByClass = ConcurrentHashMap, BSONCodec<*, Context>>()
private val providers = providers.toSet().toTypedArray()
@Suppress("UNCHECKED_CAST")
override fun codecForClass(valueClass: KClass): BSONCodec? {
return codecByClass.getOrPut(valueClass) {
for (provider in providers) {
val codec = provider.codecForClass(valueClass)
if (codec != null) {
return@getOrPut codec
}
}
return null
} as BSONCodec
}
}