-private fun parseContexts(prefix: String, fields: SimpleFieldSet): Set<String> {
- val contexts = HashSet<String>()
- var contextCounter = -1
- while (true) {
- val context = fields.get(prefix + "Context" + ++contextCounter) ?: break
- contexts.add(context)
- }
- return contexts
-}
-
-private fun parseProperties(prefix: String, fields: SimpleFieldSet): Map<String, String> {
- val properties = HashMap<String, String>()
- var propertiesCounter = -1
- while (true) {
- val propertyName = fields.get(prefix + "Property" + ++propertiesCounter + ".Name") ?: break
- val propertyValue = fields.get(prefix + "Property" + propertiesCounter + ".Value")
- properties[propertyName] = propertyValue
- }
- return properties
-}
+private fun SimpleFieldSet.contexts(prefix: String) =
+ generateSequence(0, Int::inc)
+ .map { get("${prefix}Context$it") }
+ .takeWhile { it != null }
+ .toList()
+
+private fun SimpleFieldSet.properties(prefix: String) =
+ generateSequence(0, Int::inc)
+ .takeWhile { get("${prefix}Property${it}.Name") != null }
+ .map { get("${prefix}Property${it}.Name") to get("${prefix}Property${it}.Value") }
+ .toMap()