Skip to content

Commit

Permalink
Use built-in check to check for maximum number of attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle van der Zwaag committed Dec 27, 2023
1 parent 5036073 commit 3046006
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/org/sqidskotlin/sqids/Sqids.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long>): String {
if (numbers.isEmpty()) {
Expand All @@ -673,7 +673,7 @@ class Sqids(private var alphabet: String = DEFAULT_ALPHABET, private val minLeng
*/
private fun encodeNumbers(numbers: List<Long>, 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) {
Expand Down

0 comments on commit 3046006

Please sign in to comment.