From 8d18dbf7a5178d43b5830f3e365cdc9fa61e201d Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 22 Mar 2022 13:23:32 +0800 Subject: [PATCH] add method --- .../matcher/BoolArrayValueMatcher.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/hutool-cron/src/main/java/cn/hutool/cron/pattern/matcher/BoolArrayValueMatcher.java b/hutool-cron/src/main/java/cn/hutool/cron/pattern/matcher/BoolArrayValueMatcher.java index 4ffff81e1..a95fb3b67 100644 --- a/hutool-cron/src/main/java/cn/hutool/cron/pattern/matcher/BoolArrayValueMatcher.java +++ b/hutool-cron/src/main/java/cn/hutool/cron/pattern/matcher/BoolArrayValueMatcher.java @@ -1,5 +1,7 @@ package cn.hutool.cron.pattern.matcher; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import java.util.Collections; @@ -7,28 +9,50 @@ import java.util.List; /** * 将表达式中的数字值列表转换为Boolean数组,匹配时匹配相应数组位 - * @author Looly * + * @author Looly */ -public class BoolArrayValueMatcher implements ValueMatcher{ - +public class BoolArrayValueMatcher implements ValueMatcher { + + /** + * 用户定义此字段的最小值 + */ + private final int minValue; private final boolean[] bValues; - + + /** + * 构造 + * + * @param intValueList 匹配值列表 + */ public BoolArrayValueMatcher(List intValueList) { + Assert.isTrue(CollUtil.isNotEmpty(intValueList), "Values must be not empty!"); bValues = new boolean[Collections.max(intValueList) + 1]; + int min = Integer.MAX_VALUE; for (Integer value : intValueList) { + min = Math.min(min, value); bValues[value] = true; } + this.minValue = min; } @Override public boolean match(Integer value) { - if(null == value || value >= bValues.length){ + if (null == value || value >= bValues.length) { return false; } return bValues[value]; } - + + /** + * 获取表达式定义的最小值 + * + * @return 最小值 + */ + public int getMinValue() { + return this.minValue; + } + @Override public String toString() { return StrUtil.format("Matcher:{}", new Object[]{this.bValues});