e.ultra.kontainer.0.76.4.source-code.DynamicsChecker.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontainer Show documentation
Show all versions of kontainer Show documentation
"Kotlin Depdency Injection Framework"
package de.peekandpoke.ultra.kontainer
import kotlin.reflect.KClass
/**
* Helper class to validate the correctness instances passed [KontainerBlueprint.create].
*
* For each set of classes passed to [getUnexpected] the result is cached for future reuse.
*/
data class DynamicsChecker internal constructor(val dynamics: Set>) {
/**
* Internal cache
*
* A set of classes will have the same hash for the same classes, so we can do some caching here
*/
private val unexpectedLookUp = mutableMapOf>, Set>>()
/**
* Checks if all [given] are contained in all [dynamics]
*
* If all is well an empty set is returned.
* Otherwise the set will contain all classes that are not expected.
*/
fun getUnexpected(given: Set>): Set> {
return unexpectedLookUp.getOrPut(given) {
given.filter { givenClass ->
dynamics.none { dynamic -> dynamic.java.isAssignableFrom(givenClass.java) }
}.toSet()
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy