hasSizeEqualTo

@JvmName(name = "arrayHasSizeEqualTo")
fun <T> Validatable<Array<out T>?>.hasSizeEqualTo(size: Int): Constraint

The validatable Array must have a size equal to size when this constraint is applied.

Code example:

val validate = Validator<Array<Char>> { hasSizeEqualTo(3) }
validate(arrayOf('a', 'b', 'c')) // Success
validate(arrayOf('a', 'b')) // Failure (message: The number of items must be equal to 3)

@JvmName(name = "collectionHasSizeEqualTo")
fun <T> Validatable<Collection<T>?>.hasSizeEqualTo(size: Int): Constraint

The validatable Collection must have a size equal to size when this constraint is applied.

Code example:

val validate = Validator<Collection<Char>> { hasSizeEqualTo(3) }
validate(listOf('a', 'b', 'c')) // Success
validate(listOf('a', 'b')) // Failure (message: The number of items must be equal to 3)

@JvmName(name = "mapHasSizeEqualTo")
fun <T> Validatable<Map<*, T>?>.hasSizeEqualTo(size: Int): Constraint

The validatable Map must have a size equal to size when this constraint is applied.

Code example:

val validate = Validator<Map<Char, Int>> { hasSizeEqualTo(3) }
validate(mapOf('a' to 1, 'b' to 2, 'c' to 3)) // Success
validate(mapOf('a' to 1, 'b' to 2)) // Failure (message: The number of items must be equal to 3)