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

io.github.numichi.reactive.logger.internal.helper.kt Maven / Gradle / Ivy

package io.github.numichi.reactive.logger.internal

import io.github.numichi.reactive.logger.KEY_MUST_NOT_BE_NULL
import reactor.util.function.Tuple2
import reactor.util.function.Tuples

internal inline fun  Map.toSafeMdcMap(): Map {
    return this.filter { it.key != null }
        .mapKeys { it.key.toString() }
        .mapValues { it.value?.toString() }
}

internal inline fun  Tuple2.toSafeMdcTuple2(): Tuple2 {
    requireNotNull(this.t1) { KEY_MUST_NOT_BE_NULL }

    return Tuples.of(this.t1.toString(), this.t2.toString())
}

internal inline fun  Tuple2.toSafeMdcMap(): Map {
    val safe = this.toSafeMdcTuple2()
    return mapOf(safe.t1 to safe.t2)
}

internal inline fun  Pair.toSafeMdcPair(): Pair {
    requireNotNull(this.first) { KEY_MUST_NOT_BE_NULL }

    if (this.second == null) {
        return this.first.toString() to null
    }

    return this.first.toString() to this.second.toString()
}

internal inline fun  Pair.toSafeMdcMap(): Map {
    return mapOf(this.toSafeMdcPair())
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy