mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
add method
This commit is contained in:
parent
2ac275dd8f
commit
8d18dbf7a5
@ -1,5 +1,7 @@
|
|||||||
package cn.hutool.cron.pattern.matcher;
|
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 cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -7,28 +9,50 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将表达式中的数字值列表转换为Boolean数组,匹配时匹配相应数组位
|
* 将表达式中的数字值列表转换为Boolean数组,匹配时匹配相应数组位
|
||||||
* @author Looly
|
|
||||||
*
|
*
|
||||||
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class BoolArrayValueMatcher implements ValueMatcher{
|
public class BoolArrayValueMatcher implements ValueMatcher {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户定义此字段的最小值
|
||||||
|
*/
|
||||||
|
private final int minValue;
|
||||||
private final boolean[] bValues;
|
private final boolean[] bValues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param intValueList 匹配值列表
|
||||||
|
*/
|
||||||
public BoolArrayValueMatcher(List<Integer> intValueList) {
|
public BoolArrayValueMatcher(List<Integer> intValueList) {
|
||||||
|
Assert.isTrue(CollUtil.isNotEmpty(intValueList), "Values must be not empty!");
|
||||||
bValues = new boolean[Collections.max(intValueList) + 1];
|
bValues = new boolean[Collections.max(intValueList) + 1];
|
||||||
|
int min = Integer.MAX_VALUE;
|
||||||
for (Integer value : intValueList) {
|
for (Integer value : intValueList) {
|
||||||
|
min = Math.min(min, value);
|
||||||
bValues[value] = true;
|
bValues[value] = true;
|
||||||
}
|
}
|
||||||
|
this.minValue = min;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean match(Integer value) {
|
public boolean match(Integer value) {
|
||||||
if(null == value || value >= bValues.length){
|
if (null == value || value >= bValues.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return bValues[value];
|
return bValues[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表达式定义的最小值
|
||||||
|
*
|
||||||
|
* @return 最小值
|
||||||
|
*/
|
||||||
|
public int getMinValue() {
|
||||||
|
return this.minValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return StrUtil.format("Matcher:{}", new Object[]{this.bValues});
|
return StrUtil.format("Matcher:{}", new Object[]{this.bValues});
|
||||||
|
Loading…
Reference in New Issue
Block a user