hasSizeBetween
The validatable Array must have a size within the provided range when this constraint is applied.
Code example:
val validate = Validator<Array<Char>> { hasSizeBetween(1..2) }
validate(emptyArray()) // Failure (message: The number of items must be between 1 and 2)
validate(arrayOf('a')) // Success
validate(arrayOf('a', 'b')) // Success
validate(arrayOf('a', 'b', 'c')) // Failure (message: The number of items must be between 1 and 2)
Content copied to clipboard
The validatable Collection must have a size within the provided range when this constraint is applied.
Code example:
val validate = Validator<Collection<Char>> { hasSizeBetween(1..2) }
validate(emptyList()) // Failure (message: The number of items must be between 1 and 2)
validate(listOf('a')) // Success
validate(listOf('a', 'b')) // Success
validate(listOf('a', 'b', 'c')) // Failure (message: The number of items must be between 1 and 2)
Content copied to clipboard
The validatable Map must have a size within the provided range when this constraint is applied.
Code example:
val validate = Validator<Map<Char, Int>> { hasSizeBetween(1..2) }
validate(emptyMap()) // Failure (message: The number of items must be between 1 and 2)
validate(mapOf('a' to 1)) // Success
validate(mapOf('a' to 1, 'b' to 2)) // Success
validate(mapOf('a' to 1, 'b' to 2, 'c' to 3)) // Failure (message: The number of items must be between 1 and 2)
Content copied to clipboard