mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-12-07 01:28:34 +08:00
fix code
This commit is contained in:
parent
ac50c13f4f
commit
f91f0f21df
@ -21,5 +21,5 @@
|
|||||||
#--------------------------------------
|
#--------------------------------------
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
mvn versions:display-dependency-updates
|
mvn versions:display-dependency-updates
|
||||||
|
|||||||
@ -17,5 +17,5 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
exec mvn cobertura:cobertura
|
exec mvn cobertura:cobertura
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
git add .
|
git add .
|
||||||
git commit -am "$1"
|
git commit -am "$1"
|
||||||
|
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/push_dev.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/push_dev.sh
|
||||||
|
|||||||
@ -17,6 +17,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
mvn clean deploy -P release -Dhttps.protocols=TLSv1.2
|
mvn clean deploy -P release -Dhttps.protocols=TLSv1.2
|
||||||
|
|||||||
@ -17,6 +17,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
exec mvn clean source:jar javadoc:javadoc install -Dmaven.test.skip=false -Dmaven.javadoc.skip=false -Dmaven.compile.fork=true
|
exec mvn clean source:jar javadoc:javadoc install -Dmaven.test.skip=false -Dmaven.javadoc.skip=false -Dmaven.compile.fork=true
|
||||||
|
|||||||
@ -16,13 +16,13 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
bin_home="$(dirname ${BASH_SOURCE[0]})"
|
bin_home="$(dirname "${BASH_SOURCE[0]}")"
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
$bin_home/logo.sh
|
"$bin_home"/logo.sh
|
||||||
|
|
||||||
# 多模块聚合文档,生成在target/site/apidocs
|
# 多模块聚合文档,生成在target/site/apidocs
|
||||||
exec mvn javadoc:aggregate
|
mvn javadoc:aggregate
|
||||||
|
|
||||||
# 拷贝自定义的index.html到聚合文档目录
|
# 拷贝自定义的index.html到聚合文档目录
|
||||||
cp -vf $bin_home/../docs/apidocs/index.html $bin_home/../target/reports/apidocs/
|
cp -vf "$bin_home"/../docs/apidocs/index.html "$bin_home"/../target/reports/apidocs/
|
||||||
|
|||||||
@ -17,6 +17,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
exec mvn clean source:jar javadoc:javadoc package -Dmaven.test.skip=false -Dmaven.javadoc.skip=false
|
exec mvn clean source:jar javadoc:javadoc package -Dmaven.test.skip=false -Dmaven.javadoc.skip=false
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
echo -e "\033[32mCheckout to v7-master\033[0m"
|
echo -e "\033[32mCheckout to v7-master\033[0m"
|
||||||
git checkout v7-master
|
git checkout v7-master
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
# 保证当前在v7-dev分支
|
# 保证当前在v7-dev分支
|
||||||
git checkout v7-dev
|
git checkout v7-dev
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
#------------------------------------------------
|
#------------------------------------------------
|
||||||
|
|
||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname "${BASH_SOURCE[0]}")"/logo.sh
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
echo "ERROR: 新版本不存在,请指定参数1"
|
echo "ERROR: 新版本不存在,请指定参数1"
|
||||||
@ -37,4 +37,4 @@ mvn versions:set -DnewVersion=$1
|
|||||||
version=${1%-SNAPSHOT}
|
version=${1%-SNAPSHOT}
|
||||||
|
|
||||||
# 替换其它地方的版本
|
# 替换其它地方的版本
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/replaceVersion.sh "$version"
|
"$(dirname "${BASH_SOURCE[0]}")"/replaceVersion.sh "$version"
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class DeepSeekServiceImpl extends BaseAIService implements DeepSeekServic
|
|||||||
@Override
|
@Override
|
||||||
public void beta(String prompt, Consumer<String> callback) {
|
public void beta(String prompt, Consumer<String> callback) {
|
||||||
Map<String, Object> paramMap = buildBetaStreamRequestBody(prompt);
|
Map<String, Object> paramMap = buildBetaStreamRequestBody(prompt);
|
||||||
ThreadUtil.newThread(() -> sendPostStream(BETA_ENDPOINT, paramMap, callback::accept), "deepseek-beta-sse").start();
|
ThreadUtil.newThread(() -> sendPostStream(BETA_ENDPOINT, paramMap, callback), "deepseek-beta-sse").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -156,22 +156,38 @@ public class DoubaoCommon {
|
|||||||
private final String type;
|
private final String type;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param type 参数类型
|
||||||
|
* @param value 参数值
|
||||||
|
*/
|
||||||
DoubaoVideo(final String type, final Object value) {
|
DoubaoVideo(final String type, final Object value) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数类型
|
||||||
|
*
|
||||||
|
* @return 参数类型
|
||||||
|
*/
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数值
|
||||||
|
*
|
||||||
|
* @return 值
|
||||||
|
*/
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
return (String) value;
|
return value;
|
||||||
} else if (value instanceof Integer) {
|
} else if (value instanceof Integer) {
|
||||||
return (Integer) value;
|
return value;
|
||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean) {
|
||||||
return (Boolean) value;
|
return value;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,6 +59,11 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
//文生图
|
//文生图
|
||||||
private static final String IMAGES_GENERATIONS = "/images/generations";
|
private static final String IMAGES_GENERATIONS = "/images/generations";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param config 配置
|
||||||
|
*/
|
||||||
public DoubaoServiceImpl(final AIConfig config) {
|
public DoubaoServiceImpl(final AIConfig config) {
|
||||||
//初始化doubao客户端
|
//初始化doubao客户端
|
||||||
super(config);
|
super(config);
|
||||||
|
|||||||
@ -24,11 +24,22 @@ package cn.hutool.v7.ai.model.grok;
|
|||||||
*/
|
*/
|
||||||
public class GrokCommon {
|
public class GrokCommon {
|
||||||
|
|
||||||
//grok视觉参数
|
/**
|
||||||
|
* grok视觉参数
|
||||||
|
*/
|
||||||
public enum GrokVision {
|
public enum GrokVision {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
AUTO("auto"),
|
AUTO("auto"),
|
||||||
|
/**
|
||||||
|
* 低
|
||||||
|
*/
|
||||||
LOW("low"),
|
LOW("low"),
|
||||||
|
/**
|
||||||
|
* 高
|
||||||
|
*/
|
||||||
HIGH("high");
|
HIGH("high");
|
||||||
|
|
||||||
private final String detail;
|
private final String detail;
|
||||||
@ -37,6 +48,11 @@ public class GrokCommon {
|
|||||||
this.detail = detail;
|
this.detail = detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取详情
|
||||||
|
*
|
||||||
|
* @return 详情
|
||||||
|
*/
|
||||||
public String getDetail() {
|
public String getDetail() {
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,16 +27,28 @@ import cn.hutool.v7.ai.core.BaseAIConfig;
|
|||||||
*/
|
*/
|
||||||
public class GrokConfig extends BaseAIConfig {
|
public class GrokConfig extends BaseAIConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API接口地址
|
||||||
|
*/
|
||||||
private final String API_URL = "https://api.x.ai/v1";
|
private final String API_URL = "https://api.x.ai/v1";
|
||||||
|
/**
|
||||||
|
* 默认模型
|
||||||
|
*/
|
||||||
private final String DEFAULT_MODEL = Models.Grok.GROK_2_1212.getModel();
|
private final String DEFAULT_MODEL = Models.Grok.GROK_2_1212.getModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*/
|
||||||
public GrokConfig() {
|
public GrokConfig() {
|
||||||
setApiUrl(API_URL);
|
setApiUrl(API_URL);
|
||||||
setModel(DEFAULT_MODEL);
|
setModel(DEFAULT_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param apiKey API密钥
|
||||||
|
*/
|
||||||
public GrokConfig(String apiKey) {
|
public GrokConfig(String apiKey) {
|
||||||
this();
|
this();
|
||||||
setApiKey(apiKey);
|
setApiKey(apiKey);
|
||||||
|
|||||||
@ -52,6 +52,11 @@ public class GrokServiceImpl extends BaseAIService implements GrokService {
|
|||||||
//文生图
|
//文生图
|
||||||
private final String IMAGES_GENERATIONS = "/images/generations";
|
private final String IMAGES_GENERATIONS = "/images/generations";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数
|
||||||
|
*
|
||||||
|
* @param config 配置
|
||||||
|
*/
|
||||||
public GrokServiceImpl(final AIConfig config) {
|
public GrokServiceImpl(final AIConfig config) {
|
||||||
//初始化grok客户端
|
//初始化grok客户端
|
||||||
super(config);
|
super(config);
|
||||||
|
|||||||
@ -26,9 +26,8 @@ import cn.hutool.v7.swing.img.ImgUtil;
|
|||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Toolkit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -85,7 +84,7 @@ class DoubaoServiceTest {
|
|||||||
final DoubaoService doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue())
|
final DoubaoService doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue())
|
||||||
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
||||||
final String base64 = ImgUtil.toBase64DataUri(Toolkit.getDefaultToolkit().createImage("your imageUrl"), "png");
|
final String base64 = ImgUtil.toBase64DataUri(Toolkit.getDefaultToolkit().createImage("your imageUrl"), "png");
|
||||||
final String chatVision = doubaoService.chatVision("图片上有些什么?", Arrays.asList(base64));
|
final String chatVision = doubaoService.chatVision("图片上有些什么?", List.of(base64));
|
||||||
assertNotNull(chatVision);
|
assertNotNull(chatVision);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ class DoubaoServiceTest {
|
|||||||
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
||||||
|
|
||||||
String prompt = "图片上有些什么?";
|
String prompt = "图片上有些什么?";
|
||||||
List<String> images = Arrays.asList("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544");
|
List<String> images = List.of("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544");
|
||||||
|
|
||||||
// 使用AtomicBoolean作为结束标志
|
// 使用AtomicBoolean作为结束标志
|
||||||
AtomicBoolean isDone = new AtomicBoolean(false);
|
AtomicBoolean isDone = new AtomicBoolean(false);
|
||||||
@ -121,7 +120,7 @@ class DoubaoServiceTest {
|
|||||||
void testChatVision() {
|
void testChatVision() {
|
||||||
final DoubaoService doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue())
|
final DoubaoService doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue())
|
||||||
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
.setApiKey(key).setModel(Models.Doubao.DOUBAO_1_5_VISION_PRO_32K.getModel()).build(), DoubaoService.class);
|
||||||
final String chatVision = doubaoService.chatVision("图片上有些什么?", Arrays.asList("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544"),DoubaoCommon.DoubaoVision.HIGH.getDetail());
|
final String chatVision = doubaoService.chatVision("图片上有些什么?", List.of("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544"),DoubaoCommon.DoubaoVision.HIGH.getDetail());
|
||||||
assertNotNull(chatVision);
|
assertNotNull(chatVision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,13 +26,12 @@ import cn.hutool.v7.swing.img.ImgUtil;
|
|||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Toolkit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
class GrokServiceTest {
|
class GrokServiceTest {
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ class GrokServiceTest {
|
|||||||
void chatVision() {
|
void chatVision() {
|
||||||
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
||||||
final String base64 = ImgUtil.toBase64DataUri(Toolkit.getDefaultToolkit().createImage("your imageUrl"), "png");
|
final String base64 = ImgUtil.toBase64DataUri(Toolkit.getDefaultToolkit().createImage("your imageUrl"), "png");
|
||||||
final String chatVision = grokService.chatVision("图片上有些什么?", Arrays.asList(base64));
|
final String chatVision = grokService.chatVision("图片上有些什么?", List.of(base64));
|
||||||
assertNotNull(chatVision);
|
assertNotNull(chatVision);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +123,7 @@ class GrokServiceTest {
|
|||||||
void testChatVisionStream() {
|
void testChatVisionStream() {
|
||||||
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
||||||
String prompt = "图片上有些什么?";
|
String prompt = "图片上有些什么?";
|
||||||
List<String> images = Arrays.asList("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544");
|
List<String> images = List.of("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544");
|
||||||
|
|
||||||
// 使用AtomicBoolean作为结束标志
|
// 使用AtomicBoolean作为结束标志
|
||||||
AtomicBoolean isDone = new AtomicBoolean(false);
|
AtomicBoolean isDone = new AtomicBoolean(false);
|
||||||
@ -148,7 +147,7 @@ class GrokServiceTest {
|
|||||||
@Disabled
|
@Disabled
|
||||||
void testChatVision() {
|
void testChatVision() {
|
||||||
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
final GrokService grokService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.GROK.getValue()).setModel(Models.Grok.GROK_2_VISION_1212.getModel()).setApiKey(key).build(), GrokService.class);
|
||||||
final String chatVision = grokService.chatVision("图片上有些什么?", Arrays.asList("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544"));
|
final String chatVision = grokService.chatVision("图片上有些什么?", List.of("https://img2.baidu.com/it/u=862000265,4064861820&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1544"));
|
||||||
assertNotNull(chatVision);
|
assertNotNull(chatVision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -207,7 +207,7 @@ public class SimpleCache<K, V> implements Iterable<Map.Entry<K, V>>, Serializabl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Map.Entry<K, V>> iterator() {
|
public Iterator<Map.Entry<K, V>> iterator() {
|
||||||
return new TransIter<>(this.rawMap.entrySet().iterator(), (entry) -> new Map.Entry<K, V>() {
|
return new TransIter<>(this.rawMap.entrySet().iterator(), (entry) -> new Map.Entry<>() {
|
||||||
@Override
|
@Override
|
||||||
public K getKey() {
|
public K getKey() {
|
||||||
return entry.getKey().get();
|
return entry.getKey().get();
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class LFUFileCache extends AbstractFileCache{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Cache<File, byte[]> initCache() {
|
protected Cache<File, byte[]> initCache() {
|
||||||
return new LFUCache<File, byte[]>(LFUFileCache.this.capacity, LFUFileCache.this.timeout) {
|
return new LFUCache<>(LFUFileCache.this.capacity, LFUFileCache.this.timeout) {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class LRUFileCache extends AbstractFileCache{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Cache<File, byte[]> initCache() {
|
protected Cache<File, byte[]> initCache() {
|
||||||
return new LRUCache<File, byte[]>(LRUFileCache.this.capacity, super.timeout) {
|
return new LRUCache<>(LRUFileCache.this.capacity, super.timeout) {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class NoCache<K, V> implements Cache<K, V> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<V> iterator() {
|
public Iterator<V> iterator() {
|
||||||
return new Iterator<V>() {
|
return new Iterator<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -134,8 +134,7 @@ public class Number128 extends Number implements Comparable<Number128>{
|
|||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (o instanceof Number128) {
|
if (o instanceof Number128 number128) {
|
||||||
final Number128 number128 = (Number128) o;
|
|
||||||
return leastSigBits == number128.leastSigBits && mostSigBits == number128.mostSigBits;
|
return leastSigBits == number128.leastSigBits && mostSigBits == number128.mostSigBits;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -268,7 +268,7 @@ public class MurmurHash implements Hash32<byte[]>, Hash64<byte[]>, Hash128<byte[
|
|||||||
*/
|
*/
|
||||||
public Number128 hash128(final byte[] data, final int offset, final int length, int seed) {
|
public Number128 hash128(final byte[] data, final int offset, final int length, int seed) {
|
||||||
// 避免负数的种子
|
// 避免负数的种子
|
||||||
seed &= 0xffffffffL;
|
seed &= (int) 0xffffffffL;
|
||||||
|
|
||||||
long h1 = seed;
|
long h1 = seed;
|
||||||
long h2 = seed;
|
long h2 = seed;
|
||||||
|
|||||||
@ -2129,7 +2129,7 @@ public class CollUtil {
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public static <T> List<List<T>> groupByFunc(final Collection<T> collection, final Function<T, ?> getter) {
|
public static <T> List<List<T>> groupByFunc(final Collection<T> collection, final Function<T, ?> getter) {
|
||||||
return group(collection, new Hash32<T>() {
|
return group(collection, new Hash32<>() {
|
||||||
private final List<Object> hashValList = new ArrayList<>();
|
private final List<Object> hashValList = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -106,7 +106,7 @@ public class MemorySafeLinkedBlockingQueue<E> extends CheckedLinkedBlockingQueue
|
|||||||
private static final FreeMemoryCalculator INSTANCE = new FreeMemoryCalculator();
|
private static final FreeMemoryCalculator INSTANCE = new FreeMemoryCalculator();
|
||||||
|
|
||||||
FreeMemoryCalculator() {
|
FreeMemoryCalculator() {
|
||||||
super(new SimpleScheduler.Job<Long>() {
|
super(new SimpleScheduler.Job<>() {
|
||||||
private volatile long maxAvailable = RuntimeUtil.getFreeMemory();
|
private volatile long maxAvailable = RuntimeUtil.getFreeMemory();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -88,8 +88,7 @@ public class SetUtil {
|
|||||||
if (null == iterable) {
|
if (null == iterable) {
|
||||||
return of(isLinked);
|
return of(isLinked);
|
||||||
}
|
}
|
||||||
if (iterable instanceof Collection) {
|
if (iterable instanceof Collection<T> collection) {
|
||||||
final Collection<T> collection = (Collection<T>) iterable;
|
|
||||||
return isLinked ? new LinkedHashSet<>(collection) : new HashSet<>(collection);
|
return isLinked ? new LinkedHashSet<>(collection) : new HashSet<>(collection);
|
||||||
}
|
}
|
||||||
return of(isLinked, iterable.iterator());
|
return of(isLinked, iterable.iterator());
|
||||||
|
|||||||
@ -89,16 +89,14 @@ public class EntryConverter extends ConverterWithRoot implements MatcherConverte
|
|||||||
public Map.Entry<?, ?> convert(final Type targetType, final Type keyType, final Type valueType, final Object value)
|
public Map.Entry<?, ?> convert(final Type targetType, final Type keyType, final Type valueType, final Object value)
|
||||||
throws ConvertException {
|
throws ConvertException {
|
||||||
Map map = null;
|
Map map = null;
|
||||||
if (value instanceof Map.Entry) {
|
if (value instanceof Map.Entry entry) {
|
||||||
final Map.Entry entry = (Map.Entry) value;
|
|
||||||
map = MapUtil.of(entry.getKey(), entry.getValue());
|
map = MapUtil.of(entry.getKey(), entry.getValue());
|
||||||
} else if (value instanceof Pair) {
|
} else if (value instanceof Pair) {
|
||||||
final Pair entry = (Pair<?, ?>) value;
|
final Pair entry = (Pair<?, ?>) value;
|
||||||
map = MapUtil.of(entry.getLeft(), entry.getRight());
|
map = MapUtil.of(entry.getLeft(), entry.getRight());
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
map = (Map) value;
|
map = (Map) value;
|
||||||
} else if (value instanceof CharSequence) {
|
} else if (value instanceof CharSequence str) {
|
||||||
final CharSequence str = (CharSequence) value;
|
|
||||||
map = strToMap(str);
|
map = strToMap(str);
|
||||||
} else if (BeanUtil.isWritableBean(value.getClass())) {
|
} else if (BeanUtil.isWritableBean(value.getClass())) {
|
||||||
// 一次性只读场景,包装为Map效率更高
|
// 一次性只读场景,包装为Map效率更高
|
||||||
|
|||||||
@ -80,16 +80,14 @@ public class PairConverter extends ConverterWithRoot implements Serializable {
|
|||||||
public Pair<?, ?> convert(final Type leftType, final Type rightType, final Object value)
|
public Pair<?, ?> convert(final Type leftType, final Type rightType, final Object value)
|
||||||
throws ConvertException {
|
throws ConvertException {
|
||||||
Map map = null;
|
Map map = null;
|
||||||
if (value instanceof Map.Entry) {
|
if (value instanceof Map.Entry entry) {
|
||||||
final Map.Entry entry = (Map.Entry) value;
|
|
||||||
map = MapUtil.of(entry.getKey(), entry.getValue());
|
map = MapUtil.of(entry.getKey(), entry.getValue());
|
||||||
} else if (value instanceof Pair) {
|
} else if (value instanceof Pair) {
|
||||||
final Pair entry = (Pair<?, ?>) value;
|
final Pair entry = (Pair<?, ?>) value;
|
||||||
map = MapUtil.of(entry.getLeft(), entry.getRight());
|
map = MapUtil.of(entry.getLeft(), entry.getRight());
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
map = (Map) value;
|
map = (Map) value;
|
||||||
} else if (value instanceof CharSequence) {
|
} else if (value instanceof CharSequence str) {
|
||||||
final CharSequence str = (CharSequence) value;
|
|
||||||
map = strToMap(str);
|
map = strToMap(str);
|
||||||
} else if (BeanUtil.isReadableBean(value.getClass())) {
|
} else if (BeanUtil.isReadableBean(value.getClass())) {
|
||||||
// 一次性只读场景,包装为Map效率更高
|
// 一次性只读场景,包装为Map效率更高
|
||||||
|
|||||||
@ -36,8 +36,7 @@ public class StackTraceElementConverter extends AbstractConverter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected StackTraceElement convertInternal(final Class<?> targetClass, final Object value) {
|
protected StackTraceElement convertInternal(final Class<?> targetClass, final Object value) {
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map<?, ?> map) {
|
||||||
final Map<?, ?> map = (Map<?, ?>) value;
|
|
||||||
|
|
||||||
final String declaringClass = MapUtil.getStr(map, "className");
|
final String declaringClass = MapUtil.getStr(map, "className");
|
||||||
final String methodName = MapUtil.getStr(map, "methodName");
|
final String methodName = MapUtil.getStr(map, "methodName");
|
||||||
|
|||||||
@ -110,8 +110,7 @@ public class TemporalAccessorConverter extends AbstractConverter {
|
|||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
final DateTime dateTime = DateUtil.date((Date) value);
|
final DateTime dateTime = DateUtil.date((Date) value);
|
||||||
return parseFromInstant(targetClass, dateTime.toInstant(), dateTime.getZoneId());
|
return parseFromInstant(targetClass, dateTime.toInstant(), dateTime.getZoneId());
|
||||||
} else if (value instanceof Calendar) {
|
} else if (value instanceof Calendar calendar) {
|
||||||
final Calendar calendar = (Calendar) value;
|
|
||||||
return parseFromInstant(targetClass, calendar.toInstant(), calendar.getTimeZone().toZoneId());
|
return parseFromInstant(targetClass, calendar.toInstant(), calendar.getTimeZone().toZoneId());
|
||||||
} else {
|
} else {
|
||||||
return parseFromCharSequence(targetClass, convertToStr(value));
|
return parseFromCharSequence(targetClass, convertToStr(value));
|
||||||
|
|||||||
@ -87,8 +87,7 @@ public class XMLGregorianCalendarConverter extends AbstractConverter {
|
|||||||
// Handle Date
|
// Handle Date
|
||||||
if (value instanceof Date) {
|
if (value instanceof Date) {
|
||||||
gregorianCalendar.setTime((Date) value);
|
gregorianCalendar.setTime((Date) value);
|
||||||
} else if (value instanceof Calendar) {
|
} else if (value instanceof Calendar calendar) {
|
||||||
final Calendar calendar = (Calendar) value;
|
|
||||||
gregorianCalendar.setTimeZone(calendar.getTimeZone());
|
gregorianCalendar.setTimeZone(calendar.getTimeZone());
|
||||||
gregorianCalendar.setFirstDayOfWeek(calendar.getFirstDayOfWeek());
|
gregorianCalendar.setFirstDayOfWeek(calendar.getFirstDayOfWeek());
|
||||||
gregorianCalendar.setLenient(calendar.isLenient());
|
gregorianCalendar.setLenient(calendar.isLenient());
|
||||||
|
|||||||
@ -243,7 +243,6 @@ public class RichTextMaskingProcessor {
|
|||||||
case REPLACE ->
|
case REPLACE ->
|
||||||
// 替换脱敏,用指定文本替换
|
// 替换脱敏,用指定文本替换
|
||||||
rule.getReplacement();
|
rule.getReplacement();
|
||||||
default -> matched;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理正则表达式中的特殊字符
|
// 处理正则表达式中的特殊字符
|
||||||
|
|||||||
@ -1674,8 +1674,8 @@ public class DateUtil {
|
|||||||
* @since 5.7.21
|
* @since 5.7.21
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeContains(final DateRange start, final DateRange end) {
|
public static List<DateTime> rangeContains(final DateRange start, final DateRange end) {
|
||||||
final List<DateTime> startDateTimes = ListUtil.of((Iterable<DateTime>) start);
|
final List<DateTime> startDateTimes = ListUtil.of(start);
|
||||||
final List<DateTime> endDateTimes = ListUtil.of((Iterable<DateTime>) end);
|
final List<DateTime> endDateTimes = ListUtil.of(end);
|
||||||
return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList());
|
return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1689,8 +1689,8 @@ public class DateUtil {
|
|||||||
* @since 5.7.21
|
* @since 5.7.21
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeNotContains(final DateRange start, final DateRange end) {
|
public static List<DateTime> rangeNotContains(final DateRange start, final DateRange end) {
|
||||||
final List<DateTime> startDateTimes = ListUtil.of((Iterable<DateTime>) start);
|
final List<DateTime> startDateTimes = ListUtil.of(start);
|
||||||
final List<DateTime> endDateTimes = ListUtil.of((Iterable<DateTime>) end);
|
final List<DateTime> endDateTimes = ListUtil.of(end);
|
||||||
return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList());
|
return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1741,7 +1741,7 @@ public class DateUtil {
|
|||||||
* @return {@link DateRange}
|
* @return {@link DateRange}
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit) {
|
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit) {
|
||||||
return ListUtil.of((Iterable<DateTime>) range(start, end, unit));
|
return ListUtil.of(range(start, end, unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1755,7 +1755,7 @@ public class DateUtil {
|
|||||||
* @since 5.7.16
|
* @since 5.7.16
|
||||||
*/
|
*/
|
||||||
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit, final int step) {
|
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit, final int step) {
|
||||||
return ListUtil.of((Iterable<DateTime>) new DateRange(start, end, unit, step));
|
return ListUtil.of(new DateRange(start, end, unit, step));
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,6 @@ public class TemporalUtil {
|
|||||||
case MINUTES -> ChronoUnit.MINUTES;
|
case MINUTES -> ChronoUnit.MINUTES;
|
||||||
case HOURS -> ChronoUnit.HOURS;
|
case HOURS -> ChronoUnit.HOURS;
|
||||||
case DAYS -> ChronoUnit.DAYS;
|
case DAYS -> ChronoUnit.DAYS;
|
||||||
default -> throw new IllegalArgumentException("Unknown TimeUnit constant");
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ public class FastDateFormat extends Format implements PositionDateParser, DatePr
|
|||||||
*/
|
*/
|
||||||
public static final int SHORT = DateFormat.SHORT;
|
public static final int SHORT = DateFormat.SHORT;
|
||||||
|
|
||||||
private static final FormatCache<FastDateFormat> CACHE = new FormatCache<FastDateFormat>() {
|
private static final FormatCache<FastDateFormat> CACHE = new FormatCache<>() {
|
||||||
@Override
|
@Override
|
||||||
protected FastDateFormat createInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
|
protected FastDateFormat createInstance(final String pattern, final TimeZone timeZone, final Locale locale) {
|
||||||
return new FastDateFormat(pattern, timeZone, locale);
|
return new FastDateFormat(pattern, timeZone, locale);
|
||||||
|
|||||||
@ -233,9 +233,7 @@ public class RegexDateParser implements DateParser, Serializable {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// zone(包括可时区名称、时区偏移等信息,综合解析)
|
// zone(包括可时区名称、时区偏移等信息,综合解析)
|
||||||
Opt.ofNullable(ReUtil.group(matcher, "zone")).ifPresent((zoneOffset) -> {
|
Opt.ofNullable(ReUtil.group(matcher, "zone")).ifPresent((zoneOffset) -> parseZone(zoneOffset, dateBuilder));
|
||||||
parseZone(zoneOffset, dateBuilder);
|
|
||||||
});
|
|
||||||
|
|
||||||
// zone offset
|
// zone offset
|
||||||
Opt.ofNullable(ReUtil.group(matcher, "zoneOffset")).ifPresent((zoneOffset) -> {
|
Opt.ofNullable(ReUtil.group(matcher, "zoneOffset")).ifPresent((zoneOffset) -> {
|
||||||
@ -244,9 +242,7 @@ public class RegexDateParser implements DateParser, Serializable {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// unix时间戳,可能有NS
|
// unix时间戳,可能有NS
|
||||||
Opt.ofNullable(ReUtil.group(matcher, "unixsecond")).ifPresent((unixsecond) -> {
|
Opt.ofNullable(ReUtil.group(matcher, "unixsecond")).ifPresent((unixsecond) -> dateBuilder.setUnixsecond(parseLong(unixsecond)));
|
||||||
dateBuilder.setUnixsecond(parseLong(unixsecond));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -117,7 +117,7 @@ public class LineReader extends ReaderWrapper implements Iterable<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<String> iterator() {
|
public Iterator<String> iterator() {
|
||||||
return new ComputeIter<String>() {
|
return new ComputeIter<>() {
|
||||||
@Override
|
@Override
|
||||||
protected String computeNext() {
|
protected String computeNext() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package cn.hutool.v7.core.io;
|
package cn.hutool.v7.core.io;
|
||||||
|
|
||||||
import cn.hutool.v7.core.io.IORuntimeException;
|
|
||||||
import cn.hutool.v7.core.io.resource.ResourceUtil;
|
import cn.hutool.v7.core.io.resource.ResourceUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -56,8 +55,7 @@ public class ManifestUtil {
|
|||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection instanceof JarURLConnection) {
|
if (connection instanceof JarURLConnection conn) {
|
||||||
final JarURLConnection conn = (JarURLConnection) connection;
|
|
||||||
return getManifest(conn);
|
return getManifest(conn);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -169,7 +169,7 @@ public class PathUtil {
|
|||||||
return fileList;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
walkFiles(path, maxDepth, isFollowLinks, new SimpleFileVisitor<Path>() {
|
walkFiles(path, maxDepth, isFollowLinks, new SimpleFileVisitor<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) {
|
||||||
|
|||||||
@ -89,8 +89,7 @@ public class JarResource extends UrlResource {
|
|||||||
*/
|
*/
|
||||||
private JarFile doGetJarFile() throws IOException {
|
private JarFile doGetJarFile() throws IOException {
|
||||||
final URLConnection con = getUrl().openConnection();
|
final URLConnection con = getUrl().openConnection();
|
||||||
if (con instanceof JarURLConnection) {
|
if (con instanceof JarURLConnection jarCon) {
|
||||||
final JarURLConnection jarCon = (JarURLConnection) con;
|
|
||||||
return jarCon.getJarFile();
|
return jarCon.getJarFile();
|
||||||
} else {
|
} else {
|
||||||
final String urlFile = getUrl().getFile();
|
final String urlFile = getUrl().getFile();
|
||||||
|
|||||||
@ -127,8 +127,7 @@ public class ResourceFinder {
|
|||||||
String rootEntryPath;
|
String rootEntryPath;
|
||||||
final boolean closeJarFile;
|
final boolean closeJarFile;
|
||||||
|
|
||||||
if (conn instanceof JarURLConnection) {
|
if (conn instanceof JarURLConnection jarCon) {
|
||||||
final JarURLConnection jarCon = (JarURLConnection) conn;
|
|
||||||
UrlUtil.useCachesIfNecessary(jarCon);
|
UrlUtil.useCachesIfNecessary(jarCon);
|
||||||
jarFile = jarCon.getJarFile();
|
jarFile = jarCon.getJarFile();
|
||||||
final JarEntry jarEntry = jarCon.getJarEntry();
|
final JarEntry jarEntry = jarCon.getJarEntry();
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public class LineInputStream extends FilterInputStream implements Iterable<byte[
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<byte[]> iterator() {
|
public Iterator<byte[]> iterator() {
|
||||||
return new ComputeIter<byte[]>() {
|
return new ComputeIter<>() {
|
||||||
@Override
|
@Override
|
||||||
protected byte[] computeNext() {
|
protected byte[] computeNext() {
|
||||||
return readLine();
|
return readLine();
|
||||||
|
|||||||
@ -193,7 +193,7 @@ public class WatchServiceWrapper extends SimpleWrapper<WatchService> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 递归注册下一层层级的目录和文件
|
// 递归注册下一层层级的目录和文件
|
||||||
PathUtil.walkFiles(path, maxDepth, new SimpleFileVisitor<Path>() {
|
PathUtil.walkFiles(path, maxDepth, new SimpleFileVisitor<>() {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
|
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
|
||||||
|
|||||||
@ -52,8 +52,7 @@ public class Console {
|
|||||||
* @param obj 要打印的对象
|
* @param obj 要打印的对象
|
||||||
*/
|
*/
|
||||||
public static void log(final Object obj) {
|
public static void log(final Object obj) {
|
||||||
if (obj instanceof Throwable) {
|
if (obj instanceof Throwable e) {
|
||||||
final Throwable e = (Throwable) obj;
|
|
||||||
log(e, e.getMessage());
|
log(e, e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
log(TEMPLATE_VAR, obj);
|
log(TEMPLATE_VAR, obj);
|
||||||
@ -220,8 +219,7 @@ public class Console {
|
|||||||
* @param obj 要打印的对象
|
* @param obj 要打印的对象
|
||||||
*/
|
*/
|
||||||
public static void error(final Object obj) {
|
public static void error(final Object obj) {
|
||||||
if (obj instanceof Throwable) {
|
if (obj instanceof Throwable e) {
|
||||||
final Throwable e = (Throwable) obj;
|
|
||||||
error(e, e.getMessage());
|
error(e, e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
error(TEMPLATE_VAR, obj);
|
error(TEMPLATE_VAR, obj);
|
||||||
|
|||||||
@ -541,11 +541,10 @@ public class Opt<T> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(obj instanceof Opt)) {
|
if (!(obj instanceof Opt<?> other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Opt<?> other = (Opt<?>) obj;
|
|
||||||
return Objects.equals(value, other.value);
|
return Objects.equals(value, other.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class Range<T> implements Iterable<T>, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<T> iterator() {
|
public Iterator<T> iterator() {
|
||||||
return new Iterator<T>(){
|
return new Iterator<>() {
|
||||||
/**
|
/**
|
||||||
* 下一个对象
|
* 下一个对象
|
||||||
*/
|
*/
|
||||||
@ -142,11 +142,11 @@ public class Range<T> implements Iterable<T>, Serializable {
|
|||||||
*/
|
*/
|
||||||
private T nextUncheck() {
|
private T nextUncheck() {
|
||||||
final T current;
|
final T current;
|
||||||
if(0 == this.index){
|
if (0 == this.index) {
|
||||||
current = start;
|
current = start;
|
||||||
if(!includeStart){
|
if (!includeStart) {
|
||||||
// 获取下一组元素
|
// 获取下一组元素
|
||||||
index ++;
|
index++;
|
||||||
return nextUncheck();
|
return nextUncheck();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -39,8 +39,7 @@ public abstract class AbsEntry<K, V> implements Map.Entry<K, V> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object) {
|
public boolean equals(final Object object) {
|
||||||
if (object instanceof Map.Entry) {
|
if (object instanceof Map.Entry<?, ?> that) {
|
||||||
final Map.Entry<?, ?> that = (Map.Entry<?, ?>) object;
|
|
||||||
return ObjUtil.equals(this.getKey(), that.getKey())
|
return ObjUtil.equals(this.getKey(), that.getKey())
|
||||||
&& ObjUtil.equals(this.getValue(), that.getValue());
|
&& ObjUtil.equals(this.getValue(), that.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -772,7 +772,7 @@ public class MapUtil extends MapGetUtil {
|
|||||||
* @since 3.2.2
|
* @since 3.2.2
|
||||||
*/
|
*/
|
||||||
public static <T> Map<T, T> reverse(final Map<T, T> map) {
|
public static <T> Map<T, T> reverse(final Map<T, T> map) {
|
||||||
return edit(map, t -> new Entry<T, T>() {
|
return edit(map, t -> new Entry<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T getKey() {
|
public T getKey() {
|
||||||
|
|||||||
@ -243,7 +243,7 @@ public class TableMap<K, V> implements Map<K, V>, Iterable<Map.Entry<K, V>>, Ser
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Map.Entry<K, V>> iterator() {
|
public Iterator<Map.Entry<K, V>> iterator() {
|
||||||
return new Iterator<Map.Entry<K, V>>() {
|
return new Iterator<>() {
|
||||||
private final Iterator<K> keysIter = keys.iterator();
|
private final Iterator<K> keysIter = keys.iterator();
|
||||||
private final Iterator<V> valuesIter = values.iterator();
|
private final Iterator<V> valuesIter = values.iterator();
|
||||||
|
|
||||||
|
|||||||
@ -54,8 +54,7 @@ public abstract class AbsTable<R, C, V> implements Table<R, C, V> {
|
|||||||
public boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
return true;
|
return true;
|
||||||
} else if (obj instanceof Table) {
|
} else if (obj instanceof Table<?, ?, ?> that) {
|
||||||
final Table<?, ?, ?> that = (Table<?, ?, ?>) obj;
|
|
||||||
return this.cellSet().equals(that.cellSet());
|
return this.cellSet().equals(that.cellSet());
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -232,8 +231,7 @@ public abstract class AbsTable<R, C, V> implements Table<R, C, V> {
|
|||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof Cell) {
|
if (obj instanceof Cell<?, ?, ?> other) {
|
||||||
final Cell<?, ?, ?> other = (Cell<?, ?, ?>) obj;
|
|
||||||
return ObjUtil.equals(rowKey, other.getRowKey())
|
return ObjUtil.equals(rowKey, other.getRowKey())
|
||||||
&& ObjUtil.equals(columnKey, other.getColumnKey())
|
&& ObjUtil.equals(columnKey, other.getColumnKey())
|
||||||
&& ObjUtil.equals(value, other.getValue());
|
&& ObjUtil.equals(value, other.getValue());
|
||||||
|
|||||||
@ -73,9 +73,7 @@ public class DirectedWeightGraph<T> {
|
|||||||
allPoints.clear();
|
allPoints.clear();
|
||||||
neighborEdgeMap.forEach((f, m) -> {
|
neighborEdgeMap.forEach((f, m) -> {
|
||||||
allPoints.add(f);
|
allPoints.add(f);
|
||||||
m.forEach((t, e) -> {
|
m.forEach((t, e) -> allPoints.add(t));
|
||||||
allPoints.add(t);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,20 +85,16 @@ public class DirectedWeightGraph<T> {
|
|||||||
public void removePoint(final T point) {
|
public void removePoint(final T point) {
|
||||||
allPoints.remove(point);
|
allPoints.remove(point);
|
||||||
neighborEdgeMap.remove(point);
|
neighborEdgeMap.remove(point);
|
||||||
neighborEdgeMap.forEach((f, m) -> {
|
neighborEdgeMap.forEach((f, m) -> m.remove(point));
|
||||||
m.remove(point);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
neighborEdgeMap.forEach((from, edgeMap) -> {
|
neighborEdgeMap.forEach((from, edgeMap) -> edgeMap.forEach((to, edge) -> {
|
||||||
edgeMap.forEach((to, edge) -> {
|
|
||||||
builder.append(edge);
|
builder.append(edge);
|
||||||
builder.append("\r\n");
|
builder.append("\r\n");
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -271,7 +271,7 @@ public class RowKeyTable<R, C, V> extends AbsTable<R, C, V> {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Entry<R, Map<C, V>> entry = iterator.next();
|
final Entry<R, Map<C, V>> entry = iterator.next();
|
||||||
if (entry.getValue().containsKey(columnKey)) {
|
if (entry.getValue().containsKey(columnKey)) {
|
||||||
return new AbsEntry<R, V>() {
|
return new AbsEntry<>() {
|
||||||
@Override
|
@Override
|
||||||
public R getKey() {
|
public R getKey() {
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
|
|||||||
@ -212,11 +212,11 @@ public abstract class ReferenceConcurrentMap<K, V> implements ConcurrentMap<K, V
|
|||||||
public Set<K> keySet() {
|
public Set<K> keySet() {
|
||||||
this.purgeStale();
|
this.purgeStale();
|
||||||
final Set<Ref<K>> referenceSet = this.raw.keySet();
|
final Set<Ref<K>> referenceSet = this.raw.keySet();
|
||||||
return new AbstractSet<K>() {
|
return new AbstractSet<>() {
|
||||||
@Override
|
@Override
|
||||||
public Iterator<K> iterator() {
|
public Iterator<K> iterator() {
|
||||||
final Iterator<Ref<K>> referenceIter = referenceSet.iterator();
|
final Iterator<Ref<K>> referenceIter = referenceSet.iterator();
|
||||||
return new Iterator<K>() {
|
return new Iterator<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return referenceIter.hasNext();
|
return referenceIter.hasNext();
|
||||||
@ -240,11 +240,11 @@ public abstract class ReferenceConcurrentMap<K, V> implements ConcurrentMap<K, V
|
|||||||
public Collection<V> values() {
|
public Collection<V> values() {
|
||||||
this.purgeStale();
|
this.purgeStale();
|
||||||
final Collection<Ref<V>> referenceValues = this.raw.values();
|
final Collection<Ref<V>> referenceValues = this.raw.values();
|
||||||
return new AbstractCollection<V>() {
|
return new AbstractCollection<>() {
|
||||||
@Override
|
@Override
|
||||||
public Iterator<V> iterator() {
|
public Iterator<V> iterator() {
|
||||||
final Iterator<Ref<V>> referenceIter = referenceValues.iterator();
|
final Iterator<Ref<V>> referenceIter = referenceValues.iterator();
|
||||||
return new Iterator<V>() {
|
return new Iterator<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return referenceIter.hasNext();
|
return referenceIter.hasNext();
|
||||||
@ -268,7 +268,7 @@ public abstract class ReferenceConcurrentMap<K, V> implements ConcurrentMap<K, V
|
|||||||
public Set<Entry<K, V>> entrySet() {
|
public Set<Entry<K, V>> entrySet() {
|
||||||
this.purgeStale();
|
this.purgeStale();
|
||||||
final Set<Entry<Ref<K>, Ref<V>>> referenceEntrySet = this.raw.entrySet();
|
final Set<Entry<Ref<K>, Ref<V>>> referenceEntrySet = this.raw.entrySet();
|
||||||
return new AbstractSet<Entry<K, V>>() {
|
return new AbstractSet<>() {
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Entry<K, V>> iterator() {
|
public Iterator<Entry<K, V>> iterator() {
|
||||||
final Iterator<Entry<Ref<K>, Ref<V>>> referenceIter = referenceEntrySet.iterator();
|
final Iterator<Entry<Ref<K>, Ref<V>>> referenceIter = referenceEntrySet.iterator();
|
||||||
@ -281,7 +281,7 @@ public abstract class ReferenceConcurrentMap<K, V> implements ConcurrentMap<K, V
|
|||||||
@Override
|
@Override
|
||||||
public Entry<K, V> next() {
|
public Entry<K, V> next() {
|
||||||
final Entry<Ref<K>, Ref<V>> next = referenceIter.next();
|
final Entry<Ref<K>, Ref<V>> next = referenceIter.next();
|
||||||
return new Entry<K, V>() {
|
return new Entry<>() {
|
||||||
@Override
|
@Override
|
||||||
public K getKey() {
|
public K getKey() {
|
||||||
return unwrap(next.getKey());
|
return unwrap(next.getKey());
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import java.util.Stack;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 数学表达式计算工具类<br>
|
* 数学表达式计算工具类<br>
|
||||||
* 见:https://github.com/chinabugotech/hutool/issues/1090#issuecomment-693750140
|
* 见:<a href="https://github.com/chinabugotech/hutool/issues/1090#issuecomment-693750140">issues#1090#issuecomment-693750140</a>
|
||||||
*
|
*
|
||||||
* @author trainliang, Looly
|
* @author trainliang, Looly
|
||||||
* @since 5.4.3
|
* @since 5.4.3
|
||||||
@ -165,7 +165,7 @@ public class Calculator {
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculate(final String firstValue, final String secondValue, final char currentOp) {
|
private BigDecimal calculate(final String firstValue, final String secondValue, final char currentOp) {
|
||||||
final BigDecimal result = switch (currentOp) {
|
return switch (currentOp) {
|
||||||
case '+' -> NumberUtil.add(firstValue, secondValue);
|
case '+' -> NumberUtil.add(firstValue, secondValue);
|
||||||
case '-' -> NumberUtil.sub(firstValue, secondValue);
|
case '-' -> NumberUtil.sub(firstValue, secondValue);
|
||||||
case '*' -> NumberUtil.mul(firstValue, secondValue);
|
case '*' -> NumberUtil.mul(firstValue, secondValue);
|
||||||
@ -173,7 +173,6 @@ public class Calculator {
|
|||||||
case '%' -> NumberUtil.toBigDecimal(firstValue).remainder(NumberUtil.toBigDecimal(secondValue));
|
case '%' -> NumberUtil.toBigDecimal(firstValue).remainder(NumberUtil.toBigDecimal(secondValue));
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + currentOp);
|
default -> throw new IllegalStateException("Unexpected value: " + currentOp);
|
||||||
};
|
};
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -618,10 +618,9 @@ public final class Fraction extends Number implements Comparable<Fraction> {
|
|||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof Fraction)) {
|
if (!(obj instanceof Fraction other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Fraction other = (Fraction) obj;
|
|
||||||
return getNumerator() == other.getNumerator() && getDenominator() == other.getDenominator();
|
return getNumerator() == other.getNumerator() && getDenominator() == other.getDenominator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -60,8 +60,7 @@ public class MethodTypeUtil {
|
|||||||
if (null == declaringClass) {
|
if (null == declaringClass) {
|
||||||
declaringClass = executable.getDeclaringClass();
|
declaringClass = executable.getDeclaringClass();
|
||||||
}
|
}
|
||||||
if (executable instanceof Method) {
|
if (executable instanceof Method method) {
|
||||||
final Method method = (Method) executable;
|
|
||||||
return MethodType.methodType(method.getReturnType(), declaringClass, method.getParameterTypes());
|
return MethodType.methodType(method.getReturnType(), declaringClass, method.getParameterTypes());
|
||||||
} else {
|
} else {
|
||||||
final Constructor<?> constructor = (Constructor<?>) executable;
|
final Constructor<?> constructor = (Constructor<?>) executable;
|
||||||
|
|||||||
@ -184,7 +184,7 @@ public class ListServiceLoader<S> extends AbsServiceLoader<S> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<S> iterator() {
|
public Iterator<S> iterator() {
|
||||||
return new Iterator<S>() {
|
return new Iterator<>() {
|
||||||
private final Iterator<String> nameIter = serviceNames.iterator();
|
private final Iterator<String> nameIter = serviceNames.iterator();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -156,7 +156,7 @@ public class MapServiceLoader<S> extends AbsServiceLoader<S> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<S> iterator() {
|
public Iterator<S> iterator() {
|
||||||
return new Iterator<S>() {
|
return new Iterator<>() {
|
||||||
private final Iterator<String> nameIter =
|
private final Iterator<String> nameIter =
|
||||||
serviceProperties.stringPropertyNames().iterator();
|
serviceProperties.stringPropertyNames().iterator();
|
||||||
|
|
||||||
|
|||||||
@ -100,7 +100,7 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
|
|||||||
* @return a unwrap builder
|
* @return a unwrap builder
|
||||||
*/
|
*/
|
||||||
public static <T> Builder<T> builder() {
|
public static <T> Builder<T> builder() {
|
||||||
return new Builder<T>() {
|
return new Builder<>() {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private final Stream.Builder<T> streamBuilder = Stream.builder();
|
private final Stream.Builder<T> streamBuilder = Stream.builder();
|
||||||
@ -473,6 +473,7 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
|
|||||||
* 建造者
|
* 建造者
|
||||||
*
|
*
|
||||||
* @author VampireAchao
|
* @author VampireAchao
|
||||||
|
* @param <T> 元素类型
|
||||||
*/
|
*/
|
||||||
public interface Builder<T> extends Consumer<T>, cn.hutool.v7.core.lang.builder.Builder<EasyStream<T>> {
|
public interface Builder<T> extends Consumer<T>, cn.hutool.v7.core.lang.builder.Builder<EasyStream<T>> {
|
||||||
|
|
||||||
|
|||||||
@ -347,7 +347,7 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
|||||||
* @return 流是否为空
|
* @return 流是否为空
|
||||||
*/
|
*/
|
||||||
default boolean isEmpty() {
|
default boolean isEmpty() {
|
||||||
return !findAny().isPresent();
|
return findAny().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import java.util.function.Predicate;
|
|||||||
*
|
*
|
||||||
* @author emptypoint
|
* @author emptypoint
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
|
* @param <T> 元素类型
|
||||||
*/
|
*/
|
||||||
public class TakeWhileSpliterator<T> implements Spliterator<T> {
|
public class TakeWhileSpliterator<T> implements Spliterator<T> {
|
||||||
|
|
||||||
|
|||||||
@ -20,26 +20,16 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unicode字符遍历器<br>
|
* Unicode字符遍历器<br>
|
||||||
* 参考:http://stackoverflow.com/a/21791059/6030888
|
* 参考:<a href="http://stackoverflow.com/a/21791059/6030888">http://stackoverflow.com/a/21791059/6030888</a>
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
|
* @param str
|
||||||
*/
|
*/
|
||||||
public class CodePointIter implements Iterable<Integer> {
|
public record CodePointIter(String str) implements Iterable<Integer> {
|
||||||
|
|
||||||
final String str;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造
|
|
||||||
*
|
|
||||||
* @param str 字符串
|
|
||||||
*/
|
|
||||||
public CodePointIter(final String str) {
|
|
||||||
this.str = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Integer> iterator() {
|
public Iterator<Integer> iterator() {
|
||||||
return new Iterator<Integer>() {
|
return new Iterator<>() {
|
||||||
|
|
||||||
private final int length = str.length();
|
private final int length = str.length();
|
||||||
private int nextIndex = 0;
|
private int nextIndex = 0;
|
||||||
|
|||||||
@ -148,7 +148,7 @@ public class NFA {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final List<FoundWord> ans = new ArrayList<>();
|
final List<FoundWord> ans = new ArrayList<>();
|
||||||
Node p = root, k = null;
|
Node p = root, k;
|
||||||
for (int i = 0, len = text.length(); i < len; i++) {
|
for (int i = 0, len = text.length(); i < len; i++) {
|
||||||
final int ind = text.charAt(i);
|
final int ind = text.charAt(i);
|
||||||
// 状态转移(沿着fail指针链接的链表,此处区别于DFA模型)
|
// 状态转移(沿着fail指针链接的链表,此处区别于DFA模型)
|
||||||
|
|||||||
@ -225,7 +225,7 @@ public class RecyclableBatchThreadPoolExecutor {
|
|||||||
*/
|
*/
|
||||||
private static <T> List<List<T>> splitData(final List<T> data, final int batchSize) {
|
private static <T> List<List<T>> splitData(final List<T> data, final int batchSize) {
|
||||||
final int batchCount = (data.size() + batchSize - 1) / batchSize;
|
final int batchCount = (data.size() + batchSize - 1) / batchSize;
|
||||||
return new AbstractList<List<T>>() {
|
return new AbstractList<>() {
|
||||||
@Override
|
@Override
|
||||||
public List<T> get(final int index) {
|
public List<T> get(final int index) {
|
||||||
final int from = index * batchSize;
|
final int from = index * batchSize;
|
||||||
|
|||||||
@ -386,9 +386,7 @@ public class MapTree<T> extends LinkedHashMap<String, Object> implements Node<T>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<MapTree<T>> newChildren = new ArrayList<>(children.size());
|
final List<MapTree<T>> newChildren = new ArrayList<>(children.size());
|
||||||
children.forEach((t) -> {
|
children.forEach((t) -> newChildren.add(t.cloneTree().setParent(parent)));
|
||||||
newChildren.add(t.cloneTree().setParent(parent));
|
|
||||||
});
|
|
||||||
return newChildren;
|
return newChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class GenericAnnotationMappingTest {
|
|||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
|
final Annotation1 annotation = Foo.class.getAnnotation(Annotation1.class);
|
||||||
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
|
final GenericAnnotationMapping mapping = GenericAnnotationMapping.create(annotation, false);
|
||||||
Assertions.assertNotEquals(mapping, null);
|
Assertions.assertNotEquals(null, mapping);
|
||||||
Assertions.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false));
|
Assertions.assertEquals(mapping, GenericAnnotationMapping.create(annotation, false));
|
||||||
Assertions.assertNotEquals(mapping, GenericAnnotationMapping.create(annotation, true));
|
Assertions.assertNotEquals(mapping, GenericAnnotationMapping.create(annotation, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public class HierarchicalAnnotatedElementTest {
|
|||||||
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY));
|
Assertions.assertEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, ELEMENT_MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Super.class, ELEMENT_MAPPING_FACTORY));
|
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Super.class, ELEMENT_MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, (es, e) -> e));
|
Assertions.assertNotEquals(elements, HierarchicalAnnotatedElements.of(Foo.class, (es, e) -> e));
|
||||||
Assertions.assertNotEquals(elements, null);
|
Assertions.assertNotEquals(null, elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -44,10 +44,10 @@ public class MetaAnnotatedElementTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
final AnnotatedElement element = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY);
|
final AnnotatedElement element = new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY);
|
||||||
Assertions.assertNotEquals(element, null);
|
Assertions.assertNotEquals(null, element);
|
||||||
Assertions.assertEquals(element, new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY));
|
Assertions.assertEquals(new MetaAnnotatedElement<>(Foo.class, RESOLVED_MAPPING_FACTORY), element);
|
||||||
Assertions.assertNotEquals(element, new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY));
|
Assertions.assertNotEquals(new MetaAnnotatedElement<>(Foo.class, MAPPING_FACTORY), element);
|
||||||
Assertions.assertNotEquals(element, new MetaAnnotatedElement<>(Annotation1.class, MAPPING_FACTORY));
|
Assertions.assertNotEquals(new MetaAnnotatedElement<>(Annotation1.class, MAPPING_FACTORY), element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class RepeatableMetaAnnotatedElementTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
|
final AnnotatedElement element = RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY);
|
||||||
Assertions.assertNotEquals(element, null);
|
Assertions.assertNotEquals(null, element);
|
||||||
Assertions.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
|
Assertions.assertEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, RESOLVED_MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
|
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Foo.class, MAPPING_FACTORY));
|
||||||
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY));
|
Assertions.assertNotEquals(element, RepeatableMetaAnnotatedElement.create(Annotation1.class, MAPPING_FACTORY));
|
||||||
|
|||||||
@ -104,21 +104,21 @@ public class ArrayUtilTest {
|
|||||||
public void filterEditTest() {
|
public void filterEditTest() {
|
||||||
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
||||||
final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t : null);
|
final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t : null);
|
||||||
assertArrayEquals(filter, new Integer[]{2, 4, 6});
|
assertArrayEquals(new Integer[]{2, 4, 6}, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filterTestForFilter() {
|
public void filterTestForFilter() {
|
||||||
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
||||||
final Integer[] filter = ArrayUtil.filter(a, t -> t % 2 == 0);
|
final Integer[] filter = ArrayUtil.filter(a, t -> t % 2 == 0);
|
||||||
assertArrayEquals(filter, new Integer[]{2, 4, 6});
|
assertArrayEquals(new Integer[]{2, 4, 6}, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void editTest() {
|
public void editTest() {
|
||||||
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
final Integer[] a = {1, 2, 3, 4, 5, 6};
|
||||||
final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t * 10 : t);
|
final Integer[] filter = ArrayUtil.edit(a, t -> (t % 2 == 0) ? t * 10 : t);
|
||||||
assertArrayEquals(filter, new Integer[]{1, 20, 3, 40, 5, 60});
|
assertArrayEquals(new Integer[]{1, 20, 3, 40, 5, 60}, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -227,7 +227,7 @@ public class ArrayUtilTest {
|
|||||||
final String[] keys = {"a", "b", "c"};
|
final String[] keys = {"a", "b", "c"};
|
||||||
final Integer[] values = {1, 2, 3};
|
final Integer[] values = {1, 2, 3};
|
||||||
final Map<String, Integer> map = ArrayUtil.zip(keys, values, true);
|
final Map<String, Integer> map = ArrayUtil.zip(keys, values, true);
|
||||||
assertEquals(Objects.requireNonNull(map).toString(), "{a=1, b=2, c=3}");
|
assertEquals("{a=1, b=2, c=3}", Objects.requireNonNull(map).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class Issue3497Test {
|
|||||||
entry.setKey(StrUtil.toCamelCase(entry.getKey().toString()));
|
entry.setKey(StrUtil.toCamelCase(entry.getKey().toString()));
|
||||||
return entry;
|
return entry;
|
||||||
}));
|
}));
|
||||||
Assertions.assertEquals(bean.toString(), "{aB=1}");
|
Assertions.assertEquals("{aB=1}", bean.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,7 @@ public class CacheTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TimedCache的数据过期后不是每次都触发监听器onRemove,而是偶尔触发onRemove
|
* TimedCache的数据过期后不是每次都触发监听器onRemove,而是偶尔触发onRemove
|
||||||
* https://gitee.com/chinabugotech/hutool/issues/IBP752
|
* <a href="https://gitee.com/chinabugotech/hutool/issues/IBP752">issues#IBP752</a>
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void whenContainsKeyTimeoutShouldCallOnRemove() {
|
public void whenContainsKeyTimeoutShouldCallOnRemove() {
|
||||||
@ -153,9 +153,7 @@ public class CacheTest {
|
|||||||
final TimedCache<Integer, String> ALARM_CACHE = new TimedCache<>(timeout);
|
final TimedCache<Integer, String> ALARM_CACHE = new TimedCache<>(timeout);
|
||||||
|
|
||||||
final AtomicInteger counter = new AtomicInteger(0);
|
final AtomicInteger counter = new AtomicInteger(0);
|
||||||
ALARM_CACHE.setListener((key, value) -> {
|
ALARM_CACHE.setListener((key, value) -> counter.incrementAndGet());
|
||||||
counter.incrementAndGet();
|
|
||||||
});
|
|
||||||
|
|
||||||
ALARM_CACHE.put(1, "value1");
|
ALARM_CACHE.put(1, "value1");
|
||||||
|
|
||||||
@ -167,7 +165,7 @@ public class CacheTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ReentrantCache类clear()方法、AbstractCache.putWithoutLock方法可能导致资源泄露
|
* ReentrantCache类clear()方法、AbstractCache.putWithoutLock方法可能导致资源泄露
|
||||||
* https://github.com/chinabugotech/hutool/issues/3957
|
* <a href="https://github.com/chinabugotech/hutool/issues/3957">issues#3957</a>
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void reentrantCacheClearMethodTest() {
|
public void reentrantCacheClearMethodTest() {
|
||||||
|
|||||||
@ -35,15 +35,15 @@ public class MorseTest {
|
|||||||
public void test1() {
|
public void test1() {
|
||||||
final String text = "你好,世界!";
|
final String text = "你好,世界!";
|
||||||
final String morse = "-..----.--...../-.--..-.-----.-/--------....--../-..---....-.--./---.-.-.-..--../--------.......-/";
|
final String morse = "-..----.--...../-.--..-.-----.-/--------....--../-..---....-.--./---.-.-.-..--../--------.......-/";
|
||||||
Assertions.assertEquals(morseCoder.encode(text), morse);
|
Assertions.assertEquals(morse, morseCoder.encode(text));
|
||||||
Assertions.assertEquals(morseCoder.decode(morse), text);
|
Assertions.assertEquals(text, morseCoder.decode(morse));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test2() {
|
public void test2() {
|
||||||
final String text = "こんにちは";
|
final String text = "こんにちは";
|
||||||
final String morse = "--.....-.-..--/--....-..-..--/--.....--.-.--/--.....--....-/--.....--.----/";
|
final String morse = "--.....-.-..--/--....-..-..--/--.....--.-.--/--.....--....-/--.....--.----/";
|
||||||
Assertions.assertEquals(morseCoder.encode(text), morse);
|
Assertions.assertEquals(morse, morseCoder.encode(text));
|
||||||
Assertions.assertEquals(morseCoder.decode(morse), text);
|
Assertions.assertEquals(text, morseCoder.decode(morse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -172,13 +172,15 @@ public class CollStreamUtilTest {
|
|||||||
|
|
||||||
// 对null友好
|
// 对null友好
|
||||||
final Map<Long, Map<Long, Student>> termIdClassIdStudentMap = CollStreamUtil.group2Map(Arrays.asList(null, new Student(2, 2, 1, "王五")), Student::getTermId, Student::getClassId);
|
final Map<Long, Map<Long, Student>> termIdClassIdStudentMap = CollStreamUtil.group2Map(Arrays.asList(null, new Student(2, 2, 1, "王五")), Student::getTermId, Student::getClassId);
|
||||||
final Map<Long, Map<Long, Student>> termIdClassIdStudentCompareMap = new HashMap<Long, Map<Long, Student>>() {
|
final Map<Long, Map<Long, Student>> termIdClassIdStudentCompareMap = new HashMap<>() {
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(null, MapUtil.empty());
|
put(null, MapUtil.empty());
|
||||||
put(2L, MapUtil.of(2L, new Student(2, 2, 1, "王五")));
|
put(2L, MapUtil.of(2L, new Student(2, 2, 1, "王五")));
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
assertEquals(termIdClassIdStudentCompareMap, termIdClassIdStudentMap);
|
assertEquals(termIdClassIdStudentCompareMap, termIdClassIdStudentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,9 +377,7 @@ public class CollStreamUtilTest {
|
|||||||
list.add(null);
|
list.add(null);
|
||||||
list.add(new Student(1, 2, 2L, null));
|
list.add(new Student(1, 2, 2L, null));
|
||||||
|
|
||||||
assertThrows(NullPointerException.class, () -> {
|
assertThrows(NullPointerException.class, () -> CollStreamUtil.toMap(list, Student::getStudentId, Student::getName));
|
||||||
CollStreamUtil.toMap(list, Student::getStudentId, Student::getName);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -57,7 +57,7 @@ public class MapProxyTest {
|
|||||||
public void classProxyTest() {
|
public void classProxyTest() {
|
||||||
final Student student = MapProxy.of(new HashMap<>()).toProxyBean(Student.class);
|
final Student student = MapProxy.of(new HashMap<>()).toProxyBean(Student.class);
|
||||||
student.setName("小明").setAge(18);
|
student.setName("小明").setAge(18);
|
||||||
Assertions.assertEquals(student.getAge(), 18);
|
Assertions.assertEquals(18, student.getAge());
|
||||||
Assertions.assertEquals(student.getName(), "小明");
|
Assertions.assertEquals("小明", student.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class ConvertOtherTest {
|
|||||||
Assertions.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode);
|
Assertions.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode);
|
||||||
|
|
||||||
final String raw = ConvertUtil.unicodeToStr(unicode);
|
final String raw = ConvertUtil.unicodeToStr(unicode);
|
||||||
Assertions.assertEquals(raw, a);
|
Assertions.assertEquals(a, raw);
|
||||||
|
|
||||||
// 针对有特殊空白符的Unicode
|
// 针对有特殊空白符的Unicode
|
||||||
final String str = "你 好";
|
final String str = "你 好";
|
||||||
@ -63,7 +63,7 @@ public class ConvertOtherTest {
|
|||||||
// 转换后result为乱码
|
// 转换后result为乱码
|
||||||
final String result = ConvertUtil.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1);
|
final String result = ConvertUtil.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1);
|
||||||
final String raw = ConvertUtil.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8");
|
final String raw = ConvertUtil.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8");
|
||||||
Assertions.assertEquals(raw, a);
|
Assertions.assertEquals(a, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -353,7 +353,7 @@ public class ConvertTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toSetTest(){
|
public void toSetTest(){
|
||||||
final Set<Integer> result = ConvertUtil.convert(new TypeReference<Set<Integer>>() {
|
final Set<Integer> result = ConvertUtil.convert(new TypeReference<>() {
|
||||||
}, "1,2,3");
|
}, "1,2,3");
|
||||||
assertEquals(SetUtil.of(1,2,3), result);
|
assertEquals(SetUtil.of(1,2,3), result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,14 +41,14 @@ public class ConvertToArrayTest {
|
|||||||
final String[] b = { "1", "2", "3", "4" };
|
final String[] b = { "1", "2", "3", "4" };
|
||||||
|
|
||||||
final Integer[] integerArray = ConvertUtil.toIntArray(b);
|
final Integer[] integerArray = ConvertUtil.toIntArray(b);
|
||||||
Assertions.assertArrayEquals(integerArray, new Integer[]{1,2,3,4});
|
Assertions.assertArrayEquals(new Integer[]{1,2,3,4}, integerArray);
|
||||||
|
|
||||||
final int[] intArray = ConvertUtil.convert(int[].class, b);
|
final int[] intArray = ConvertUtil.convert(int[].class, b);
|
||||||
Assertions.assertArrayEquals(intArray, new int[]{1,2,3,4});
|
Assertions.assertArrayEquals(new int[]{1,2,3,4}, intArray);
|
||||||
|
|
||||||
final long[] c = {1,2,3,4,5};
|
final long[] c = {1,2,3,4,5};
|
||||||
final Integer[] intArray2 = ConvertUtil.toIntArray(c);
|
final Integer[] intArray2 = ConvertUtil.toIntArray(c);
|
||||||
Assertions.assertArrayEquals(intArray2, new Integer[]{1,2,3,4,5});
|
Assertions.assertArrayEquals(new Integer[]{1,2,3,4,5}, intArray2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -57,7 +57,7 @@ public class ConvertToArrayTest {
|
|||||||
|
|
||||||
final ArrayConverter arrayConverter = new ArrayConverter(true);
|
final ArrayConverter arrayConverter = new ArrayConverter(true);
|
||||||
final Integer[] integerArray = arrayConverter.convert(Integer[].class, b, null);
|
final Integer[] integerArray = arrayConverter.convert(Integer[].class, b, null);
|
||||||
Assertions.assertArrayEquals(integerArray, new Integer[]{null, 1});
|
Assertions.assertArrayEquals(new Integer[]{null, 1}, integerArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -65,14 +65,14 @@ public class ConvertToArrayTest {
|
|||||||
final String[] b = { "1", "2", "3", "4" };
|
final String[] b = { "1", "2", "3", "4" };
|
||||||
|
|
||||||
final Long[] longArray = ConvertUtil.toLongArray(b);
|
final Long[] longArray = ConvertUtil.toLongArray(b);
|
||||||
Assertions.assertArrayEquals(longArray, new Long[]{1L,2L,3L,4L});
|
Assertions.assertArrayEquals(new Long[]{1L,2L,3L,4L}, longArray);
|
||||||
|
|
||||||
final long[] longArray2 = ConvertUtil.convert(long[].class, b);
|
final long[] longArray2 = ConvertUtil.convert(long[].class, b);
|
||||||
Assertions.assertArrayEquals(longArray2, new long[]{1L,2L,3L,4L});
|
Assertions.assertArrayEquals(new long[]{1L,2L,3L,4L}, longArray2);
|
||||||
|
|
||||||
final int[] c = {1,2,3,4,5};
|
final int[] c = {1,2,3,4,5};
|
||||||
final Long[] intArray2 = ConvertUtil.toLongArray(c);
|
final Long[] intArray2 = ConvertUtil.toLongArray(c);
|
||||||
Assertions.assertArrayEquals(intArray2, new Long[]{1L,2L,3L,4L,5L});
|
Assertions.assertArrayEquals(new Long[]{1L,2L,3L,4L,5L}, intArray2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -80,14 +80,14 @@ public class ConvertToArrayTest {
|
|||||||
final String[] b = { "1", "2", "3", "4" };
|
final String[] b = { "1", "2", "3", "4" };
|
||||||
|
|
||||||
final Double[] doubleArray = ConvertUtil.toDoubleArray(b);
|
final Double[] doubleArray = ConvertUtil.toDoubleArray(b);
|
||||||
Assertions.assertArrayEquals(doubleArray, new Double[]{1D,2D,3D,4D});
|
Assertions.assertArrayEquals(new Double[]{1D,2D,3D,4D}, doubleArray);
|
||||||
|
|
||||||
final double[] doubleArray2 = ConvertUtil.convert(double[].class, b);
|
final double[] doubleArray2 = ConvertUtil.convert(double[].class, b);
|
||||||
Assertions.assertArrayEquals(doubleArray2, new double[]{1D,2D,3D,4D}, 2);
|
Assertions.assertArrayEquals(new double[]{1D,2D,3D,4D}, doubleArray2, 2);
|
||||||
|
|
||||||
final int[] c = {1,2,3,4,5};
|
final int[] c = {1,2,3,4,5};
|
||||||
final Double[] intArray2 = ConvertUtil.toDoubleArray(c);
|
final Double[] intArray2 = ConvertUtil.toDoubleArray(c);
|
||||||
Assertions.assertArrayEquals(intArray2, new Double[]{1D,2D,3D,4D,5D});
|
Assertions.assertArrayEquals(new Double[]{1D,2D,3D,4D,5D}, intArray2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -46,8 +46,8 @@ public class ConvertToBeanTest {
|
|||||||
person.setSubName("sub名字");
|
person.setSubName("sub名字");
|
||||||
|
|
||||||
final Map<?, ?> map = ConvertUtil.convert(Map.class, person);
|
final Map<?, ?> map = ConvertUtil.convert(Map.class, person);
|
||||||
assertEquals(map.get("name"), "测试A11");
|
assertEquals("测试A11", map.get("name"));
|
||||||
assertEquals(map.get("age"), 14);
|
assertEquals(14, map.get("age"));
|
||||||
assertEquals("11213232", map.get("openid"));
|
assertEquals("11213232", map.get("openid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,7 @@ public class ConvertToBeanTest {
|
|||||||
assertEquals("14", map.get("age"));
|
assertEquals("14", map.get("age"));
|
||||||
assertEquals("11213232", map.get("openid"));
|
assertEquals("11213232", map.get("openid"));
|
||||||
|
|
||||||
final LinkedHashMap<String, String> map2 = ConvertUtil.convert(
|
final LinkedHashMap<String, String> map2 = ConvertUtil.convert(new TypeReference<>() {}, person);
|
||||||
new TypeReference<LinkedHashMap<String, String>>() {}, person);
|
|
||||||
assertEquals("测试A11", map2.get("name"));
|
assertEquals("测试A11", map2.get("name"));
|
||||||
assertEquals("14", map2.get("age"));
|
assertEquals("14", map2.get("age"));
|
||||||
assertEquals("11213232", map2.get("openid"));
|
assertEquals("11213232", map2.get("openid"));
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toCollectionTest() {
|
public void toCollectionTest() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<?> list = (List<?>) ConvertUtil.convert(Collection.class, a);
|
final List<?> list = (List<?>) ConvertUtil.convert(Collection.class, a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
@ -49,7 +49,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toListTest() {
|
public void toListTest() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<?> list = ConvertUtil.toList(a);
|
final List<?> list = ConvertUtil.toList(a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
@ -60,7 +60,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toListTest2() {
|
public void toListTest2() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<String> list = ConvertUtil.toList(String.class, a);
|
final List<String> list = ConvertUtil.toList(String.class, a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
@ -71,7 +71,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toListTest3() {
|
public void toListTest3() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<String> list = ConvertUtil.toList(String.class, a);
|
final List<String> list = ConvertUtil.toList(String.class, a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
@ -82,8 +82,8 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toListTest4() {
|
public void toListTest4() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<String> list = ConvertUtil.convert(new TypeReference<List<String>>() {}, a);
|
final List<String> list = ConvertUtil.convert(new TypeReference<>() {}, a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
Assertions.assertEquals("好", list.get(2));
|
Assertions.assertEquals("好", list.get(2));
|
||||||
@ -131,7 +131,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toLinkedListTest() {
|
public void toLinkedListTest() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final List<?> list = ConvertUtil.convert(LinkedList.class, a);
|
final List<?> list = ConvertUtil.convert(LinkedList.class, a);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
Assertions.assertEquals("你", list.get(1));
|
Assertions.assertEquals("你", list.get(1));
|
||||||
@ -142,7 +142,7 @@ public class ConvertToCollectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toSetTest() {
|
public void toSetTest() {
|
||||||
final Object[] a = { "a", "你", "好", "", 1 };
|
final Object[] a = {"a", "你", "好", "", 1};
|
||||||
final LinkedHashSet<?> set = ConvertUtil.convert(LinkedHashSet.class, a);
|
final LinkedHashSet<?> set = ConvertUtil.convert(LinkedHashSet.class, a);
|
||||||
final ArrayList<?> list = ListUtil.of(set);
|
final ArrayList<?> list = ListUtil.of(set);
|
||||||
Assertions.assertEquals("a", list.get(0));
|
Assertions.assertEquals("a", list.get(0));
|
||||||
|
|||||||
@ -82,6 +82,6 @@ public class DateConvertTest {
|
|||||||
|
|
||||||
final String str = "2020-12-12 12:12:12.0";
|
final String str = "2020-12-12 12:12:12.0";
|
||||||
ldt = ConvertUtil.toLocalDateTime(str);
|
ldt = ConvertUtil.toLocalDateTime(str);
|
||||||
Assertions.assertEquals(ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")), str);
|
Assertions.assertEquals(str, ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,9 +30,7 @@ public class PrimitiveConvertTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toIntErrorTest(){
|
public void toIntErrorTest(){
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
Assertions.assertThrows(IllegalArgumentException.class, ()-> ConvertUtil.convert(int.class, "aaaa"));
|
||||||
ConvertUtil.convert(int.class, "aaaa");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -191,7 +191,7 @@ public class IdcardUtilTest {
|
|||||||
assertTrue(IdcardUtil.isValidCard(FOREIGN_ID_18));
|
assertTrue(IdcardUtil.isValidCard(FOREIGN_ID_18));
|
||||||
|
|
||||||
final Date date = DateUtil.parse("2017-04-10");
|
final Date date = DateUtil.parse("2017-04-10");
|
||||||
assertEquals(IdcardUtil.getAge(FOREIGN_ID_18, date), 32);
|
assertEquals(32, IdcardUtil.getAge(FOREIGN_ID_18, date));
|
||||||
|
|
||||||
// 新版外国人永久居留身份证
|
// 新版外国人永久居留身份证
|
||||||
assertTrue(IdcardUtil.isValidCard18("932682198501010017"));
|
assertTrue(IdcardUtil.isValidCard18("932682198501010017"));
|
||||||
|
|||||||
@ -149,9 +149,7 @@ public class NanoIdTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomNanoIdEmptyAlphabetExceptionThrownTest() {
|
public void randomNanoIdEmptyAlphabetExceptionThrownTest() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
Assertions.assertThrows(IllegalArgumentException.class, ()-> NanoId.randomNanoId(new SecureRandom(), new char[]{}, 10));
|
||||||
NanoId.randomNanoId(new SecureRandom(), new char[]{}, 10);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -170,15 +168,11 @@ public class NanoIdTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomNanoIdNegativeSizeExceptionThrown() {
|
public void randomNanoIdNegativeSizeExceptionThrown() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
Assertions.assertThrows(IllegalArgumentException.class, ()-> NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, -10));
|
||||||
NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, -10);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void randomNanoIdZeroSizeExceptionThrown() {
|
public void randomNanoIdZeroSizeExceptionThrown() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
Assertions.assertThrows(IllegalArgumentException.class, ()-> NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, 0));
|
||||||
NanoId.randomNanoId(new SecureRandom(), new char[]{'a', 'b', 'c'}, 0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,22 +23,19 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class BetweenFormatterTest {
|
public class BetweenFormatterTest {
|
||||||
|
|
||||||
Function<BetweenFormatter.Level, String> levelFormatterEn = level -> {
|
Function<BetweenFormatter.Level, String> levelFormatterEn = level -> switch (level) {
|
||||||
return switch (level) {
|
|
||||||
case DAY -> " day";
|
case DAY -> " day";
|
||||||
case HOUR -> " hour";
|
case HOUR -> " hour";
|
||||||
case MINUTE -> " minute";
|
case MINUTE -> " minute";
|
||||||
case SECOND -> " second";
|
case SECOND -> " second";
|
||||||
case MILLISECOND -> " millisecond";
|
case MILLISECOND -> " millisecond";
|
||||||
default -> " " + level.name();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formatTest() {
|
public void formatTest() {
|
||||||
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2017-01-01 22:59:59"), DateUtil.parse("2017-01-02 23:59:58"));
|
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2017-01-01 22:59:59"), DateUtil.parse("2017-01-02 23:59:58"));
|
||||||
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.MILLISECOND, 1);
|
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.MILLISECOND, 1);
|
||||||
Assertions.assertEquals(formatter.toString(), "1天");
|
Assertions.assertEquals("1天", formatter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -46,27 +43,27 @@ public class BetweenFormatterTest {
|
|||||||
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2017-01-01 22:59:59"), DateUtil.parse("2017-01-02 23:59:58"));
|
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2017-01-01 22:59:59"), DateUtil.parse("2017-01-02 23:59:58"));
|
||||||
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.MILLISECOND, 1);
|
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.MILLISECOND, 1);
|
||||||
formatter.setLevelFormatter(levelFormatterEn);
|
formatter.setLevelFormatter(levelFormatterEn);
|
||||||
Assertions.assertEquals(formatter.toString(), "1 day");
|
Assertions.assertEquals("1 day", formatter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formatBetweenTest() {
|
public void formatBetweenTest() {
|
||||||
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 11:23:19"), DateUtil.parse("2018-07-16 11:23:20"));
|
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 11:23:19"), DateUtil.parse("2018-07-16 11:23:20"));
|
||||||
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.SECOND, 1);
|
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.SECOND, 1);
|
||||||
Assertions.assertEquals(formatter.toString(), "1秒");
|
Assertions.assertEquals("1秒", formatter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formatBetweenTest2() {
|
public void formatBetweenTest2() {
|
||||||
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 12:25:23"), DateUtil.parse("2018-07-16 11:23:20"));
|
final long betweenMs = DateUtil.betweenMs(DateUtil.parse("2018-07-16 12:25:23"), DateUtil.parse("2018-07-16 11:23:20"));
|
||||||
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.SECOND, 5);
|
final BetweenFormatter formatter = new BetweenFormatter(betweenMs, BetweenFormatter.Level.SECOND, 5);
|
||||||
Assertions.assertEquals(formatter.toString(), "1小时2分3秒");
|
Assertions.assertEquals("1小时2分3秒", formatter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formatTest2() {
|
public void formatTest2() {
|
||||||
final BetweenFormatter formatter = new BetweenFormatter(584, BetweenFormatter.Level.SECOND, 1);
|
final BetweenFormatter formatter = new BetweenFormatter(584, BetweenFormatter.Level.SECOND, 1);
|
||||||
Assertions.assertEquals(formatter.toString(), "0秒");
|
Assertions.assertEquals("0秒", formatter.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -53,9 +53,7 @@ public class QuarterTest {
|
|||||||
assertEquals(3, Objects.requireNonNull(quarter).getValue());
|
assertEquals(3, Objects.requireNonNull(quarter).getValue());
|
||||||
assertEquals("Q3", quarter.name());
|
assertEquals("Q3", quarter.name());
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> Quarter.valueOf("Abc"));
|
||||||
Quarter.valueOf("Abc");
|
|
||||||
});
|
|
||||||
|
|
||||||
final Month firstMonth = quarter.firstMonth();
|
final Month firstMonth = quarter.firstMonth();
|
||||||
assertEquals(Month.JULY, firstMonth);
|
assertEquals(Month.JULY, firstMonth);
|
||||||
@ -69,12 +67,10 @@ public class QuarterTest {
|
|||||||
final Quarter quarter = Quarter.of(4);
|
final Quarter quarter = Quarter.of(4);
|
||||||
assertSame(Quarter.Q4, quarter);
|
assertSame(Quarter.Q4, quarter);
|
||||||
assertSame(quarter, Quarter.valueOf("Q4"));
|
assertSame(quarter, Quarter.valueOf("Q4"));
|
||||||
assertEquals(4, quarter.getValue());
|
assertEquals(4, Objects.requireNonNull(quarter).getValue());
|
||||||
assertEquals("Q4", quarter.name());
|
assertEquals("Q4", quarter.name());
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> Quarter.valueOf("Q5"));
|
||||||
Quarter.valueOf("Q5");
|
|
||||||
});
|
|
||||||
|
|
||||||
final Month firstMonth = quarter.firstMonth();
|
final Month firstMonth = quarter.firstMonth();
|
||||||
assertEquals(Month.OCTOBER, firstMonth);
|
assertEquals(Month.OCTOBER, firstMonth);
|
||||||
|
|||||||
@ -329,9 +329,7 @@ public class LambdaUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
void getInvokeMethodErrorTest() {
|
void getInvokeMethodErrorTest() {
|
||||||
// 非函数接口返回异常
|
// 非函数接口返回异常
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
Assertions.assertThrows(IllegalArgumentException.class, () -> LambdaUtil.getInvokeMethod(LambdaUtilTest.class));
|
||||||
LambdaUtil.getInvokeMethod(LambdaUtilTest.class);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@ -17,14 +17,12 @@
|
|||||||
package cn.hutool.v7.core.func;
|
package cn.hutool.v7.core.func;
|
||||||
|
|
||||||
import cn.hutool.v7.core.collection.set.SetUtil;
|
import cn.hutool.v7.core.collection.set.SetUtil;
|
||||||
import cn.hutool.v7.core.func.PredicateUtil;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class PredicateUtilTest {
|
public class PredicateUtilTest {
|
||||||
@ -34,7 +32,7 @@ public class PredicateUtilTest {
|
|||||||
final Set<String> sets = SetUtil.of("1", "2", "3");
|
final Set<String> sets = SetUtil.of("1", "2", "3");
|
||||||
final List<String> collect = Stream.of("3", "4", "5")
|
final List<String> collect = Stream.of("3", "4", "5")
|
||||||
.filter(PredicateUtil.negate(sets::contains))
|
.filter(PredicateUtil.negate(sets::contains))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
Assertions.assertEquals(2, collect.size());
|
Assertions.assertEquals(2, collect.size());
|
||||||
Assertions.assertEquals("4", collect.get(0));
|
Assertions.assertEquals("4", collect.get(0));
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class FileSystemUtilTest {
|
|||||||
final FileSystem fileSystem = FileSystemUtil.createZip("d:/test/test.zip",
|
final FileSystem fileSystem = FileSystemUtil.createZip("d:/test/test.zip",
|
||||||
CharsetUtil.GBK);
|
CharsetUtil.GBK);
|
||||||
final Path root = FileSystemUtil.getRoot(fileSystem);
|
final Path root = FileSystemUtil.getRoot(fileSystem);
|
||||||
PathUtil.walkFiles(root, new SimpleFileVisitor<Path>() {
|
PathUtil.walkFiles(root, new SimpleFileVisitor<>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) {
|
||||||
|
|||||||
@ -506,9 +506,7 @@ public class FileUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkSlipTest() {
|
void checkSlipTest() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
Assertions.assertThrows(IllegalArgumentException.class, () -> FileUtil.checkSlip(FileUtil.file("test/a"), FileUtil.file("test/../a")));
|
||||||
FileUtil.checkSlip(FileUtil.file("test/a"), FileUtil.file("test/../a"));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -537,15 +535,11 @@ public class FileUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSub_NullParentTest() {
|
public void isSub_NullParentTest() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> FileUtil.isSub(null, new File("d:/any/path")));
|
||||||
FileUtil.isSub(null, new java.io.File("d:/any/path"));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSub_NullSubTest() {
|
public void isSub_NullSubTest() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> {
|
assertThrows(IllegalArgumentException.class, () -> FileUtil.isSub(new File("d:/any/path"), null));
|
||||||
FileUtil.isSub(new java.io.File("d:/any/path"), null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,12 +84,10 @@ public class SingletonTest {
|
|||||||
final String key = "123";
|
final String key = "123";
|
||||||
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
|
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
threadPoolExecutor.execute(() -> {
|
threadPoolExecutor.execute(() -> Singleton.get(key, () -> {
|
||||||
Singleton.get(key, () -> {
|
|
||||||
System.out.println(key);
|
System.out.println(key);
|
||||||
return "123";
|
return "123";
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadUtil.sleep(5000);
|
ThreadUtil.sleep(5000);
|
||||||
|
|||||||
@ -311,11 +311,11 @@ public class ValidatorTest {
|
|||||||
public void validateByteLengthTest() {
|
public void validateByteLengthTest() {
|
||||||
final String s1 = "abc";
|
final String s1 = "abc";
|
||||||
final int len1 = StrUtil.byteLength(s1, CharsetUtil.UTF_8);
|
final int len1 = StrUtil.byteLength(s1, CharsetUtil.UTF_8);
|
||||||
Assertions.assertEquals(len1, 3);
|
Assertions.assertEquals(3, len1);
|
||||||
|
|
||||||
final String s2 = "我ab";
|
final String s2 = "我ab";
|
||||||
final int len2 = StrUtil.byteLength(s2, CharsetUtil.UTF_8);
|
final int len2 = StrUtil.byteLength(s2, CharsetUtil.UTF_8);
|
||||||
Assertions.assertEquals(len2, 5);
|
Assertions.assertEquals(5, len2);
|
||||||
|
|
||||||
//一个汉字在utf-8编码下,占3个字节。
|
//一个汉字在utf-8编码下,占3个字节。
|
||||||
Assertions.assertThrows(ValidateException.class, ()->
|
Assertions.assertThrows(ValidateException.class, ()->
|
||||||
|
|||||||
@ -128,8 +128,8 @@ abstract class BaseMutableTest<V, M extends Mutable<V>> {
|
|||||||
final Mutable<V> mutableObj = new MutableObj<>(value);
|
final Mutable<V> mutableObj = new MutableObj<>(value);
|
||||||
Assertions.assertNotEquals(value, mutableObj);
|
Assertions.assertNotEquals(value, mutableObj);
|
||||||
Assertions.assertEquals(mutableObj, new MutableObj<>(value));
|
Assertions.assertEquals(mutableObj, new MutableObj<>(value));
|
||||||
Assertions.assertNotEquals(mutableObj, new MutableObj<>(null));
|
Assertions.assertNotEquals(new MutableObj<>(null), mutableObj);
|
||||||
Assertions.assertNotEquals(mutableObj, null);
|
Assertions.assertNotEquals(null, mutableObj);
|
||||||
Assertions.assertNotEquals(mutableObj, value);
|
Assertions.assertNotEquals(mutableObj, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,10 +29,10 @@ public class BoundTest {
|
|||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
final Bound<Integer> bound = new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND);
|
final Bound<Integer> bound = new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND);
|
||||||
Assertions.assertEquals(bound, bound);
|
Assertions.assertEquals(bound, bound);
|
||||||
Assertions.assertEquals(bound, new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND));
|
Assertions.assertEquals(new FiniteBound<>(1, BoundType.OPEN_UPPER_BOUND), bound);
|
||||||
Assertions.assertNotEquals(bound, new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND));
|
Assertions.assertNotEquals(new FiniteBound<>(2, BoundType.OPEN_UPPER_BOUND), bound);
|
||||||
Assertions.assertNotEquals(bound, new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND));
|
Assertions.assertNotEquals(new FiniteBound<>(1, BoundType.OPEN_LOWER_BOUND), bound);
|
||||||
Assertions.assertNotEquals(bound, null);
|
Assertions.assertNotEquals(null, bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class BoundedRangeTest {
|
|||||||
final BoundedRange<Integer> range = new BoundedRange<>(
|
final BoundedRange<Integer> range = new BoundedRange<>(
|
||||||
Bound.greaterThan(0), Bound.lessThan(10)
|
Bound.greaterThan(0), Bound.lessThan(10)
|
||||||
);
|
);
|
||||||
Assertions.assertNotEquals(range, null);
|
Assertions.assertNotEquals(null, range);
|
||||||
Assertions.assertEquals(range, new BoundedRange<>(
|
Assertions.assertEquals(range, new BoundedRange<>(
|
||||||
Bound.greaterThan(0), Bound.lessThan(10)
|
Bound.greaterThan(0), Bound.lessThan(10)
|
||||||
));
|
));
|
||||||
|
|||||||
@ -62,10 +62,10 @@ public class RangeTest {
|
|||||||
final Date end = DateUtil.parse("2021-01-03");
|
final Date end = DateUtil.parse("2021-01-03");
|
||||||
|
|
||||||
final List<Integer> dayOfMonthList = DateUtil.rangeFunc(start, end, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth());
|
final List<Integer> dayOfMonthList = DateUtil.rangeFunc(start, end, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth());
|
||||||
Assertions.assertArrayEquals(dayOfMonthList.toArray(new Integer[]{}), new Integer[]{1, 2, 3});
|
Assertions.assertArrayEquals(new Integer[]{1, 2, 3}, dayOfMonthList.toArray(new Integer[]{}));
|
||||||
|
|
||||||
final List<Integer> dayOfMonthList2 = DateUtil.rangeFunc(null, null, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth());
|
final List<Integer> dayOfMonthList2 = DateUtil.rangeFunc(null, null, DateField.DAY_OF_YEAR, a -> DateTime.of(a).dayOfMonth());
|
||||||
Assertions.assertArrayEquals(dayOfMonthList2.toArray(new Integer[]{}), new Integer[]{});
|
Assertions.assertArrayEquals(new Integer[]{}, dayOfMonthList2.toArray(new Integer[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -75,11 +75,11 @@ public class RangeTest {
|
|||||||
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
DateUtil.rangeConsume(start, end, DateField.DAY_OF_YEAR, a -> sb.append(DateTime.of(a).dayOfMonth()).append("#"));
|
DateUtil.rangeConsume(start, end, DateField.DAY_OF_YEAR, a -> sb.append(DateTime.of(a).dayOfMonth()).append("#"));
|
||||||
Assertions.assertEquals(sb.toString(), "1#2#3#");
|
Assertions.assertEquals("1#2#3#", sb.toString());
|
||||||
|
|
||||||
final StringBuilder sb2 = new StringBuilder();
|
final StringBuilder sb2 = new StringBuilder();
|
||||||
DateUtil.rangeConsume(null, null, DateField.DAY_OF_YEAR, a -> sb2.append(DateTime.of(a).dayOfMonth()).append("#"));
|
DateUtil.rangeConsume(null, null, DateField.DAY_OF_YEAR, a -> sb2.append(DateTime.of(a).dayOfMonth()).append("#"));
|
||||||
Assertions.assertEquals(sb2.toString(), StrUtil.EMPTY);
|
Assertions.assertEquals(StrUtil.EMPTY, sb2.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -55,8 +55,6 @@ public class DirectedWeightGraphTest {
|
|||||||
|
|
||||||
graph.removePoint("X");
|
graph.removePoint("X");
|
||||||
|
|
||||||
Assertions.assertThrows(DirectedWeightGraph.NegativeRingException.class, ()->{
|
Assertions.assertThrows(DirectedWeightGraph.NegativeRingException.class, ()-> graph.bestPathMap("A"));
|
||||||
graph.bestPathMap("A");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,8 +29,6 @@ public class Issue2349Test {
|
|||||||
final ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
|
final ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// JDK9+ has been resolved JDK-8161372 bug, when cause dead then throw IllegalStateException
|
// JDK9+ has been resolved JDK-8161372 bug, when cause dead then throw IllegalStateException
|
||||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
Assertions.assertThrows(IllegalStateException.class, () -> map.computeIfAbsent("AaAa", key -> map.computeIfAbsent("BBBB", key2 -> 42)));
|
||||||
map.computeIfAbsent("AaAa", key -> map.computeIfAbsent("BBBB", key2 -> 42));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,9 +32,9 @@ public class MapBuilderTest {
|
|||||||
.put(false, "d", () -> getValue(4))
|
.put(false, "d", () -> getValue(4))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertEquals(map.get("a"), "1");
|
Assertions.assertEquals("1", map.get("a"));
|
||||||
Assertions.assertFalse(map.containsKey("b"));
|
Assertions.assertFalse(map.containsKey("b"));
|
||||||
Assertions.assertEquals(map.get("c"), "3");
|
Assertions.assertEquals("3", map.get("c"));
|
||||||
Assertions.assertFalse(map.containsKey("d"));
|
Assertions.assertFalse(map.containsKey("d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user