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

jvmMain.MapRaptorSettings.kt Maven / Gradle / Ivy

There is a newer version: 0.27.0
Show newest version
package io.fluidsonic.raptor

import io.fluidsonic.raptor.RaptorSettings.*


internal class MapRaptorSettings(
	private val valueProviders: Map>,
) : RaptorSettings {

	override fun valueProvider(path: String): ValueProvider<*>? =
		split(path) { key, remainingPath ->
			when (remainingPath) {
				null -> valueProviders[key]
				else -> (valueProviders[key]?.value as? RaptorSettings?)?.valueProvider(remainingPath) // TODO Improve - what if not RaptorSettings?
			}
		}


	private inline fun  split(
		path: String,
		action: (key: String, remainingPath: String?) -> Result,
	): Result {
		val index = path.indexOf('.')
		if (index < 0)
			return action(path, null)

		val key = path.substring(0, index)
		val remainingPath = path.substring(index + 1)

		return action(key, remainingPath)
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy