Browse Source

Validator.validateString implementation with function

pull/10328/head
Sergey Matvienko 2 years ago
parent
commit
c8abb9ed8e
  1. 13
      dao/src/main/java/org/thingsboard/server/dao/service/Validator.java

13
dao/src/main/java/org/thingsboard/server/dao/service/Validator.java

@ -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

Loading…
Cancel
Save