All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bson.StandardBSONCodecProvider.kt Maven / Gradle / Ivy

There is a newer version: 0.9.27
Show newest version
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
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy