PropertyRange

class PropertyRange<T : Comparable<T>>(initValue: T, min: T?, max: T?, violation: (T, T) -> T)

Represents range validator for properties with comparable type (e.g. Int, Long)

Author

Alexander Kornilov (akornilov.82@gmail.com).

Parameters

initValue

an initial value of the property.

min

a minimum bound of the value.

max

a maximum bound of the value.

violation

a violation handler.

Constructors

PropertyRange
Link copied to clipboard
fun <T : Comparable<T>> PropertyRange(initValue: T, range: ClosedRange<T>, violation: (T, T) -> T = ::defaultViolation)
PropertyRange
Link copied to clipboard
fun <T : Comparable<T>> PropertyRange(initValue: T, min: T? = null, max: T? = null, violation: (T, T) -> T = ::defaultViolation)
an initial value of the property.

Functions

getValue
Link copied to clipboard
operator fun getValue(obj: Any, prop: KProperty<*>): T
Returns property value within the range.
setValue
Link copied to clipboard
operator fun setValue(obj: Any, prop: KProperty<*>, newValue: T)
Sets a new property value with validation.