This commit is contained in:
Looly
2022-06-18 23:03:06 +08:00
parent b0ed5bea9a
commit e9cf532af0
40 changed files with 327 additions and 415 deletions

View File

@@ -12,7 +12,7 @@ public class AlwaysTrueMatcher implements PartMatcher {
public static AlwaysTrueMatcher INSTANCE = new AlwaysTrueMatcher();
@Override
public boolean match(final Integer t) {
public boolean test(final Integer t) {
return true;
}

View File

@@ -37,7 +37,7 @@ public class BoolArrayMatcher implements PartMatcher {
}
@Override
public boolean match(final Integer value) {
public boolean test(final Integer value) {
if (null == value || value >= bValues.length) {
return false;
}

View File

@@ -30,9 +30,9 @@ public class DayOfMonthMatcher extends BoolArrayMatcher {
* @return 是否匹配
*/
public boolean match(final int value, final int month, final boolean isLeapYear) {
return (super.match(value) // 在约定日范围内的某一天
return (super.test(value) // 在约定日范围内的某一天
//匹配器中用户定义了最后一天31表示最后一天
|| (value > 27 && match(31) && isLastDayOfMonth(value, month, isLeapYear)));
|| (value > 27 && test(31) && isLastDayOfMonth(value, month, isLeapYear)));
}
/**

View File

@@ -1,6 +1,6 @@
package cn.hutool.cron.pattern.matcher;
import cn.hutool.core.lang.func.Matcher;
import java.util.function.Predicate;
/**
* 表达式中的某个位置部分匹配器<br>
@@ -8,7 +8,7 @@ import cn.hutool.core.lang.func.Matcher;
*
* @author Looly
*/
public interface PartMatcher extends Matcher<Integer> {
public interface PartMatcher extends Predicate<Integer> {
/**
* 获取指定值之后的匹配值,也可以是指定值本身

View File

@@ -80,7 +80,7 @@ public class PatternMatcher {
* @since 5.8.0
*/
public boolean matchWeek(final int dayOfWeekValue) {
return matchers[5].match(dayOfWeekValue);
return matchers[5].test(dayOfWeekValue);
}
/**
@@ -96,13 +96,13 @@ public class PatternMatcher {
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
private boolean match(final int second, final int minute, final int hour, final int dayOfMonth, final int month, final int dayOfWeek, final int year) {
return ((second < 0) || matchers[0].match(second)) // 匹配秒非秒匹配模式下始终返回true
&& matchers[1].match(minute)// 匹配分
&& matchers[2].match(hour)// 匹配时
return ((second < 0) || matchers[0].test(second)) // 匹配秒非秒匹配模式下始终返回true
&& matchers[1].test(minute)// 匹配分
&& matchers[2].test(hour)// 匹配时
&& matchDayOfMonth(matchers[3], dayOfMonth, month, Year.isLeap(year))// 匹配日
&& matchers[4].match(month) // 匹配月
&& matchers[5].match(dayOfWeek)// 匹配周
&& matchers[6].match(year);// 匹配年
&& matchers[4].test(month) // 匹配月
&& matchers[5].test(dayOfWeek)// 匹配周
&& matchers[6].test(year);// 匹配年
}
/**
@@ -117,7 +117,7 @@ public class PatternMatcher {
private static boolean matchDayOfMonth(final PartMatcher matcher, final int dayOfMonth, final int month, final boolean isLeapYear) {
return ((matcher instanceof DayOfMonthMatcher) //
? ((DayOfMonthMatcher) matcher).match(dayOfMonth, month, isLeapYear) //
: matcher.match(dayOfMonth));
: matcher.test(dayOfMonth));
}
//endregion

View File

@@ -18,7 +18,7 @@ public class YearValueMatcher implements PartMatcher {
}
@Override
public boolean match(final Integer t) {
public boolean test(final Integer t) {
return valueList.contains(t);
}