Validator.validateString implementation with function

This commit is contained in:
Sergey Matvienko 2024-03-07 19:01:10 +01:00
parent 71583c5a29
commit c8abb9ed8e

View File

@ -27,6 +27,7 @@ import org.thingsboard.server.dao.exception.IncorrectParameterException;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import java.util.regex.Pattern;
public class Validator {
@ -59,6 +60,18 @@ public class Validator {
}
}
/*
* This method validate <code>String</code> string. If string is invalid than throw
* <code>IncorrectParameterException</code> exception
*
* @param val the value
* @param errorMessageFunction the error message function that apply value
*/
public static void validateString(String val, Function<String, String> errorMessageFunction) {
if (val == null || val.isEmpty()) {
throw new IncorrectParameterException(errorMessageFunction.apply(val));
}
}
/**
* This method validate <code>long</code> value. If value isn't positive than throw