I'd like a better way to loop through the keyList and if a key starts with the one of the comparator to grab that comparator string and add it to a Map as a header like so MutableMap>..the list being all the key items that match the comparator..
keysList: List<String>
val comparators = listOf("error", "customer", "custom", "feature")
So far I am doing it this way
private fun addToMap(key: String, attributeMap: MutableMap<String, MutableList<String>>) {
val list: MutableList<String> = attributeMap[getHeader(key)] ?: mutableListOf()
list.add(key)
attributeMap[getHeader(key)] = list
}
private fun getHeader(key: String): String {
val compareMap = mapOf("error" to "Error Attributes", "customer" to "Customer Attributes",
"custom" to "Customer Attributes", "feature" to "Feature Attributes", "request.header" to "Request Header Attributes",
"request.parameter" to "Request Parameter Attributes", "request" to "Other Request Attributes")
val defaultKeys = listOf("error.expected", "error.class", "error.message", "host", "httpResponseCode", "transactionName", "transactionUiName") // contains
for ((k, v) in compareMap) {
return if (key.startsWith(k)) {
v
} else if (key in defaultKeys) {
"Error Attributes"
} else {
"Custom Attributes"
}
}
return "Custom Attributes"
}