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

commonMain.kiota.internal.SegmentUtils.kt Maven / Gradle / Ivy

Go to download

A kotlin multiplatform library for representing headless collection based ui such as lists, tables and grids

There is a newer version: 3.0.11
Show newest version
package kiota.internal

import kiota.DynamicParamMatch
import kiota.ExactMatch
import kiota.SegmentMatch
import kiota.WildCardMatch
import kollections.Collection
import kollections.filterIsInstance
import kollections.forEachIndexed
import kollections.joinToString
import kollections.associate


private fun SegmentMatch.toScore() = when (this) {
    is WildCardMatch -> 1
    is DynamicParamMatch -> 2
    is ExactMatch -> 3
}

internal fun Collection.toScore(): Int {
    var score = 0
    forEachIndexed { idx, segment ->
        val level = idx + 1
        score += level * segment.toScore()
    }
    return score
}

internal fun Collection.toEvaluatedUrl() = joinToString("/") { it.path }

internal fun Collection.toParams() = filterIsInstance().associate { it.key to it.value }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy