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

jvmMain.dev.programadorthi.routing.statuspages.StatusPagesUtilsJvm.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha02
Show newest version
/*
 * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package dev.programadorthi.routing.statuspages

import kotlin.reflect.KClass

internal actual fun selectNearestParentClass(
    cause: Throwable,
    keys: List>,
): KClass<*>? = keys.minByOrNull { distance(cause.javaClass, it.java) }

private fun distance(
    child: Class<*>,
    parent: Class<*>,
): Int {
    var result = 0
    var current = child
    while (current != parent) {
        current = current.superclass
        result++
    }

    return result
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy