mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add method
This commit is contained in:
parent
9c6339a99c
commit
fa4f71a112
@ -23,6 +23,7 @@
|
|||||||
* 【core 】 DateUtil增加rangeToList重载(pr#1925@Github)
|
* 【core 】 DateUtil增加rangeToList重载(pr#1925@Github)
|
||||||
* 【core 】 CollUtil增加safeContains方法(pr#1926@Github)
|
* 【core 】 CollUtil增加safeContains方法(pr#1926@Github)
|
||||||
* 【core 】 ActualTypeMapperPool增加getStrKeyMap方法(pr#447@Gitee)
|
* 【core 】 ActualTypeMapperPool增加getStrKeyMap方法(pr#447@Gitee)
|
||||||
|
* 【core 】 TreeUtil增加walk方法(pr#1932@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
* 【core 】 修复UrlBuilder.addPath歧义问题(issue#1912@Github)
|
||||||
|
@ -12,6 +12,7 @@ import java.io.StringWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过转换器将你的实体转化为TreeNodeMap节点实体 属性都存在此处,属性有序,可支持排序
|
* 通过转换器将你的实体转化为TreeNodeMap节点实体 属性都存在此处,属性有序,可支持排序
|
||||||
@ -174,6 +175,20 @@ import java.util.List;
|
|||||||
return (List<Tree<T>>) this.get(treeNodeConfig.getChildrenKey());
|
return (List<Tree<T>>) this.get(treeNodeConfig.getChildrenKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归树并处理子树下的节点:
|
||||||
|
*
|
||||||
|
* @param consumer 节点处理器
|
||||||
|
* @since 5.7.16
|
||||||
|
*/
|
||||||
|
public void walk(Consumer<Tree<T>> consumer) {
|
||||||
|
consumer.accept(this);
|
||||||
|
final List<Tree<T>> children = getChildren();
|
||||||
|
if(CollUtil.isNotEmpty(children)){
|
||||||
|
children.forEach((tree)-> tree.walk(consumer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置子节点,设置后会覆盖所有原有子节点
|
* 设置子节点,设置后会覆盖所有原有子节点
|
||||||
*
|
*
|
||||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,4 +67,13 @@ public class TreeTest {
|
|||||||
|
|
||||||
Assert.assertEquals(treeNodes.size(), 2);
|
Assert.assertEquals(treeNodes.size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void walkTest(){
|
||||||
|
List<String> ids = new ArrayList<>();
|
||||||
|
final Tree<String> tree = TreeUtil.buildSingle(nodeList, "0");
|
||||||
|
tree.walk((tr)-> ids.add(tr.getId()));
|
||||||
|
|
||||||
|
Assert .assertEquals(7, ids.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ import java.util.TimeZone;
|
|||||||
* 注意:
|
* 注意:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* 当isMatchSecond为<code>true</code>时才会匹配秒部分
|
* 当isMatchSecond为{@code true}时才会匹配秒部分
|
||||||
* 默认都是关闭的
|
* 默认都是关闭的
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
@ -124,7 +124,7 @@ public class CronPattern {
|
|||||||
*
|
*
|
||||||
* @param millis 时间毫秒数
|
* @param millis 时间毫秒数
|
||||||
* @param isMatchSecond 是否匹配秒
|
* @param isMatchSecond 是否匹配秒
|
||||||
* @return 如果匹配返回 <code>true</code>, 否则返回 <code>false</code>
|
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean match(long millis, boolean isMatchSecond) {
|
public boolean match(long millis, boolean isMatchSecond) {
|
||||||
return match(TimeZone.getDefault(), millis, isMatchSecond);
|
return match(TimeZone.getDefault(), millis, isMatchSecond);
|
||||||
@ -136,7 +136,7 @@ public class CronPattern {
|
|||||||
* @param timezone 时区 {@link TimeZone}
|
* @param timezone 时区 {@link TimeZone}
|
||||||
* @param millis 时间毫秒数
|
* @param millis 时间毫秒数
|
||||||
* @param isMatchSecond 是否匹配秒
|
* @param isMatchSecond 是否匹配秒
|
||||||
* @return 如果匹配返回 <code>true</code>, 否则返回 <code>false</code>
|
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean match(TimeZone timezone, long millis, boolean isMatchSecond) {
|
public boolean match(TimeZone timezone, long millis, boolean isMatchSecond) {
|
||||||
final GregorianCalendar calendar = new GregorianCalendar(timezone);
|
final GregorianCalendar calendar = new GregorianCalendar(timezone);
|
||||||
@ -149,7 +149,7 @@ public class CronPattern {
|
|||||||
*
|
*
|
||||||
* @param calendar 时间
|
* @param calendar 时间
|
||||||
* @param isMatchSecond 是否匹配秒
|
* @param isMatchSecond 是否匹配秒
|
||||||
* @return 如果匹配返回 <code>true</code>, 否则返回 <code>false</code>
|
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean match(GregorianCalendar calendar, boolean isMatchSecond) {
|
public boolean match(GregorianCalendar calendar, boolean isMatchSecond) {
|
||||||
final int second = calendar.get(Calendar.SECOND);
|
final int second = calendar.get(Calendar.SECOND);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.cron.pattern;
|
package cn.hutool.cron.pattern;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.hutool.cron.CronException;
|
import cn.hutool.cron.CronException;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -18,6 +19,7 @@ public class CronPatternTest {
|
|||||||
CronPattern pattern;
|
CronPattern pattern;
|
||||||
// 任何时间匹配
|
// 任何时间匹配
|
||||||
pattern = new CronPattern("* * * * * *");
|
pattern = new CronPattern("* * * * * *");
|
||||||
|
ThreadUtil.sleep(600);
|
||||||
Assert.assertTrue(pattern.match(DateUtil.current(), true));
|
Assert.assertTrue(pattern.match(DateUtil.current(), true));
|
||||||
Assert.assertTrue(pattern.match(DateUtil.current(), false));
|
Assert.assertTrue(pattern.match(DateUtil.current(), false));
|
||||||
}
|
}
|
||||||
@ -144,7 +146,7 @@ public class CronPatternTest {
|
|||||||
@Test(expected = CronException.class)
|
@Test(expected = CronException.class)
|
||||||
public void rangeYearTest() {
|
public void rangeYearTest() {
|
||||||
// year的范围是1970~2099年,超出报错
|
// year的范围是1970~2099年,超出报错
|
||||||
CronPattern pattern = new CronPattern("0/1 * * * 1/1 ? 2020-2120");
|
new CronPattern("0/1 * * * 1/1 ? 2020-2120");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user