diff --git a/README.md b/README.md
index f8d4dfa..9ebd9e2 100644
--- a/README.md
+++ b/README.md
@@ -20,14 +20,14 @@ xtool 是一个小小的 Java 工具集,遵循简单、可靠的原则,不
com.igeeksky.xtool
xtool
- 1.1.4
+ 1.2.0
```
### 2.2.Gradle
```groovy
-implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.1.4'
+implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.0'
```
### 2.3.编译安装
@@ -80,125 +80,126 @@ mvn clean install
## 4. 更新日志
+### 1.2.0
+
+* 调整 Futures 接口参数
+
### 1.1.3
-1. add AsyncCloseable API
+* add `AsyncCloseable`
### 1.1.2
-1. add Shutdown API
+* add `GracefulShutdown`
### 1.1.1
-1. add RingBuffer
-2. add FuturesTest
+* add `RingBuffer`
+* add `Futures` testcase
### 1.1.0
-1. remove @ParameterNames
-2. add ObjectUtils
-3. tuple move to root package
+* remove `@ParameterNames`
+* add `ObjectUtils`
+* tuple move to root package
### 1.0.22
-1. add ImmutableByteArray
+* add `ImmutableByteArray`
### 1.0.21
-1. KeyValue 和 ByteArray 增加静态方法
+* `KeyValue` 和 `ByteArray` 增加静态方法
### 1.0.20
-1. Futures 增加 awaitAll 方法
+* `Futures` 增加 awaitAll 方法
### 1.0.19
-1. 优化 SimpleJSON 实现:如果 field 为 public,即使无 readMethod,也读取属性值
+* 优化 `SimpleJSON` 实现:如果 field 为 public,即使无 readMethod,也读取属性值
### 1.0.18
-1. 优化 RandomUtils 实现,通过 threadId 计算 index ,并获取数组对应 index 的 Random 实例
+* 优化 `RandomUtils` 实现,通过 threadId 计算 index ,并获取数组对应 index 的 Random 实例
### 1.0.17
-1. 优化 SimpleJSON 实现,仅获取 readMethod,支持非标准 JavaBean
+* 优化 `SimpleJSON` 实现,仅获取 readMethod,支持非标准 JavaBean
### 1.0.16
-1. remove ThreadLocalRandom,change to Random[]
-
-### 1.0.15
-
-1. add ArrayUtils.fill
+* remove `ThreadLocalRandom`,change to Random[]
### 1.0.14
-1. add Codec
-2. add Compressor
+* add `Codec`
+
+* add `Compressor`
### 1.0.13
-1. add Futures
-2. add ByteArray
-3. add KeyValue & ExpireKeyValue
+* add `Futures`
-### 1.0.12
+* add `ByteArray`
-1. 修改部分文档说明
+* add `KeyValue` & `ExpireKeyValue`
### 1.0.11
-1. 添加 ConcurrentHashSet
-2. 添加 PlatformThreadFactory
-3. 添加 VirtualThreadFactory
-4. 升级为支持 JDK 21,不再支持 JDK 17
+* 添加 `ConcurrentHashSet`
+* 添加 `PlatformThreadFactory`
+* 添加 `VirtualThreadFactory`
+* 升级为支持 JDK 21,不再支持 JDK 17
### 1.0.10
-1. 添加 SimpleJSON(仅实现对象转 JSONString)
-2. 升级为支持 JDK 17,不再支持 JDK 8
+* 添加 `SimpleJSON`(仅实现对象转 JSONString)
+* 升级为支持 JDK 17,不再支持 JDK 8
### 1.0.9
-1. 添加 RandomUtils
+* 添加 `RandomUtils`
### 1.0.8
-1. 添加 Maps.newHashMap方法
+* 添加 Maps.newHashMap方法
### 1.0.7
-1. 添加 IOUtils.closeQuietly方法
+* 添加 IOUtils.closeQuietly方法
### 1.0.6
-1. Found 删除 node 字段,NodeHelper 增加精确匹配方法
+* `Found` 删除 node 字段,`NodeHelper` 增加精确匹配方法
### 1.0.5
-1. 调整部分方法返回值
+* 调整部分方法返回值
### 1.0.4
-1. 增加测试用例
-2. 编写参考文档
-3. 调整部分代码
+* 增加测试用例
+
+* 编写参考文档
+
+* 调整部分代码
### 1.0.3
-1. 调整DigestUtils默认小写
+* 调整 `DigestUtils` 默认小写
### 1.0.2
-1. 补充完整注释
+* 补充注释
### 1.0.1
-1. 增加测试用例
-2. 删除 Lists类
+* 增加测试用例
+* 删除 `Lists`
### 1.0.0
-1. 添加常用工具类
-2. 添加 ConcurrentHashTrie 字典树
+* 常用工具
+* 字典树
diff --git a/docs/Reference.md b/docs/Reference.md
index 630d2be..18c5824 100644
--- a/docs/Reference.md
+++ b/docs/Reference.md
@@ -1,6 +1,6 @@
## xtool 参考文档
-Author: [Patrick.Lau](mailto:patricklauxx@gmail.com) Version: 1.1.4
+Author: [Patrick.Lau](mailto:patricklauxx@gmail.com) Version: 1.2.0
[](https://www.apache.org/licenses/LICENSE-2.0.html) [](https://github.com/patricklaux/xtool/releases) [](https://search.maven.org/search?q=g:%22com.igeeksky.xtool%22%20AND%20a:%22xtool%22) [](https://codecov.io/gh/patricklaux/xtool) [](https://github.com/patricklaux/xtool/commits) [](https://gitter.im/igeeksky/xtool?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -26,14 +26,14 @@ xtool 是一个小小的 Java 工具集,遵循简单、可靠的原则,不
com.igeeksky.xtool
xtool
- 1.1.4
+ 1.2.0
```
#### 1.2.2.Gradle
```groovy
-implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.1.4'
+implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.0'
```
#### 1.2.3.编译安装
diff --git a/pom.xml b/pom.xml
index e552035..0fb9fb7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.igeeksky.xtool
xtool
- 1.1.4
+ 1.2.0
xtool
xtool is a very small set of Java tools.
https://github.com/patricklaux/xtool
diff --git a/src/main/java/com/igeeksky/xtool/core/concurrent/Futures.java b/src/main/java/com/igeeksky/xtool/core/concurrent/Futures.java
index 21a3693..5fa74b9 100644
--- a/src/main/java/com/igeeksky/xtool/core/concurrent/Futures.java
+++ b/src/main/java/com/igeeksky/xtool/core/concurrent/Futures.java
@@ -7,18 +7,38 @@
import java.util.concurrent.TimeoutException;
/**
+ * Future 工具类
+ *
* @author Patrick.Lau
* @since 1.0.13 2024/8/13
*/
-public class Futures {
+public final class Futures {
+
+ /**
+ * 私有构造器,禁止实例化
+ */
+ private Futures() {
+ }
/**
* 等待所有任务完成(无时间限制)
+ *
+ * 默认从 0 开始检查并等待任务完成
*
* @param futures 任务列表
*/
public static void awaitAll(Future>[] futures) {
- int i = 0, len = futures.length;
+ awaitAll(futures, 0);
+ }
+
+ /**
+ * 等待所有任务完成(无时间限制)
+ *
+ * @param futures 任务列表
+ * @param start 起始位置,从此位置开始检查并等待任务完成
+ */
+ public static void awaitAll(Future>[] futures, int start) {
+ int i = start, len = futures.length;
try {
for (; i < len; i++) {
Future> future = futures[i];
@@ -36,11 +56,23 @@ public static void awaitAll(Future>[] futures) {
/**
* 等待所有任务完成(无时间限制)
+ *
+ * 默认从 0 开始检查并等待任务完成
*
* @param futures 任务列表
*/
public static void awaitAll(ArrayList> futures) {
- int i = 0, len = futures.size();
+ awaitAll(futures, 0);
+ }
+
+ /**
+ * 等待所有任务完成(无时间限制)
+ *
+ * @param futures 任务列表
+ * @param start 起始位置,从此位置开始检查并等待任务完成
+ */
+ public static void awaitAll(ArrayList> futures, int start) {
+ int i = start, len = futures.size();
try {
for (; i < len; i++) {
Future> future = futures.get(i);
@@ -56,6 +88,20 @@ public static void awaitAll(ArrayList> futures) {
}
}
+ /**
+ * 等待所有任务完成(有时间限制)
+ *
+ * 默认从 0 开始检查并等待任务完成
+ *
+ * @param futures 任务列表
+ * @param timeout 超时时间
+ * @param unit 时间单位
+ * @return 剩余未完成的任务的起始位置
+ */
+ public static int awaitAll(Future>[] futures, long timeout, TimeUnit unit) {
+ return awaitAll(futures, timeout, unit, 0);
+ }
+
/**
* 等待所有任务完成(有时间限制)
*
@@ -65,7 +111,7 @@ public static void awaitAll(ArrayList> futures) {
* @param futures 任务列表
* @return 剩余未完成任务的起始位置
*/
- public static int awaitAll(long timeout, TimeUnit unit, int start, Future>[] futures) {
+ public static int awaitAll(Future>[] futures, long timeout, TimeUnit unit, int start) {
int i = start, len = futures.length;
try {
long nanos = unit.toNanos(timeout);
@@ -96,14 +142,28 @@ public static int awaitAll(long timeout, TimeUnit unit, int start, Future>[] f
/**
* 等待所有任务完成(有时间限制)
+ *
+ * 默认从 0 开始检查并等待任务完成
*
+ * @param futures 任务列表
* @param timeout 超时时间
* @param unit 时间单位
- * @param start 起始位置,从此位置开始检查任务是否已完成,如未完成,则等待给定的时间
+ * @return 剩余未完成的任务的起始位置
+ */
+ public static int awaitAll(ArrayList> futures, long timeout, TimeUnit unit) {
+ return awaitAll(futures, timeout, unit, 0);
+ }
+
+ /**
+ * 等待所有任务完成(有时间限制)
+ *
* @param futures 任务列表
+ * @param timeout 超时时间
+ * @param unit 时间单位
+ * @param start 起始位置,从此位置开始检查任务是否已完成,如未完成,则等待给定的时间
* @return 剩余未完成的任务的起始位置
*/
- public static int awaitAll(long timeout, TimeUnit unit, int start, ArrayList> futures) {
+ public static int awaitAll(ArrayList> futures, long timeout, TimeUnit unit, int start) {
int i = start, len = futures.size();
try {
long nanos = unit.toNanos(timeout);
@@ -133,12 +193,24 @@ public static int awaitAll(long timeout, TimeUnit unit, int start, ArrayList
+ * 默认从 0 开始检查是否还有未完成的任务
*
- * @param start 起始位置,从此位置开始检查任务是否已完成
* @param futures 任务列表
- * @return 剩余未完成的任务的起始位置
+ * @return 剩余未完成任务的起始位置
*/
- public static int checkAll(int start, ArrayList> futures) {
+ public static int checkAll(ArrayList> futures) {
+ return checkAll(futures, 0);
+ }
+
+ /**
+ * 检查是否还有未完成的任务
+ *
+ * @param futures 任务列表
+ * @param start 起始位置,从此位置开始检查任务是否已完成
+ * @return 剩余未完成任务的起始位置
+ */
+ public static int checkAll(ArrayList> futures, int start) {
int i = start, len = futures.size();
for (; i < len; i++) {
Future> future = futures.get(i);
@@ -152,6 +224,18 @@ public static int checkAll(int start, ArrayList> futures) {
return i;
}
+ /**
+ * 检查是否还有未完成的任务
+ *
+ * 默认从 0 开始检查是否还有未完成的任务
+ *
+ * @param futures 任务列表
+ * @return 剩余未完成任务的起始位置
+ */
+ public static int checkAll(Future>[] futures) {
+ return checkAll(futures, 0);
+ }
+
/**
* 检查是否还有未完成的任务
*
@@ -159,7 +243,7 @@ public static int checkAll(int start, ArrayList> futures) {
* @param futures 任务列表
* @return 剩余未完成的任务的起始位置
*/
- public static int checkAll(int start, Future>[] futures) {
+ public static int checkAll(Future>[] futures, int start) {
int i = start, len = futures.length;
for (; i < len; i++) {
Future> future = futures[i];
@@ -175,11 +259,24 @@ public static int checkAll(int start, Future>[] futures) {
/**
* 取消所有未完成的任务
+ *
+ * 默认从 0 开始取消未完成的任务
*
- * @param start 起始位置,从此位置开始取消未完成的任务
- * @param futures 任务列表
+ * @param futures 任务列表
+ * @param mayInterruptIfRunning 是否中断正在运行的任务
*/
- public static void cancelAll(int start, Future>[] futures, boolean mayInterruptIfRunning) {
+ public static void cancelAll(Future>[] futures, boolean mayInterruptIfRunning) {
+ cancelAll(futures, mayInterruptIfRunning, 0);
+ }
+
+ /**
+ * 取消所有未完成的任务
+ *
+ * @param futures 任务列表
+ * @param mayInterruptIfRunning 是否中断正在运行的任务
+ * @param start 起始位置,从此位置开始取消未完成的任务
+ */
+ public static void cancelAll(Future>[] futures, boolean mayInterruptIfRunning, int start) {
int i = start, len = futures.length;
for (; i < len; i++) {
Future> future = futures[i];
@@ -194,11 +291,24 @@ public static void cancelAll(int start, Future>[] futures, boolean mayInterrup
/**
* 取消所有未完成的任务
+ *
+ * 默认从 0 开始取消未完成的任务
*
- * @param start 起始位置,从此位置开始取消未完成的任务
- * @param futures 任务列表
+ * @param futures 任务列表
+ * @param mayInterruptIfRunning 是否中断正在运行的任务
+ */
+ public static void cancelAll(ArrayList> futures, boolean mayInterruptIfRunning) {
+ cancelAll(futures, mayInterruptIfRunning, 0);
+ }
+
+ /**
+ * 取消所有未完成的任务
+ *
+ * @param futures 任务列表
+ * @param mayInterruptIfRunning 是否中断正在运行的任务
+ * @param start 起始位置,从此位置开始取消未完成的任务
*/
- public static void cancelAll(int start, ArrayList> futures, boolean mayInterruptIfRunning) {
+ public static void cancelAll(ArrayList> futures, boolean mayInterruptIfRunning, int start) {
int i = start, len = futures.size();
for (; i < len; i++) {
Future> future = futures.get(i);
diff --git a/src/test/java/com/igeeksky/xtool/core/concurrent/FuturesTest.java b/src/test/java/com/igeeksky/xtool/core/concurrent/FuturesTest.java
index 0ec9b54..3dfe546 100644
--- a/src/test/java/com/igeeksky/xtool/core/concurrent/FuturesTest.java
+++ b/src/test/java/com/igeeksky/xtool/core/concurrent/FuturesTest.java
@@ -72,7 +72,7 @@ public void awaitAll_Timeout_AllCompletedBeforeTimeout() {
when(future2.isDone()).thenReturn(true);
when(future3.isDone()).thenReturn(true);
- int result = Futures.awaitAll(1000, TimeUnit.MILLISECONDS, 0, new Future>[]{future1, future2, future3});
+ int result = Futures.awaitAll(new Future>[]{future1, future2, future3}, 1000, TimeUnit.MILLISECONDS, 0);
assertEquals(3, result);
}
@@ -82,7 +82,7 @@ public void checkAll_AllCompleted_ReturnsLength() {
when(future2.isDone()).thenReturn(true);
when(future3.isDone()).thenReturn(true);
- int result = Futures.checkAll(0, new Future>[]{future1, future2, future3});
+ int result = Futures.checkAll(new Future>[]{future1, future2, future3});
assertEquals(3, result);
}
@@ -92,13 +92,13 @@ public void checkAll_NotAllCompleted_ReturnsFirstUncompletedIndex() {
when(future2.isDone()).thenReturn(false);
when(future3.isDone()).thenReturn(true);
- int result = Futures.checkAll(0, new Future>[]{future1, future2, future3});
+ int result = Futures.checkAll(new Future>[]{future1, future2, future3});
assertEquals(1, result);
}
@Test
public void checkAll_EmptyList_ReturnsZero() {
- int result = Futures.checkAll(0, new Future>[]{});
+ int result = Futures.checkAll(new Future>[]{});
assertEquals(0, result);
}
@@ -108,7 +108,7 @@ public void cancelAll_AllCompleted_NoCancellation() {
when(future2.isDone()).thenReturn(true);
when(future3.isDone()).thenReturn(true);
- Futures.cancelAll(0, new Future>[]{future1, future2, future3}, false);
+ Futures.cancelAll(new Future>[]{future1, future2, future3}, false);
verify(future1, never()).cancel(anyBoolean());
verify(future2, never()).cancel(anyBoolean());
@@ -117,12 +117,12 @@ public void cancelAll_AllCompleted_NoCancellation() {
@Test
public void cancelAll_EmptyList_NoCancellation() {
- Futures.cancelAll(0, new Future>[]{}, false);
+ Futures.cancelAll(new Future>[]{}, false);
}
@Test
public void cancelAll_ListWithNulls_NoCancellation() {
- Futures.cancelAll(0, new Future>[]{future1, null, future2}, false);
+ Futures.cancelAll(new Future>[]{future1, null, future2}, false);
}
}