Using .entries instead of .values()

This commit is contained in:
dankito 2024-10-04 03:13:45 +02:00
parent 686777b34f
commit a928f04fa6
1 changed files with 4 additions and 4 deletions

View File

@ -25,19 +25,19 @@ open class EpcQrCodeParser {
} }
protected open fun parseEpcQrAfterSuccessfulFormatCheck(decodedQrCode: String, lines: List<String>): ParseEpcQrCodeResult { protected open fun parseEpcQrAfterSuccessfulFormatCheck(decodedQrCode: String, lines: List<String>): ParseEpcQrCodeResult {
val validVersionCodes = EpcQrCodeVersion.values().map { it.code } val validVersionCodes = EpcQrCodeVersion.entries.map { it.code }
if (lines[1].length != 3 || validVersionCodes.contains(lines[1]) == false) { if (lines[1].length != 3 || validVersionCodes.contains(lines[1]) == false) {
return createInvalidFormatResult(decodedQrCode, "The second line has to be exactly one of these values: ${validVersionCodes.joinToString(", ")}") return createInvalidFormatResult(decodedQrCode, "The second line has to be exactly one of these values: ${validVersionCodes.joinToString(", ")}")
} }
val version = EpcQrCodeVersion.values().first { it.code == lines[1] } val version = EpcQrCodeVersion.entries.first { it.code == lines[1] }
val codingCode = lines[2].toIntOrNull() val codingCode = lines[2].toIntOrNull()
if (lines[2].length != 1 || codingCode == null || codingCode < 1 || codingCode > 8) { if (lines[2].length != 1 || codingCode == null || codingCode < 1 || codingCode > 8) {
return createInvalidFormatResult(decodedQrCode, "The third line has to be exactly one of these values: ${EpcQrCodeCharacterSet.values().map { it.code }.joinToString(", ")}") return createInvalidFormatResult(decodedQrCode, "The third line has to be exactly one of these values: ${EpcQrCodeCharacterSet.entries.map { it.code }.joinToString(", ")}")
} }
val coding = EpcQrCodeCharacterSet.values().first { it.code == codingCode } val coding = EpcQrCodeCharacterSet.entries.first { it.code == codingCode }
if (lines[3].length != 3) { if (lines[3].length != 3) {
return createInvalidFormatResult(decodedQrCode, "The fourth line, ${lines[3]}, has to be exactly three characters long.") return createInvalidFormatResult(decodedQrCode, "The fourth line, ${lines[3]}, has to be exactly three characters long.")