You can make one generic function to check all string are valid or not.
You can take n number of strings as vararg and can check each of them by making one util or extension function.
Here is Util class
object StringUtils {
fun isAllValid(vararg args: String?) : Boolean {
//checking all strings passed and if a single string is not valid returning false.
args.forEach {
if(isNotValid(it))
return false
}
return true
}
fun isValid(string: String?): Boolean {
return string != null && string.isNotEmpty() && string.isNotBlank()
}
fun isNotValid(string: String?) : Boolean {
return isValid(string).not()
}
}
and you can use like this
fun changeUserAccount(
userName: String,
password: String,
confirmPassword: String,
realName: String,
accountEmail: String,
applicationContext: Context
) {
//You can pass n number of strings.
val isAllStringsValid = StringUtils.isAllValid(userName,password,confirmPassword,realName,accountEmail)
//this returns true
StringUtils.isAllValid("hi","how","are","you","?")
//this returns false
StringUtils.isAllValid("","how","are","you","?")
//this returns false
StringUtils.isAllValid(null,"how","are","you","?")
//this returns false
StringUtils.isAllValid("","how","are","you","?")
}
isEmpty()for example:userName.isEmpty()kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/is-empty.html