io.smooth.constraint.resolution.ConstraintResolutionService.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of constraints Show documentation
Show all versions of constraints Show documentation
A suite of libraries made to help ease developer's life
The newest version!
package io.smooth.constraint.resolution
import io.smooth.constraint.Constraint
import io.smooth.store.Store
import io.smooth.store.memory.PerpetualInMemoryStore
import kotlinx.coroutines.flow.firstOrNull
import javax.inject.Provider
import kotlin.reflect.KClass
internal class ConstraintResolutionService {
private val resolutionsStore =
PerpetualInMemoryStore>, MutableList>>>()
internal suspend fun > addConstraintsResolutions(
constraint: Constraint
) {
val resolutions = constraint.resolutions() ?: return
addConstraintsResolutions(constraint::class, resolutions)
}
internal suspend fun addConstraintsResolutions(
constraintClass: KClass>,
resolutions: List, *>>>
) {
var resolutionsProviders = resolutionsStore.getById(constraintClass).firstOrNull()
if (resolutionsProviders == null) {
resolutionsProviders = resolutions.toMutableList()
} else {
resolutionsProviders.addAll(resolutions)
}
resolutionsStore.save(
Store.SaveDto(constraintClass, resolutionsProviders)
)
}
internal suspend fun > addConstraintResolution(
constraintClass: KClass,
resolutionProvider: Provider>
) {
var resolutionsProviders = resolutionsStore.getById(constraintClass).firstOrNull()
if (resolutionsProviders == null) {
resolutionsProviders = arrayListOf()
}
resolutionsProviders.add(resolutionProvider)
resolutionsStore.save(
Store.SaveDto(constraintClass, resolutionsProviders)
)
}
internal suspend fun > getConstraintResolutions(constraintClass: KClass): List>>? =
resolutionsStore.getById(constraintClass).firstOrNull()?.map {
it as Provider>
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy