![JAR search and dependency download from the Maven repository](/logo.png)
commonMain.com.harmony.kotlin.data.validator.Validator.kt Maven / Gradle / Ivy
package com.harmony.kotlin.data.validator
import com.harmony.kotlin.data.datasource.GetDataSource
import com.harmony.kotlin.data.datasource.GetDataSourceValidator
import com.harmony.kotlin.data.validator.vastra.strategies.ValidationStrategyEntity
import kotlin.jvm.JvmName
interface Validator {
fun isValid(value: T): Boolean
}
/** Validator for list **/
class ListValidator(private val singleValueValidator: Validator) : Validator> {
/** Validates all object of the list, if one of them is not valid the whole list is not valid **/
override fun isValid(value: List): Boolean {
if (value.isEmpty()) return false
value.forEach { if (!singleValueValidator.isValid(it)) return false }
return true
}
}
/**
* Create a validator for lists
*/
fun Validator.toListValidator(): Validator> {
val singleValueMapper = this
return ListValidator(singleValueMapper)
}
/**
* Helper function to create a GetDataSourceValidator from a Validator
*/
fun Validator.toGetDataSourceValidator(getDataSource: GetDataSource): GetDataSourceValidator {
return GetDataSourceValidator(getDataSource, this)
}
/**
* Helper function to create a GetDataSourceValidator from a Validator
*/
@JvmName("toGetDataSourceListValidator")
fun Validator>.toGetDataSourceValidator(getDataSource: GetDataSource>): GetDataSourceValidator> {
return GetDataSourceValidator(getDataSource, this)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy