mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add methods
This commit is contained in:
parent
07a11f2baa
commit
bb1e4ba76a
@ -9,7 +9,7 @@
|
||||
* 【core 】 增加AsyncUtil(pr#457@Gitee)
|
||||
* 【http 】 增加HttpResource(issue#1943@Github)
|
||||
* 【http 】 增加BytesBody、FormUrlEncodedBody
|
||||
* 【cron 】 TaskTable.remove增加返回值
|
||||
* 【cron 】 TaskTable.remove增加返回值(issue#I4HX3B@Gitee)
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复FileResource构造fileName参数无效问题(issue#1942@Github)
|
||||
|
||||
|
@ -25,11 +25,11 @@ public class ConsoleTable {
|
||||
/**
|
||||
* 表格头信息
|
||||
*/
|
||||
private final List<List<String>> HEADER_LIST = new ArrayList<>();
|
||||
private final List<List<String>> headerList = new ArrayList<>();
|
||||
/**
|
||||
* 表格体信息
|
||||
*/
|
||||
private final List<List<String>> BODY_LIST = new ArrayList<>();
|
||||
private final List<List<String>> bodyList = new ArrayList<>();
|
||||
/**
|
||||
* 每列最大字符个数
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class ConsoleTable {
|
||||
}
|
||||
List<String> l = new ArrayList<>();
|
||||
fillColumns(l, titles);
|
||||
HEADER_LIST.add(l);
|
||||
headerList.add(l);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ public class ConsoleTable {
|
||||
*/
|
||||
public ConsoleTable addBody(String... values) {
|
||||
List<String> l = new ArrayList<>();
|
||||
BODY_LIST.add(l);
|
||||
bodyList.add(l);
|
||||
fillColumns(l, values);
|
||||
return this;
|
||||
}
|
||||
@ -101,9 +101,9 @@ public class ConsoleTable {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
fillBorder(sb);
|
||||
fillRow(sb, HEADER_LIST);
|
||||
fillRow(sb, headerList);
|
||||
fillBorder(sb);
|
||||
fillRow(sb, BODY_LIST);
|
||||
fillRow(sb, bodyList);
|
||||
fillBorder(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
@ -158,4 +158,4 @@ public class ConsoleTable {
|
||||
Console.print(toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,10 @@ public class CronUtil {
|
||||
* 移除任务
|
||||
*
|
||||
* @param schedulerId 任务ID
|
||||
* @return 是否移除成功,{@code false}表示未找到对应ID的任务
|
||||
*/
|
||||
public static void remove(String schedulerId) {
|
||||
scheduler.deschedule(schedulerId);
|
||||
public static boolean remove(String schedulerId) {
|
||||
return scheduler.descheduleWithStatus(schedulerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,10 +289,21 @@ public class Scheduler implements Serializable {
|
||||
* @return this
|
||||
*/
|
||||
public Scheduler deschedule(String id) {
|
||||
this.taskTable.remove(id);
|
||||
descheduleWithStatus(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除Task,并返回是否移除成功
|
||||
*
|
||||
* @param id Task的ID
|
||||
* @return 是否移除成功,{@code false}表示未找到对应ID的任务
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public boolean descheduleWithStatus(String id) {
|
||||
return this.taskTable.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Task执行的时间规则
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.cron;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.cron.pattern.CronPattern;
|
||||
import cn.hutool.cron.task.CronTask;
|
||||
import cn.hutool.cron.task.Task;
|
||||
@ -271,6 +272,16 @@ public class TaskTable implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = StrUtil.builder();
|
||||
for (int i = 0; i < size; i++) {
|
||||
builder.append(StrUtil.format("[{}] [{}] [{}]\n",
|
||||
ids.get(i), patterns.get(i), tasks.get(i)));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果时间匹配则执行相应的Task,无锁
|
||||
*
|
||||
|
21
hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java
Normal file
21
hutool-cron/src/test/java/cn/hutool/cron/TaskTableTest.java
Normal file
@ -0,0 +1,21 @@
|
||||
package cn.hutool.cron;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.cron.pattern.CronPattern;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TaskTableTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void toStringTest(){
|
||||
final TaskTable taskTable = new TaskTable();
|
||||
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/10 * * * * *"), ()-> Console.log("Task 1"));
|
||||
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/20 * * * * *"), ()-> Console.log("Task 2"));
|
||||
taskTable.add(IdUtil.fastUUID(), new CronPattern("*/30 * * * * *"), ()-> Console.log("Task 3"));
|
||||
|
||||
Console.log(taskTable);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user