stepperInputValidator

Validates the input parameters for a stepper operation.

This function ensures that the provided step value is positive and that both the start and end of the given range are multiples of the step. This is crucial for stepper operations where values are incremented or decremented by a fixed step size.

Parameters

step

The step value used for incrementing or decrementing. Must be a positive integer.

range

The range of values allowed, represented as an IntRange. Both the start and end of this range must be multiples of the step value.

Throws

If the step is not positive, or if the start or end of the range are not multiples of the step. The exception message will indicate the specific violation.

Example Usage:

// Valid input: step of 2, range from 0 to 10 (both multiples of 2)
stepperInputValidator(2, 0..10)

// Invalid input: step of -1 (not positive)
try {
stepperInputValidator(-1, 0..10)
} catch (e: IllegalArgumentException) {
println(e.message) // Output: A step can only be a positive integer, but was -1
}

// Invalid input: range start 1 (not multiple of 2)
try {
stepperInputValidator(2, 1..10)
} catch (e: IllegalArgumentException) {
println(e.message) // Output: The min range must be a multiple of the step, but has 1 remaining
}

// Invalid input: range end 9 (not multiple of 2)
try {
stepperInputValidator(2, 0..9)
} catch (e: IllegalArgumentException) {
println(e.message) // Output: The max range must be a multiple of the step, but has 1 remaining
}