(Re)introduce CronExpression::isValidExpression
This commit introduces CronExpression::isValidExpression, which was also present on the deprecated CronSequenceGenerator. Closes: gh-26996
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -202,6 +202,25 @@ public final class CronExpression {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given string represents a valid cron expression.
|
||||
* @param expression the expression to evaluate
|
||||
* @return {@code true} if the given expression is a valid cron expression
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public static boolean isValidExpression(@Nullable String expression) {
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
parse(expression);
|
||||
return true;
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static String resolveMacros(String expression) {
|
||||
expression = expression.trim();
|
||||
|
||||
Reference in New Issue
Block a user