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

com.github.squirrelgrip.scientist4k.configuration.MappingConfiguration.kt Maven / Gradle / Ivy

There is a newer version: 0.6.6
Show newest version
package com.github.squirrelgrip.scientist4k.configuration

import java.util.regex.Pattern

data class MappingConfiguration(
        val control: String,
        val candidate: String
) {
    val controlPattern: Pattern = Pattern.compile(control)

    fun matches(uri: String): Boolean {
        return controlPattern.matcher(uri).matches()
    }

    fun replace(uri: String): String {
        val matcher = controlPattern.matcher(uri)
        val stringBuffer = StringBuffer()
        while (matcher.find()) {
            matcher.appendReplacement(stringBuffer, candidate)
        }
        matcher.appendTail(stringBuffer)
        return stringBuffer.toString()
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy