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

e.ultra.kontainer.0.76.4.source-code.DynamicsChecker.kt Maven / Gradle / Ivy

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