From 304600669e23c273f1f8561420229243ce37a58e Mon Sep 17 00:00:00 2001 From: Jelle van der Zwaag Date: Wed, 27 Dec 2023 22:51:02 +0100 Subject: [PATCH] Use built-in check to check for maximum number of attempts --- src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt b/src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt index 4eb924d..e8cddbd 100644 --- a/src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt +++ b/src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt @@ -654,7 +654,7 @@ class Sqids(private var alphabet: String = DEFAULT_ALPHABET, private val minLeng * * @return the generated ID * @throws IllegalArgumentException if one of the numbers passed is smaller than 0 or greater than `maxValue()` - * @throws IllegalArgumentException if n attempts have been made to re-generated the ID, where n is alphabet length + 1 + * @throws IllegalStateException if n attempts have been made to re-generated the ID, where n is alphabet length + 1 */ fun encode(numbers: List): String { if (numbers.isEmpty()) { @@ -673,7 +673,7 @@ class Sqids(private var alphabet: String = DEFAULT_ALPHABET, private val minLeng */ private fun encodeNumbers(numbers: List, increment: Int = 0): String { - require(increment <= alphabet.length) { "Reached max attempts to re-generate the ID" } + check(increment <= alphabet.length) { "Reached max attempts to re-generate the ID" } var offset = numbers.size for (i in numbers.indices) {