Current code is relying on xtend Conversions to get first entry
from keySet/values separately. That code ends up copying the entire
collection into an array before picking the first element, which
is ... far from optimal.
Peel the first entrySet item using iterator().next() and then
reference key/value from there, which removes a dependency on
Conversions and is way more efficient.
Change-Id: I9cf16c416e65e538697aab26ebb5b9a81965e871
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
«val cValue = c.value as Map<String, String>»
«val String fieldSuffix = c.getName.substring(TypeConstants.PATTERN_CONSTANT_NAME.length)»
«IF cValue.size == 1»
«val cValue = c.value as Map<String, String>»
«val String fieldSuffix = c.getName.substring(TypeConstants.PATTERN_CONSTANT_NAME.length)»
«IF cValue.size == 1»
- private static final «Pattern.importedName» «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «Pattern.importedName».compile("«cValue.keySet.get(0).escapeJava»");
- private static final String «Constants.MEMBER_REGEX_LIST»«fieldSuffix» = "«cValue.values.get(0).escapeJava»";
+ «val firstEntry = cValue.entrySet.iterator.next»
+ private static final «Pattern.importedName» «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «Pattern.importedName».compile("«firstEntry.key.escapeJava»");
+ private static final String «Constants.MEMBER_REGEX_LIST»«fieldSuffix» = "«firstEntry.value.escapeJava»";
«ELSE»
private static final «Pattern.importedName»[] «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «CodeHelpers.importedName».compilePatterns(«ImmutableList.importedName».of(
«FOR v : cValue.keySet SEPARATOR ", "»"«v.escapeJava»"«ENDFOR»));
«ELSE»
private static final «Pattern.importedName»[] «Constants.MEMBER_PATTERN_LIST»«fieldSuffix» = «CodeHelpers.importedName».compilePatterns(«ImmutableList.importedName».of(
«FOR v : cValue.keySet SEPARATOR ", "»"«v.escapeJava»"«ENDFOR»));