arnab
11/10/2016, 5:15 PM#filter
](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/filter.html) is defined on Map
, but I am not able to figure out how to use it. Anyone care to share an example?
I have a deeply nested TreeMap instance (TreeMap<String, Map<String, Map<*, *>>>
) and I want to filter/find
the first (which is the only in the domain) top-level key that has a certain characteristics associated with something deeper in the value. I have this following non-functional code which solves it right now:
val indexToAliasMappingType = LinkedTreeMap<String, Map<String, Map<*, *>>>()
val indexToAliasMappings = Gson().fromJson(response.jsonString, indexToAliasMappingType.javaClass)
var currentIndexName = ""
for ((index, aliasMappings) in indexToAliasMappings) {
val hasCurrentAlias = aliasMappings.get("aliases")?.containsKey(alias)
if (hasCurrentAlias != null && hasCurrentAlias) {
currentIndexName = index
}
}
return currentIndexName