diff --git a/.gitignore b/.gitignore
index 54cc59ee4..0380a6557 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,4 @@ node_modules
.settings/
target/
.idea/
-docs/doc/
+docs/doc/
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3487a781d..7c4375a2a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,97 @@
===========================
+## [3.0.0](https://github.com/buession/buessionframework/releases/tag/v3.0.0) (2024-11-07)
+
+### 🔨依赖升级
+
+- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v3.0.0)
+
+
+### ⭐ 新特性
+
+- ClassUtils 新增检测类是否存在方法 isPresent
+- 新增 list 到 set 转换器 ListSetConverter
+- 新增 set 到 list 转换器 SetListConverter
+- 新增断言转换器 PredicateConverter
+- 新增 集合转换器 CollectionConverter
+- 新增 Map.Entry 到 Map 转换器 MapEntryMapConverter
+- httpClient Configuration 新增 expectContinueEnabled、hardCancellationEnabled、targetPreferredAuthSchemes、cookieSpec、proxy 配置
+- httpClient 新增代理支持
+- ApacheClient 新增支持 apache httpcomponents 5,根据依赖的 apache httpcomponents 5 和 apache httpcomponents 4 自动判断,优先使用 apache httpcomponents 5
+- 新增支持 Lettuce(stream 命令不稳定,不推荐使用)
+- jedis 模式下,集群支持管道
+- 新增代理方法调用者 ProxyMethodInvoker
+- 新增代理调用处理器 InvocationHandler 抽象类 AbstractInvocationHandler
+- PropertyMapper 增加正数断言 alwaysApplyingWhenPositiveNumber
+- com.buession.io.file.File 新增支持将 InputStream 写入文件
+- JSON 序列化和反序列化支持对原生对象进行配置
+- 增加范围类 Range 及其衍生类
+- 新增日期时间工具类 DateTimeUtils
+
+
+### 🔔 变化
+
+- Maps.toList 参数为 LinkedHashMap 时返回 LinkedList
+- Lists.toSet 参数为 LinkedList 返回 LinkedHashSet
+- Sets.toList 参数为 LinkedHashSet 返回 LinkedList
+- core 包中删除依赖 commons-beanutils
+- 删除 ArrayUtils、StatusUtils、ObjectUtils、MapUtils、BuesssionFrameworkVersion
+- 删除 AbstractAspectAnnotationsMethodInterceptor
+- geoip 删除依赖 apache httpcomponents
+- 废弃 ApacheRequest、ApacheRequestBuilder、ApacheHttpClientBuilder
+- httpClient 优化 ConnectionManager 创建默认原生 ConnectionManager,以解决在创建原生 ConnectionManager 之前,更新了 Configuration 不生效的问题
+- ApacheHttpClient 删除 apache httpcomponents 4 中的特有方法
+- httpClient 参数为 URL 时,不再验证是否为 null
+- apache httpcomponents 异步请求时 HttpAsyncResponseConsumer 采用 ZeroCopyConsumer
+- okhttp maxRequestsPerHost 大于 0 时,才会更新 okhttp 原生 maxRequestsPerHost 的值
+- 删除 OkHttpClient
+- 重构 JDBC 连接池和数据源
+- MyBatisDao 废弃 masterTemplate、slaveSqlSessionTemplate,通过其它数据库本身或其它中间件实现读写分离
+- redis 删除参数为字符串数组或 byte[] 数组的方法 bitField
+- redis 废弃字符串型 / byte[]型 min、max 参数的方法
+- redis role 命令直接返回 Role,不再返回 List<Role>
+- redis 重构管道、事务内部实现
+- redis 哨兵连接,如果指定了连接超时、读取超时,但未指定哨兵节点连接超时、读取超时,哨兵节点连接超时、读取超时也使用该值
+- redis 连接池调整在连接对象中创建,不再在 DataSource 中创建
+- redis 不再推荐从 DataSource 中创建 RedisConnection 实例
+- IO MimeType 忽略大小写比较
+- 删除 com.buession.web.mvc.Response 中参数为 com.buession.core.Pagination 的构造函数和 setter 函数
+- 删除 buession-cron 和 buession-session
+- 删除 MobileFilter、PoweredByHeaderFilter
+- 序列化类删除反序列化方法
+
+
+### 🐞 Bug 修复
+
+- httpClient 修复 ConnectionManager 未设置 connectionManagerShared 时,无法从 Configuration 中获取 connectionManagerShared 值的 BUG
+- 修复 okhttp 设置 followRedirects 时,followSslRedirects 未生效的 BUG
+- 修复 jedis 模式下 role 命令未返回数据的 BUG
+- 修复 jedis 模式下 API 中,“命令”参数设置错误的 BUG
+- 修复 jedis GeoRadiusResponseConverter coordinate 为 null 时,空指针异常
+- 修复 jedis 模式下连接中的错误和参数丢失等问题
+- 修复 Validate IPV4 验证,第一段为 10 ~ 99 时,验证失败的 BUG
+
+
+### ⏪ 优化
+- 优化 redis 转换器,不使用静态属性,以减少内存占用
+- jedis 模式命令运算优化
+- 优化 JDBC 数据源连接池设置
+- 优化 httpclient 配置、连接管理器以及连接客户端
+- 优化默认线程池执行器 DefaultThreadPoolExecutor 初始化
+- com.buession.io.file.File 读取文件优化
+
+
+### 📔 文档
+
+- 完善 redis 注释
+- 修正 httpclient 错误注释
+- 完善 httpclient 注释
+
+
+---
+
+
## [2.3.3](https://github.com/buession/buessionframework/releases/tag/v2.3.3) (2024-05-06)
### 🔨依赖升级
diff --git a/buession-aop/pom.xml b/buession-aop/pom.xml
index 518aa7c6f..25adad0a1 100644
--- a/buession-aop/pom.xml
+++ b/buession-aop/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.3.3
+ 3.0.0
buession-aop
http://www.buession.com/
@@ -61,8 +61,6 @@
aopalliance
aopalliance
- 1.0
- provided
@@ -77,8 +75,8 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-api
@@ -122,8 +120,8 @@
maven-gpg-plugin
- org.sonatype.plugins
- nexus-staging-maven-plugin
+ org.sonatype.central
+ central-publishing-maven-plugin
diff --git a/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java b/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java
new file mode 100644
index 000000000..4c7feb7bf
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.aop;
+
+import com.buession.aop.utils.ProxyUtils;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+/**
+ * {@link InvocationHandler} 抽象类
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public abstract class AbstractInvocationHandler implements InvocationHandler {
+
+ private final static int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED
+ | MethodHandles.Lookup.PUBLIC | MethodHandles.Lookup.PACKAGE;
+
+ protected final static Constructor lookupConstructor;
+
+ protected final static Method privateLookupInMethod;
+
+ static {
+ Method privateLookupIn;
+ try{
+ privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
+ }catch(NoSuchMethodException e){
+ privateLookupIn = null;
+ }
+ privateLookupInMethod = privateLookupIn;
+
+ Constructor lookup = null;
+ if(privateLookupInMethod == null){
+ // JDK 1.8
+ try{
+ lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
+ lookup.setAccessible(true);
+ }catch(NoSuchMethodException e){
+ throw new IllegalStateException(
+ "There is neither 'privateLookupIn(Class, Lookup)' nor 'Lookup(Class, int)' method in java.lang.invoke.MethodHandles.",
+ e);
+ }catch(Exception e){
+ lookup = null;
+ }
+ }
+ lookupConstructor = lookup;
+ }
+
+ @Override
+ public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if(args == null){
+ args = ProxyMethodInvoker.NO_ARGS;
+ }
+
+ if(args.length == 0){
+ if("hashCode".equals(method.getName())){
+ return doHashCode();
+ }else if("toString".equals(method.getName())){
+ return doToString();
+ }
+ }
+
+ if(args.length == 1 && "equals".equals(method.getName()) && method.getParameterTypes()[0] == Object.class){
+ Object arg = args[0];
+ return doEquals(proxy, arg);
+ }
+
+ return doInvoke(proxy, method, args);
+ }
+
+ protected Object doHashCode() {
+ return hashCode();
+ }
+
+ protected Object doEquals(final Object proxy, final Object arg) {
+ if(arg == null){
+ return false;
+ }
+
+ if(proxy == arg){
+ return true;
+ }
+
+ return ProxyUtils.isProxyOfSameInterfaces(arg, proxy.getClass()) && equals(Proxy.getInvocationHandler(arg));
+ }
+
+ protected Object doToString() {
+ return toString();
+ }
+
+ protected Object doInvoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ if(Object.class.equals(method.getDeclaringClass())){
+ return method.invoke(this, args);
+ }
+
+ return handleInvocation(proxy, method, args);
+ }
+
+ protected abstract Object handleInvocation(final Object proxy, final Method method, final Object[] args)
+ throws Throwable;
+
+ protected int getAllowedModes() {
+ return ALLOWED_MODES;
+ }
+
+ protected ProxyMethodInvoker createMethodInvoker(final Method method)
+ throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
+ if(method.isDefault()){
+ final MethodHandle methodHandle = privateLookupInMethod == null ? getMethodHandleJava8(method) :
+ getMethodHandleJava9(method);
+ return new DefaultMethodInvoker<>(methodHandle);
+ }else{
+ return new PlainMethodInvoker<>();
+ }
+ }
+
+ protected MethodHandle getMethodHandleJava8(final Method method)
+ throws IllegalAccessException, InstantiationException, InvocationTargetException {
+ final Class> declaringClass = method.getDeclaringClass();
+ return lookupConstructor.newInstance(declaringClass, getAllowedModes())
+ .unreflectSpecial(method, declaringClass);
+ }
+
+ protected MethodHandle getMethodHandleJava9(final Method method)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ final Class> declaringClass = method.getDeclaringClass();
+ final MethodType methodType = MethodType.methodType(method.getReturnType(), method.getParameterTypes());
+
+ return ((MethodHandles.Lookup) privateLookupInMethod.invoke(null, declaringClass, MethodHandles.lookup()))
+ .findSpecial(declaringClass, method.getName(), methodType, declaringClass);
+ }
+
+}
diff --git a/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java
new file mode 100644
index 000000000..368bd469f
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.aop;
+
+import com.buession.core.utils.Assert;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.reflect.Method;
+
+/**
+ * 默认代理方法调用者
+ *
+ * @param
+ * 代理类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class DefaultMethodInvoker implements ProxyMethodInvoker {
+
+ private final MethodHandle methodHandle;
+
+ /**
+ * 构造函数
+ *
+ * @param methodHandle
+ * {@link MethodHandle}
+ */
+ public DefaultMethodInvoker(final MethodHandle methodHandle) {
+ Assert.isNull(methodHandle, "MethodHandle cloud not be null");
+ this.methodHandle = methodHandle;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable {
+ return methodHandle.bindTo(proxy).invokeWithArguments(args);
+ }
+
+}
diff --git a/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java
new file mode 100644
index 000000000..89b8655d3
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.aop;
+
+import java.lang.reflect.Method;
+
+/**
+ * 简单代理方法调用者
+ *
+ * @param
+ * 代理类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class PlainMethodInvoker implements ProxyMethodInvoker {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable {
+ return method.invoke(object, args);
+ }
+
+}
diff --git a/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java
new file mode 100644
index 000000000..70c7e603c
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.aop;
+
+import java.lang.reflect.Method;
+
+/**
+ * 代理方法调用者
+ *
+ * @param
+ * 代理类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+@FunctionalInterface
+public interface ProxyMethodInvoker {
+
+ Object[] NO_ARGS = {};
+
+ /**
+ * 代理方法调用
+ *
+ * @param proxy
+ * 代理类实例
+ * @param method
+ * 方法
+ * @param args
+ * 参数
+ * @param object
+ * 代理类实例
+ *
+ * @return 返回结果
+ *
+ * @throws Throwable
+ * 异常
+ */
+ Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable;
+
+}
diff --git a/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java b/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java
index de34baa42..34c2c57f4 100644
--- a/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java
+++ b/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.aop.aopalliance;
@@ -42,12 +42,12 @@ public abstract class AbstractAopAllianceAnnotationsMethodInterceptor extends Ab
/**
* 构造函数
*/
- public AbstractAopAllianceAnnotationsMethodInterceptor(){
+ public AbstractAopAllianceAnnotationsMethodInterceptor() {
super();
}
@Override
- public Object invoke(MethodInvocation methodInvocation) throws Throwable{
+ public Object invoke(MethodInvocation methodInvocation) throws Throwable {
com.buession.aop.MethodInvocation mi = createMethodInvocation(methodInvocation);
return super.invoke(mi);
}
@@ -60,32 +60,32 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable{
*
* @return The instance of {@link com.buession.aop.MethodInvocation}
*/
- protected com.buession.aop.MethodInvocation createMethodInvocation(final MethodInvocation mi){
+ protected com.buession.aop.MethodInvocation createMethodInvocation(final MethodInvocation mi) {
return new com.buession.aop.MethodInvocation() {
@Override
- public Object getThis(){
+ public Object getThis() {
return mi.getThis();
}
@Override
- public Method getMethod(){
+ public Method getMethod() {
return mi.getMethod();
}
@Override
- public Object[] getArguments(){
+ public Object[] getArguments() {
return mi.getArguments();
}
@Override
- public Object proceed() throws Throwable{
+ public Object proceed() throws Throwable {
return mi.proceed();
}
@Override
- public String toString(){
- return "Method invocation [" + mi.getMethod() + "]";
+ public String toString() {
+ return "Method invocation [" + mi.getMethod() + ']';
}
};
diff --git a/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java b/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java
new file mode 100644
index 000000000..2330c52fa
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.aop.utils;
+
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * 代理工具类
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class ProxyUtils {
+
+ protected ProxyUtils() {
+
+ }
+
+ /**
+ * 检测对象是否为代理类实例
+ *
+ * @param obj
+ * 待检测对象
+ * @param proxyClass
+ * 代理类
+ *
+ * @return true / false
+ */
+ public static boolean isProxyOfSameInterfaces(Object obj, Class> proxyClass) {
+ return proxyClass.isInstance(obj) || (Proxy.isProxyClass(obj.getClass())
+ && Arrays.equals(obj.getClass().getInterfaces(), proxyClass.getInterfaces()));
+ }
+
+}
diff --git a/buession-aop/src/main/java/com/buession/aop/utils/package-info.java b/buession-aop/src/main/java/com/buession/aop/utils/package-info.java
new file mode 100644
index 000000000..6b9ffff28
--- /dev/null
+++ b/buession-aop/src/main/java/com/buession/aop/utils/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+/**
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+package com.buession.aop.utils;
\ No newline at end of file
diff --git a/buession-beans/pom.xml b/buession-beans/pom.xml
index c1122199b..18e7136b3 100644
--- a/buession-beans/pom.xml
+++ b/buession-beans/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.3.3
+ 3.0.0
buession-beans
http://www.buession.com/
@@ -67,6 +67,10 @@
commons-beanutils
commons-beanutils
+
+ commons-logging
+ commons-logging
+
org.slf4j
@@ -74,8 +78,8 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-api
@@ -119,8 +123,8 @@
maven-gpg-plugin
- org.sonatype.plugins
- nexus-staging-maven-plugin
+ org.sonatype.central
+ central-publishing-maven-plugin
diff --git a/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java b/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java
index 7db05f2d8..31a70da42 100644
--- a/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java
+++ b/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java
@@ -19,13 +19,12 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.beans;
-import org.junit.Test;
-import org.springframework.cglib.beans.BeanMap;
+import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.HashMap;
diff --git a/buession-core/pom.xml b/buession-core/pom.xml
index c76468e7c..aa1d41ff0 100644
--- a/buession-core/pom.xml
+++ b/buession-core/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.3.3
+ 3.0.0
buession-core
http://www.buession.com/
@@ -89,11 +89,6 @@
commons-collections4
-
- commons-beanutils
- commons-beanutils
-
-
jakarta.annotation
jakarta.annotation-api
@@ -113,7 +108,7 @@
com.fasterxml.jackson.core
jackson-databind
- compile
+ provided
true
@@ -121,12 +116,20 @@
com.alibaba
fastjson
provided
+ true
com.google.code.gson
gson
provided
+ true
+
+
+ com.google.errorprone
+ error_prone_annotations
+
+
@@ -140,8 +143,8 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter-api
@@ -185,8 +188,8 @@
maven-gpg-plugin
- org.sonatype.plugins
- nexus-staging-maven-plugin
+ org.sonatype.central
+ central-publishing-maven-plugin
diff --git a/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java
index 457dc2f86..303e74437 100644
--- a/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java
+++ b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2021 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
@@ -34,12 +34,23 @@
*/
public final class BuessionFrameworkVersion {
+ private static String VERSION;
+
private BuessionFrameworkVersion() {
}
+ /**
+ * 获取框架版本
+ *
+ * @return 框架版本
+ */
public static String getVersion() {
- return VersionUtils.determineClassVersion(BuessionFrameworkVersion.class);
+ if(VERSION == null){
+ VERSION = VersionUtils.determineClassVersion(BuessionFrameworkVersion.class);
+ }
+
+ return VERSION;
}
}
diff --git a/buession-core/src/main/java/com/buession/core/Customizer.java b/buession-core/src/main/java/com/buession/core/Customizer.java
index 629e4d44a..149cd6b0f 100644
--- a/buession-core/src/main/java/com/buession/core/Customizer.java
+++ b/buession-core/src/main/java/com/buession/core/Customizer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
@@ -27,25 +27,21 @@
/**
* 定制器接口
*
- * @param
- * 源类型
* @param
- * 待定制对象类型
+ * 定制对象类型
*
* @author Yong.Teng
* @since 2.3.0
*/
@FunctionalInterface
-public interface Customizer {
+public interface Customizer {
/**
* 定制
*
- * @param source
- * 源实例
- * @param target
- * 待定制实例
+ * @param object
+ * 定制对象
*/
- void customize(S source, T target);
+ void customize(T object);
}
diff --git a/buession-core/src/main/java/com/buession/core/DoubleRange.java b/buession-core/src/main/java/com/buession/core/DoubleRange.java
new file mode 100644
index 000000000..79b6daae1
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/DoubleRange.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * {@code Double} 范围
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class DoubleRange extends NumberRange {
+
+ /**
+ * 构造函数
+ */
+ public DoubleRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public DoubleRange(Double start, Double end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/FloatRange.java b/buession-core/src/main/java/com/buession/core/FloatRange.java
new file mode 100644
index 000000000..2ad7d055c
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/FloatRange.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * {@code Float} 范围
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class FloatRange extends NumberRange {
+
+ /**
+ * 构造函数
+ */
+ public FloatRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public FloatRange(Float start, Float end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/IntegerRange.java b/buession-core/src/main/java/com/buession/core/IntegerRange.java
new file mode 100644
index 000000000..e881e75a9
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/IntegerRange.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * {@code Integer} 范围
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class IntegerRange extends NumberRange {
+
+ /**
+ * 构造函数
+ */
+ public IntegerRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public IntegerRange(Integer start, Integer end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/LongRange.java b/buession-core/src/main/java/com/buession/core/LongRange.java
new file mode 100644
index 000000000..cc32c5b97
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/LongRange.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * {@code Long} 范围
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class LongRange extends NumberRange {
+
+ /**
+ * 构造函数
+ */
+ public LongRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public LongRange(Long start, Long end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/NumberRange.java b/buession-core/src/main/java/com/buession/core/NumberRange.java
new file mode 100644
index 000000000..b9a3d8804
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/NumberRange.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * 数值范围
+ *
+ * @param
+ * 数值类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class NumberRange extends Range {
+
+ /**
+ * 构造函数
+ */
+ public NumberRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public NumberRange(T start, T end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/Pagination.java b/buession-core/src/main/java/com/buession/core/Pagination.java
index 08e1dd6f9..a544f8c51 100755
--- a/buession-core/src/main/java/com/buession/core/Pagination.java
+++ b/buession-core/src/main/java/com/buession/core/Pagination.java
@@ -21,11 +21,12 @@
* +------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
+import java.io.Serializable;
import java.util.List;
/**
@@ -36,7 +37,9 @@
*
* @author Yong.Teng
*/
-public class Pagination {
+public class Pagination implements Serializable {
+
+ private final static long serialVersionUID = 1135345190741903064L;
/**
* 默认每页大小
@@ -81,7 +84,7 @@ public class Pagination {
/**
* Constructs with default configuration.
*/
- public Pagination(){
+ public Pagination() {
}
/**
@@ -92,7 +95,7 @@ public Pagination(){
* @param pagesize
* 每页大小
*/
- public Pagination(int page, int pagesize){
+ public Pagination(int page, int pagesize) {
setPagesize(pagesize);
setPage(page);
}
@@ -107,7 +110,7 @@ public Pagination(int page, int pagesize){
* @param totalRecords
* 总记录数
*/
- public Pagination(int page, int pagesize, long totalRecords){
+ public Pagination(int page, int pagesize, long totalRecords) {
setPagesize(pagesize);
setTotalRecords(totalRecords);
setPage(page);
@@ -118,7 +121,7 @@ public Pagination(int page, int pagesize, long totalRecords){
*
* @return 当前页码
*/
- public int getPage(){
+ public int getPage() {
return page;
}
@@ -128,7 +131,7 @@ public int getPage(){
* @param page
* 当前页码
*/
- public void setPage(int page){
+ public void setPage(int page) {
this.page = page < 1 ? 1 : (totalPages > 1 && page > totalPages ? totalPages : page);
}
@@ -137,7 +140,7 @@ public void setPage(int page){
*
* @return 每页大小
*/
- public int getPagesize(){
+ public int getPagesize() {
return pagesize;
}
@@ -147,7 +150,7 @@ public int getPagesize(){
* @param pagesize
* 每页大小
*/
- public void setPagesize(int pagesize){
+ public void setPagesize(int pagesize) {
this.pagesize = pagesize < 1 ? PAGESIZE : pagesize;
}
@@ -156,7 +159,7 @@ public void setPagesize(int pagesize){
*
* @return 前一页页码
*/
- public int getPreviousPage(){
+ public int getPreviousPage() {
return previousPage;
}
@@ -166,7 +169,7 @@ public int getPreviousPage(){
* @param previousPage
* 前一页页码
*/
- public void setPreviousPage(int previousPage){
+ public void setPreviousPage(int previousPage) {
this.previousPage = (page <= 1 ? 1 : previousPage);
}
@@ -175,7 +178,7 @@ public void setPreviousPage(int previousPage){
*
* @return 下一页页码
*/
- public int getNextPage(){
+ public int getNextPage() {
return nextPage;
}
@@ -185,7 +188,7 @@ public int getNextPage(){
* @param nextPage
* 下一页页码
*/
- public void setNextPage(int nextPage){
+ public void setNextPage(int nextPage) {
this.nextPage = totalPages < page ? page : nextPage;
}
@@ -194,7 +197,7 @@ public void setNextPage(int nextPage){
*
* @return 总页码
*/
- public int getTotalPages(){
+ public int getTotalPages() {
return totalPages;
}
@@ -204,7 +207,7 @@ public int getTotalPages(){
* @param totalPages
* 总页码
*/
- public void setTotalPages(int totalPages){
+ public void setTotalPages(int totalPages) {
this.totalPages = Math.max(totalPages, 1);
}
@@ -213,7 +216,7 @@ public void setTotalPages(int totalPages){
*
* @return 总记录数
*/
- public long getTotalRecords(){
+ public long getTotalRecords() {
return totalRecords;
}
@@ -223,7 +226,7 @@ public long getTotalRecords(){
* @param totalRecords
* 总记录数
*/
- public void setTotalRecords(long totalRecords){
+ public void setTotalRecords(long totalRecords) {
this.totalRecords = totalRecords < 0 ? 0 : totalRecords;
setTotalPages((int) Math.ceil((double) this.totalRecords / pagesize));
@@ -236,7 +239,7 @@ public void setTotalRecords(long totalRecords){
*
* @return 结果数据
*/
- public List getData(){
+ public List getData() {
return data;
}
@@ -246,7 +249,7 @@ public List getData(){
* @param data
* 结果数据
*/
- public void setData(List data){
+ public void setData(List data) {
this.data = data;
}
diff --git a/buession-core/src/main/java/com/buession/core/Range.java b/buession-core/src/main/java/com/buession/core/Range.java
new file mode 100644
index 000000000..bb1317afc
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/Range.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * 范围
+ *
+ * @param
+ * 值类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class Range {
+
+ /**
+ * 起始值
+ */
+ private T start;
+
+ /**
+ * 截止值
+ */
+ private T end;
+
+ /**
+ * 构造函数
+ */
+ public Range() {
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public Range(final T start, final T end) {
+ this.start = start;
+ this.end = end;
+ }
+
+ /**
+ * 返回起始值
+ *
+ * @return 起始值
+ */
+ public T getStart() {
+ return start;
+ }
+
+ /**
+ * 设置起始值
+ *
+ * @param start
+ * 起始值
+ */
+ public void setStart(T start) {
+ this.start = start;
+ }
+
+ /**
+ * 返回截止值
+ *
+ * @return 截止值
+ */
+ public T getEnd() {
+ return end;
+ }
+
+ /**
+ * 设置截止值
+ *
+ * @param end
+ * 截止值
+ */
+ public void setEnd(T end) {
+ this.end = end;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + start + ", " + end + "]";
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/Rawable.java b/buession-core/src/main/java/com/buession/core/Rawable.java
index 14469abf4..79be0a308 100644
--- a/buession-core/src/main/java/com/buession/core/Rawable.java
+++ b/buession-core/src/main/java/com/buession/core/Rawable.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
@@ -30,6 +30,7 @@
* @author Yong.Teng
* @since 2.0.0
*/
+@FunctionalInterface
public interface Rawable {
/**
diff --git a/buession-core/src/main/java/com/buession/core/ShortRange.java b/buession-core/src/main/java/com/buession/core/ShortRange.java
new file mode 100644
index 000000000..3402ab0e4
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/ShortRange.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core;
+
+/**
+ * {@code Short} 范围
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class ShortRange extends NumberRange {
+
+ /**
+ * 构造函数
+ */
+ public ShortRange() {
+ super();
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param start
+ * 起始值
+ * @param end
+ * 截止值
+ */
+ public ShortRange(Short start, Short end) {
+ super(start, end);
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/collect/Arrays.java b/buession-core/src/main/java/com/buession/core/collect/Arrays.java
index 1771032db..5462ab08c 100644
--- a/buession-core/src/main/java/com/buession/core/collect/Arrays.java
+++ b/buession-core/src/main/java/com/buession/core/collect/Arrays.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.collect;
diff --git a/buession-core/src/main/java/com/buession/core/collect/Lists.java b/buession-core/src/main/java/com/buession/core/collect/Lists.java
index af019760c..2d44ce0e9 100644
--- a/buession-core/src/main/java/com/buession/core/collect/Lists.java
+++ b/buession-core/src/main/java/com/buession/core/collect/Lists.java
@@ -19,14 +19,16 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.collect;
import com.buession.core.utils.StringUtils;
+import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -50,7 +52,7 @@ public class Lists {
*
* @return 拼接后的字符串
*/
- public static String toString(final List data){
+ public static String toString(final List data) {
return StringUtils.join(data, DEFAULT_GLUE);
}
@@ -66,7 +68,7 @@ public static String toString(final List data){
*
* @return 拼接后的字符串
*/
- public static String toString(final List data, final String glue){
+ public static String toString(final List data, final String glue) {
return StringUtils.join(data, glue);
}
@@ -80,8 +82,14 @@ public static String toString(final List data, final String glue){
*
* @return 当 data 为 null 时,返回 null;否则,返回 O 类型的 {@link Set}
*/
- public static Set toSet(final List data){
- return data == null ? null : new LinkedHashSet<>(data);
+ public static Set toSet(final List data) {
+ if(data == null){
+ return null;
+ }else if(data instanceof LinkedList){
+ return new LinkedHashSet<>(data);
+ }else{
+ return new HashSet<>(data);
+ }
}
}
diff --git a/buession-core/src/main/java/com/buession/core/collect/Maps.java b/buession-core/src/main/java/com/buession/core/collect/Maps.java
index 692a20867..b0365436e 100644
--- a/buession-core/src/main/java/com/buession/core/collect/Maps.java
+++ b/buession-core/src/main/java/com/buession/core/collect/Maps.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.collect;
@@ -30,6 +30,7 @@
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -134,7 +135,13 @@ public static Map map(final Map map, final Func
* @return 当 map 为 null 时,返回 null;否则返回 V 类型的 {@link List}
*/
public static List toList(final Map map) {
- return map == null ? null : new ArrayList<>(map.values());
+ if(map == null){
+ return null;
+ }else if(map instanceof LinkedHashMap){
+ return new LinkedList<>(map.values());
+ }else{
+ return new ArrayList<>(map.values());
+ }
}
/**
diff --git a/buession-core/src/main/java/com/buession/core/collect/Sets.java b/buession-core/src/main/java/com/buession/core/collect/Sets.java
index 0352a895b..40157cdec 100644
--- a/buession-core/src/main/java/com/buession/core/collect/Sets.java
+++ b/buession-core/src/main/java/com/buession/core/collect/Sets.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.collect;
@@ -27,6 +27,8 @@
import com.buession.core.utils.StringUtils;
import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -50,7 +52,7 @@ public class Sets {
*
* @return 拼接后的字符串
*/
- public static String toString(final Set data){
+ public static String toString(final Set data) {
return StringUtils.join(data, DEFAULT_GLUE);
}
@@ -66,7 +68,7 @@ public static String toString(final Set data){
*
* @return 拼接后的字符串
*/
- public static String toString(final Set data, final String glue){
+ public static String toString(final Set data, final String glue) {
return StringUtils.join(data, glue);
}
@@ -80,8 +82,14 @@ public static String toString(final Set data, final String glue){
*
* @return 当 data 为 null 时,返回 null;否则,返回 O 类型的 {@link List}
*/
- public static List toList(final Set data){
- return data == null ? null : new ArrayList<>(data);
+ public static List toList(final Set data) {
+ if(data == null){
+ return null;
+ }else if(data instanceof LinkedHashSet){
+ return new LinkedList<>(data);
+ }else{
+ return new ArrayList<>(data);
+ }
}
}
diff --git a/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java b/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java
index 2e4f22e09..f0462b74b 100644
--- a/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java
+++ b/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java
@@ -31,6 +31,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
+import java.util.function.Supplier;
/**
* 默认线程池执行器
@@ -56,13 +57,12 @@ public DefaultThreadPoolExecutor() {
* 线程池配置
*/
public DefaultThreadPoolExecutor(final ThreadPoolConfiguration configuration) {
- super(initValue(configuration.getCorePoolSize(), Runtime.getRuntime().availableProcessors() << 1),
+ super(initValue(configuration.getCorePoolSize(), ()->Runtime.getRuntime().availableProcessors() << 1),
configuration.getMaximumPoolSize() > 0 ? configuration.getMaximumPoolSize() :
Runtime.getRuntime().availableProcessors() << 1,
- initValue(configuration.getKeepAliveTime(), DEFAULT_KEEP_ALIVE_TIME),
- configuration.getKeepAliveTimeUnit(),
- initValue(configuration.getWorkQueue(), new LinkedBlockingQueue<>()),
- initValue(configuration.getThreadFactory(), createDefaultThreadFactory(configuration)));
+ initValue(configuration.getKeepAliveTime(), ()->DEFAULT_KEEP_ALIVE_TIME),
+ configuration.getKeepAliveTimeUnit(), initValue(configuration.getWorkQueue(), LinkedBlockingQueue::new),
+ initValue(configuration.getThreadFactory(), ()->createDefaultThreadFactory(configuration)));
final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
@@ -70,16 +70,16 @@ public DefaultThreadPoolExecutor(final ThreadPoolConfiguration configuration) {
propertyMapper.from(configuration.getRejectedHandler()).to(this::setRejectedExecutionHandler);
}
- protected static int initValue(final int value, final int defaultValue) {
- return value >= 0 ? value : defaultValue;
+ protected static int initValue(final int value, final Supplier defaultValue) {
+ return value >= 0 ? value : defaultValue.get();
}
- protected static long initValue(final long value, final long defaultValue) {
- return value >= 0 ? value : defaultValue;
+ protected static long initValue(final long value, final Supplier defaultValue) {
+ return value >= 0 ? value : defaultValue.get();
}
- protected static T initValue(final T value, final T defaultValue) {
- return Optional.ofNullable(value).orElse(defaultValue);
+ protected static T initValue(final T value, final Supplier defaultValue) {
+ return Optional.ofNullable(value).orElse(defaultValue.get());
}
protected static ThreadFactory createDefaultThreadFactory(final ThreadPoolConfiguration configuration) {
diff --git a/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java b/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java
new file mode 100644
index 000000000..cfddcb56e
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import org.springframework.beans.BeanUtils;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * {@link Collection} 转换器
+ *
+ * @param
+ * 原类型
+ * @param
+ * 目标类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class CollectionConverter implements Converter, Collection> {
+
+ /**
+ * List item 转换器
+ */
+ private final Converter itemConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param itemConverter
+ * Collection item 转换器
+ */
+ public CollectionConverter(final Converter itemConverter) {
+ this.itemConverter = itemConverter;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public Collection convert(final Collection source) {
+ if(source == null){
+ return null;
+ }else{
+ Stream stream = source.stream().map(itemConverter::convert);
+
+ try{
+ return stream.collect(Collectors.toCollection(()->BeanUtils.instantiateClass(source.getClass())));
+ }catch(Exception e){
+ return stream.collect(Collectors.toList());
+ }
+ }
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java b/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java
new file mode 100644
index 000000000..a0b4d5ef7
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import org.springframework.lang.Nullable;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 值为 {@link Map.Entry} 的 {@link List} 到 {@link Map} 转换器
+ *
+ * @param
+ * Map 原 key 类型
+ * @param
+ * Map 原 value 类型
+ * @param
+ * Map 目标 key 类型
+ * @param
+ * Map 目标 value 类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class ListMapEntryMapConverter implements Converter>, Map> {
+
+ /**
+ * Map key 转换器
+ */
+ private final Converter keyConverter;
+
+ /**
+ * Map value 转换器
+ */
+ private final Converter valueConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param keyConverter
+ * Map key 转换器
+ * @param valueConverter
+ * Map value 转换器
+ */
+ public ListMapEntryMapConverter(final Converter keyConverter, final Converter valueConverter) {
+ this.keyConverter = keyConverter;
+ this.valueConverter = valueConverter;
+ }
+
+ @Nullable
+ @Override
+ public Map convert(final List> source) {
+ if(source == null){
+ return null;
+ }else{
+ final Map result = new LinkedHashMap<>(source.size());
+
+ for(Map.Entry e : source){
+ result.put(keyConverter.convert(e.getKey()), valueConverter.convert(e.getValue()));
+ }
+
+ return result;
+ }
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java b/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java
new file mode 100644
index 000000000..68e5dce52
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * List => Set 转换器
+ *
+ * @param
+ * 原类型
+ * @param
+ * 目标类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class ListSetConverter implements Converter, Set> {
+
+ /**
+ * List item 转换器
+ */
+ private final Converter itemConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param itemConverter
+ * List item 转换器
+ */
+ public ListSetConverter(final Converter itemConverter) {
+ this.itemConverter = itemConverter;
+ }
+
+ @Override
+ public Set convert(final List source) {
+ if(source == null){
+ return null;
+ }else{
+ return source.stream().map(itemConverter::convert)
+ .collect(Collectors.toCollection(source instanceof LinkedList ? LinkedHashSet::new : HashSet::new));
+ }
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java b/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java
new file mode 100644
index 000000000..c3b75e640
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import com.buession.lang.KeyValue;
+import org.springframework.lang.Nullable;
+
+import java.util.Map;
+
+/**
+ * {@link Map.Entry} 到 {@link KeyValue} 转换器
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class MapEntryKeyValueConverter implements Converter, KeyValue> {
+
+ /**
+ * Map key 转换器
+ */
+ private final Converter keyConverter;
+
+ /**
+ * Map value 转换器
+ */
+ private final Converter valueConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param keyConverter
+ * Map key 转换器
+ * @param valueConverter
+ * Map value 转换器
+ */
+ public MapEntryKeyValueConverter(final Converter keyConverter, final Converter valueConverter) {
+ this.keyConverter = keyConverter;
+ this.valueConverter = valueConverter;
+ }
+
+ @Nullable
+ @Override
+ public KeyValue convert(final Map.Entry source) {
+ return source == null ? null : new KeyValue<>(keyConverter.convert(source.getKey()),
+ valueConverter.convert(source.getValue()));
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java b/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java
new file mode 100644
index 000000000..03fa77c4e
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import com.buession.core.builder.MapBuilder;
+import org.springframework.lang.Nullable;
+
+import java.util.Map;
+
+/**
+ * {@link Map.Entry} 到 {@link Map} 转换器
+ *
+ * @param
+ * Map 原 key 类型
+ * @param
+ * Map 原 value 类型
+ * @param
+ * Map 目标 key 类型
+ * @param
+ * Map 目标 value 类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class MapEntryMapConverter implements Converter, Map> {
+
+ /**
+ * Map key 转换器
+ */
+ private final Converter keyConverter;
+
+ /**
+ * Map value 转换器
+ */
+ private final Converter valueConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param keyConverter
+ * Map key 转换器
+ * @param valueConverter
+ * Map value 转换器
+ */
+ public MapEntryMapConverter(final Converter keyConverter, final Converter valueConverter) {
+ this.keyConverter = keyConverter;
+ this.valueConverter = valueConverter;
+ }
+
+ @Nullable
+ @Override
+ public Map convert(final Map.Entry source) {
+ if(source == null){
+ return null;
+ }else{
+ return MapBuilder.of(keyConverter.convert(source.getKey()), valueConverter.convert(source.getValue()));
+ }
+ }
+
+}
diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java b/buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java
similarity index 70%
rename from buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java
rename to buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java
index 294812e3b..2b09264e6 100644
--- a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java
+++ b/buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java
@@ -19,34 +19,38 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
-package com.buession.httpclient.core;
+package com.buession.core.converter;
import com.buession.core.utils.Assert;
-import com.buession.httpclient.conn.ConnectionManager;
+import com.buession.lang.Status;
+
+import java.util.function.Predicate;
/**
- * Http Client Builder 抽象类
+ * 通过 {@link Predicate} 比较参数值转换为 {@link Boolean}
*
- * @param
- * 原生 Http Client Builder
- * @param
- * 连接管理器
- * @param
- * 原生 Http Client
+ * @param
+ * 谓词的输入类型
*
* @author Yong.Teng
- * @since 2.3.0
+ * @see Predicate
+ * @since 3.0.0
*/
-public abstract class AbstractHttpClientBuilder implements HttpClientBuilder {
+public class PredicateConverter implements Converter {
+
+ private final Predicate predicate;
- protected final CM connectionManager;
+ public PredicateConverter(final Predicate predicate) {
+ Assert.isNull(predicate, "Predicate cloud not be null.");
+ this.predicate = predicate;
+ }
- public AbstractHttpClientBuilder(final CM connectionManager){
- Assert.isNull(connectionManager, "Connection manager cloud not be null.");
- this.connectionManager = connectionManager;
+ @Override
+ public Boolean convert(final T source) {
+ return predicate.test(source);
}
}
diff --git a/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java b/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java
new file mode 100644
index 000000000..66b99607f
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.converter;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Set => List 转换器
+ *
+ * @param
+ * 原类型
+ * @param
+ * 目标类型
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class SetListConverter implements Converter, List> {
+
+ /**
+ * Set item 转换器
+ */
+ private final Converter itemConverter;
+
+ /**
+ * 构造函数
+ *
+ * @param itemConverter
+ * Set item 转换器
+ */
+ public SetListConverter(final Converter itemConverter) {
+ this.itemConverter = itemConverter;
+ }
+
+ @Override
+ public List convert(final Set source) {
+ if(source == null){
+ return null;
+ }else{
+ return source.stream().map(itemConverter::convert).collect(
+ Collectors.toCollection(source instanceof LinkedHashSet ? LinkedList::new : ArrayList::new));
+ }
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java b/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java
index 53707f49e..0fb14acb1 100644
--- a/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java
+++ b/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java
@@ -99,6 +99,18 @@ public PropertyMapper alwaysApplyingWhenNonText() {
return alwaysApplying(this::whenNonText);
}
+ /**
+ * Return a new {@link PropertyMapper} instance that applies
+ * {@link Source#whenPositiveNumber() whenHasText} to every source.
+ *
+ * @return a new property mapper instance
+ *
+ * @since 3.0.0
+ */
+ public PropertyMapper alwaysApplyingWhenPositiveNumber() {
+ return alwaysApplying(this::whenPositiveNumber);
+ }
+
/**
* Return a new {@link PropertyMapper} instance that applies the given
* {@link SourceOperator} to every source.
@@ -185,6 +197,10 @@ private Source whenNonText(Source source) {
return source.whenNonText();
}
+ private Source whenPositiveNumber(Source source) {
+ return source.whenPositiveNumber();
+ }
+
private Source whenTrue(Source source) {
return source.whenTrue();
}
@@ -422,6 +438,17 @@ public Source whenNonText() {
return when((value)->value == null || Validate.isBlank(Objects.toString(value, null)));
}
+ /**
+ * Return a filtered version of the source that will only map values that have a positive number.
+ *
+ * @return a new filtered source instance
+ *
+ * @since 3.0.0
+ */
+ public Source whenPositiveNumber() {
+ return when((value)->value instanceof Number && ((Number) value).doubleValue() > 0);
+ }
+
/**
* Return a filtered version of the source that will only map values equal to the specified {@code object}.
*
diff --git a/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java b/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java
new file mode 100644
index 000000000..8ceabc811
--- /dev/null
+++ b/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java
@@ -0,0 +1,549 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.core.datetime;
+
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.chrono.ChronoZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAccessor;
+import java.time.zone.ZoneRules;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 日期时间工具类
+ *
+ * @author Yong.Teng
+ * @since 3.0.0
+ */
+public class DateTimeUtils {
+
+ protected DateTimeUtils() {
+
+ }
+
+ /**
+ * 从字符串创建 {@link LocalDateTime} 实例
+ *
+ * @param value
+ * 日期字符串
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final String value) {
+ return localDateTimeOf(value, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从字符串创建 {@link LocalDateTime} 实例
+ *
+ * @param value
+ * 日期字符串
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final String value, final ZoneId zoneId) {
+ LocalDateTime result = null;
+
+ try{
+ result = LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
+ }catch(Exception e){
+ result = null;
+ }
+
+ if(result == null){
+ try{
+ result = LocalDateTime.parse(value, DateTimeFormatter.ISO_ZONED_DATE_TIME);
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ if(result == null){
+ try{
+ result = LocalDateTime.parse(value);
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ if(result == null){
+ try{
+ result = LocalDateTime.parse(value.toUpperCase(), DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a"));
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ if(result == null){
+ try{
+ result = LocalDateTime.parse(value.toUpperCase(), DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a"));
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ if(result == null){
+ try{
+ result = LocalDateTime.parse(value, DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm"));
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ LocalDate ld;
+ if(result == null){
+ try{
+ ld = LocalDate.parse(value, DateTimeFormatter.ofPattern("MM/dd/yyyy"));
+ result = LocalDateTime.of(ld, LocalTime.now(zoneId));
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ if(result == null){
+ try{
+ ld = LocalDate.parse(value);
+ result = LocalDateTime.of(ld, LocalTime.now(zoneId));
+ }catch(Exception e){
+ result = null;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * 从时间戳创建 {@link LocalDateTime} 实例
+ *
+ * @param timestamp
+ * 日期字符串
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final long timestamp) {
+ return localDateTimeOf(timestamp, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从时间戳创建 {@link LocalDateTime} 实例
+ *
+ * @param timestamp
+ * 日期字符串
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final long timestamp, final ZoneId zoneId) {
+ return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), zoneId);
+ }
+
+ /**
+ * 从{@link Date}创建 {@link LocalDateTime} 实例
+ *
+ * @param date
+ * {@link Date}
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final Date date) {
+ return localDateTimeOf(date.getTime());
+ }
+
+ /**
+ * 从{@link Date}创建 {@link LocalDateTime} 实例
+ *
+ * @param date
+ * {@link Date}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link LocalDateTime} 实例
+ */
+ public static LocalDateTime localDateTimeOf(final Date date, final ZoneId zoneId) {
+ return localDateTimeOf(date.getTime(), zoneId);
+ }
+
+ /**
+ * 从时间戳创建 {@link LocalDateTime} 实例
+ *
+ * @param timestamp
+ * 日期字符串
+ *
+ * @return {@link LocalDate} 实例
+ */
+ public static LocalDate localDateOf(final long timestamp) {
+ return localDateOf(timestamp, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从时间戳创建 {@link LocalDate} 实例
+ *
+ * @param timestamp
+ * 日期字符串
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link LocalDate} 实例
+ */
+ public static LocalDate localDateOf(final long timestamp, final ZoneId zoneId) {
+ Instant instant = Instant.ofEpochMilli(timestamp);
+ ZoneRules rules = zoneId.getRules();
+ ZoneOffset offset = rules.getOffset(instant);
+ long localSecond = instant.getEpochSecond() + offset.getTotalSeconds();
+ long localEpochDay = Math.floorDiv(localSecond, 86400);
+ return LocalDate.ofEpochDay(localEpochDay);
+ }
+
+ /**
+ * 从{@link Date}创建 {@link LocalDate} 实例
+ *
+ * @param date
+ * {@link Date}
+ *
+ * @return {@link LocalDate} 实例
+ */
+ public static LocalDate localDateOf(final Date date) {
+ return localDateOf(date.getTime());
+ }
+
+ /**
+ * 从{@link Date}创建 {@link LocalDate} 实例
+ *
+ * @param date
+ * {@link Date}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link LocalDate} 实例
+ */
+ public static LocalDate localDateOf(final Date date, final ZoneId zoneId) {
+ return localDateOf(date.getTime(), zoneId);
+ }
+
+ /**
+ * 从字符串创建 {@link ZonedDateTime} 实例
+ *
+ * @param value
+ * 日期时间字符串
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final String value) {
+ List parsers = Arrays.asList(DateTimeFormatter.ISO_ZONED_DATE_TIME,
+ DateTimeFormatter.RFC_1123_DATE_TIME);
+ return parsers.stream().map((parser)->{
+ try{
+ return ZonedDateTime.parse(value, parser);
+ }catch(Exception e){
+ return null;
+ }
+ }).filter(Objects::nonNull).findFirst().orElse(null);
+ }
+
+ /**
+ * 从 {@link TemporalAccessor} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param temporalAccessor
+ * {@link TemporalAccessor}
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final TemporalAccessor temporalAccessor) {
+ return ZonedDateTime.from(temporalAccessor);
+ }
+
+ /**
+ * 从 {@link Instant} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param instant
+ * {@link Instant}
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final Instant instant) {
+ return zonedDateTimeOf(instant, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从 {@link Instant} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param instant
+ * {@link Instant}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final Instant instant, final ZoneId zoneId) {
+ return instant != null ? instant.atZone(zoneId) : null;
+ }
+
+ /**
+ * 从时间戳创建 {@link ZonedDateTime} 实例
+ *
+ * @param timestamp
+ * 时间戳
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final long timestamp) {
+ return zonedDateTimeOf(timestamp, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从时间戳创建 {@link ZonedDateTime} 实例
+ *
+ * @param timestamp
+ * 时间戳
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final long timestamp, final ZoneId zoneId) {
+ return ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), zoneId);
+ }
+
+ /**
+ * 从 {@link Date} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param date
+ * {@link Date}
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final Date date) {
+ return zonedDateTimeOf(date, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从 {@link Date} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param date
+ * {@link Date}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final Date date, final ZoneId zoneId) {
+ return date != null ? zonedDateTimeOf(Instant.ofEpochMilli(date.getTime()), zoneId) : null;
+ }
+
+ /**
+ * 从 {@link Calendar} 创建 {@link ZonedDateTime} 实例
+ *
+ * @param calendar
+ * {@link Date}
+ *
+ * @return {@link ZonedDateTime} 实例
+ */
+ public static ZonedDateTime zonedDateTimeOf(final Calendar calendar) {
+ return ZonedDateTime.ofInstant(calendar.toInstant(), calendar.getTimeZone().toZoneId());
+ }
+
+ /**
+ * 从 {@link ChronoZonedDateTime} 创建 {@link Date} 实例
+ *
+ * @param chronoZonedDateTime
+ * {@link ChronoZonedDateTime}
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final ChronoZonedDateTime> chronoZonedDateTime) {
+ return dateOf(chronoZonedDateTime.toInstant());
+ }
+
+ /**
+ * 从 {@link LocalDate} 创建 {@link Date} 实例
+ *
+ * @param localDate
+ * {@link LocalDate}
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final LocalDate localDate) {
+ return dateOf(localDate, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从 {@link LocalDate} 创建 {@link Date} 实例
+ *
+ * @param localDate
+ * {@link LocalDate}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final LocalDate localDate, final ZoneId zoneId) {
+ return Date.from(localDate.atStartOfDay(zoneId).toInstant());
+ }
+
+ /**
+ * 从 {@link LocalDateTime} 创建 {@link Date} 实例
+ *
+ * @param localDateTime
+ * {@link LocalDate}
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final LocalDateTime localDateTime) {
+ return dateOf(localDateTime, ZoneId.systemDefault());
+ }
+
+ /**
+ * 从 {@link LocalDateTime} 创建 {@link Date} 实例
+ *
+ * @param localDateTime
+ * {@link LocalDate}
+ * @param zoneId
+ * 时区 ID
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final LocalDateTime localDateTime, final ZoneId zoneId) {
+ return dateOf(localDateTime.toInstant(zoneId.getRules().getOffset(localDateTime)));
+ }
+
+ /**
+ * 从 {@link Instant} 创建 {@link Date} 实例
+ *
+ * @param instant
+ * {@link Instant}
+ *
+ * @return {@link Date} 实例
+ */
+ public static Date dateOf(final Instant instant) {
+ return Date.from(instant);
+ }
+
+ /**
+ * 从 {@link ChronoZonedDateTime} 创建 {@link Timestamp} 实例
+ *
+ * @param chronoZonedDateTime
+ * {@link ChronoZonedDateTime}
+ *
+ * @return {@link Timestamp} 实例
+ */
+ public static Timestamp timestampOf(final ChronoZonedDateTime chronoZonedDateTime) {
+ return timestampOf(chronoZonedDateTime.toInstant());
+ }
+
+ /**
+ * 从 {@link Instant} 创建 {@link Timestamp} 实例
+ *
+ * @param instant
+ * {@link Instant}
+ *
+ * @return {@link Timestamp} 实例
+ */
+ public static Timestamp timestampOf(final Instant instant) {
+ return Timestamp.from(instant);
+ }
+
+ /**
+ * {@link ChronoUnit} 转换为 {@link TimeUnit}
+ *
+ * @param chronoUnit
+ * {@link ChronoUnit}
+ *
+ * @return {@link TimeUnit} 实例
+ */
+ public static TimeUnit toTimeUnit(final ChronoUnit chronoUnit) {
+ if(chronoUnit == null){
+ return null;
+ }else{
+ switch(chronoUnit){
+ case DAYS:
+ return TimeUnit.DAYS;
+ case HOURS:
+ return TimeUnit.HOURS;
+ case MINUTES:
+ return TimeUnit.MINUTES;
+ case SECONDS:
+ return TimeUnit.SECONDS;
+ case MICROS:
+ return TimeUnit.MICROSECONDS;
+ case MILLIS:
+ return TimeUnit.MILLISECONDS;
+ case NANOS:
+ return TimeUnit.NANOSECONDS;
+ default:
+ throw new UnsupportedOperationException("Temporal unit is not supported");
+ }
+ }
+ }
+
+ /**
+ * {@link TimeUnit} 转换为 {@link ChronoUnit}
+ *
+ * @param timeUnit
+ * {@link TimeUnit}
+ *
+ * @return {@link ChronoUnit} 实例
+ */
+ public static ChronoUnit toChronoUnit(final TimeUnit timeUnit) {
+ if(timeUnit == null){
+ return null;
+ }else{
+ switch(timeUnit){
+ case DAYS:
+ return ChronoUnit.DAYS;
+ case HOURS:
+ return ChronoUnit.HOURS;
+ case MINUTES:
+ return ChronoUnit.MINUTES;
+ case MICROSECONDS:
+ return ChronoUnit.MICROS;
+ case MILLISECONDS:
+ return ChronoUnit.MILLIS;
+ case NANOSECONDS:
+ return ChronoUnit.NANOS;
+ case SECONDS:
+ return ChronoUnit.SECONDS;
+ default:
+ return ChronoUnit.SECONDS;
+ }
+ }
+ }
+
+}
diff --git a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java
index ad4179821..7766e20b4 100644
--- a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java
+++ b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.deserializer;
@@ -29,11 +29,13 @@
/**
* JSON 反序列化抽象类
*
+ * @param
+ * JSON 反序列化原生类型
+ *
* @author Yong.Teng
* @since 2.3.0
*/
-@Deprecated
-public abstract class AbstractJsonDeserializer extends AbstractDeserializer implements JsonDeserializer {
+public abstract class AbstractJsonDeserializer extends AbstractDeserializer implements JsonDeserializer {
@Override
public V deserialize(final String str, final String charsetName) throws DeserializerException {
diff --git a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java
index 276029c35..1540ac2e3 100644
--- a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java
+++ b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.deserializer;
@@ -34,8 +34,7 @@
* @author Yong.Teng
* @since 2.3.0
*/
-@Deprecated
-public class FastJsonJsonDeserializer extends AbstractJsonDeserializer {
+public class FastJsonJsonDeserializer extends AbstractJsonDeserializer {
@Override
public V deserialize(final String str) throws DeserializerException {
diff --git a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java
index 0aa72980d..6ea83418e 100644
--- a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java
+++ b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.deserializer;
@@ -34,12 +34,16 @@
* @author Yong.Teng
* @since 2.3.0
*/
-@Deprecated
-public class GsonJsonDeserializer extends AbstractJsonDeserializer {
+public class GsonJsonDeserializer extends AbstractJsonDeserializer {
+
+ private final Gson gson = new Gson();
+
+ public GsonJsonDeserializer() {
+ configure(gson);
+ }
@Override
public V deserialize(final String str) throws DeserializerException {
- Gson gson = new Gson();
return gson.fromJson(str, new TypeReference() {
}.getType());
@@ -49,7 +53,6 @@ public V deserialize(final String str) throws DeserializerException {
public V deserialize(final String str, final Class clazz) throws DeserializerException {
Assert.isNull(str, "String cloud not be null.");
- Gson gson = new Gson();
return gson.fromJson(str, clazz);
}
@@ -57,7 +60,6 @@ public V deserialize(final String str, final Class clazz) throws Deserial
public V deserialize(String str, TypeReference type) throws DeserializerException {
Assert.isNull(str, "String cloud not be null.");
- Gson gson = new Gson();
return gson.fromJson(str, type.getType());
}
diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java
index 11a476b84..7f69940e1 100644
--- a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java
+++ b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.deserializer;
@@ -40,15 +40,26 @@
* @author Yong.Teng
* @since 2.3.0
*/
-@Deprecated
-public class JacksonJsonDeserializer extends AbstractJsonDeserializer {
+public class JacksonJsonDeserializer extends AbstractJsonDeserializer {
+
+ private final ObjectMapper objectMapper = new ObjectMapper();
+
+ public JacksonJsonDeserializer() {
+ configure(objectMapper);
+ }
+
+ @Override
+ public void configure(ObjectMapper object) {
+ objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
+ .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ }
@Override
public V deserialize(final String str) throws DeserializerException {
Assert.isNull(str, "String cloud not be null.");
try{
- return getObjectMapper().readValue(str, new com.fasterxml.jackson.core.type.TypeReference() {
+ return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() {
});
}catch(IOException e){
@@ -61,7 +72,7 @@ public V deserialize(final String str, final Class clazz) throws Deserial
Assert.isNull(str, "String cloud not be null.");
try{
- return getObjectMapper().readValue(str, clazz);
+ return objectMapper.readValue(str, clazz);
}catch(IOException e){
final String className = clazz == null ? "null" : clazz.getName();
throw new DeserializerException(str + " json deserialize to " + className + " failure.", e);
@@ -73,7 +84,7 @@ public V deserialize(final String str, final TypeReference type) throws D
Assert.isNull(str, "String cloud not be null.");
try{
- return getObjectMapper().readValue(str, new com.fasterxml.jackson.core.type.TypeReference() {
+ return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() {
@Override
public Type getType() {
@@ -92,7 +103,7 @@ public V deserialize(final byte[] bytes) throws DeserializerException {
Assert.isNull(bytes, "Bytes cloud not be null.");
try{
- return getObjectMapper().readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() {
+ return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() {
});
}catch(IOException e){
@@ -105,7 +116,7 @@ public V deserialize(final byte[] bytes, final Class clazz) throws Deseri
Assert.isNull(bytes, "Bytes cloud not be null.");
try{
- return getObjectMapper().readValue(bytes, clazz);
+ return objectMapper.readValue(bytes, clazz);
}catch(IOException e){
final String className = clazz == null ? "null" : clazz.getName();
throw new DeserializerException(Arrays.toString(bytes) + " json deserialize to " + className + " failure.",
@@ -118,7 +129,7 @@ public V deserialize(final byte[] bytes, final TypeReference type) throws
Assert.isNull(bytes, "Bytes cloud not be null.");
try{
- return getObjectMapper().readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() {
+ return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() {
@Override
public Type getType() {
@@ -133,13 +144,4 @@ public Type getType() {
}
}
- protected static ObjectMapper getObjectMapper() {
- ObjectMapper objectMapper = new ObjectMapper();
-
- objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
- .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-
- return objectMapper;
- }
-
}
diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java
index 688cae392..6ce1875a2 100644
--- a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java
+++ b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java
@@ -19,21 +19,52 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.deserializer;
+import com.buession.core.Customizer;
import com.buession.core.type.TypeReference;
/**
* JSON 反序列化
*
+ * @param
+ * JSON 序列化原生类型
+ *
* @author Yong.Teng
* @since 2.3.0
*/
-@Deprecated
-public interface JsonDeserializer extends Deserializer {
+public interface JsonDeserializer extends Deserializer {
+
+ /**
+ * 反序列化配置
+ *
+ * @param object
+ * JSON 原生对象
+ *
+ * @since 3.0.0
+ */
+ default void configure(T object) {
+
+ }
+
+ /**
+ * 反序列化配置
+ *
+ * @param object
+ * JSON 原生对象
+ * @param customizer
+ * 配置定制
+ *
+ * @since 3.0.0
+ */
+ default void configure(T object, Customizer customizer) {
+ if(customizer != null){
+ customizer.customize(object);
+ }
+ }
/**
* 字符串反序列化
diff --git a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java
index d49b6d807..3e89f6b0d 100644
--- a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java
+++ b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.serializer;
@@ -29,10 +29,12 @@
/**
* JSON 序列化抽象类
*
+ * @param
+ * JSON 序列化原生类型
+ *
* @author Yong.Teng
*/
-@Deprecated
-public abstract class AbstractJsonSerializer extends AbstractSerializer implements JsonSerializer {
+public abstract class AbstractJsonSerializer extends AbstractSerializer implements JsonSerializer {
@Override
public String serialize(final V object, final String charsetName) throws SerializerException {
@@ -54,28 +56,4 @@ public byte[] serializeAsBytes(final V object, final Charset charset) throws
return serializeAsBytes(object);
}
- @Deprecated
- @Override
- public V deserialize(final String str, final String charsetName) throws SerializerException {
- return deserialize(str);
- }
-
- @Deprecated
- @Override
- public V deserialize(final String str, final Charset charset) throws SerializerException {
- return deserialize(str);
- }
-
- @Deprecated
- @Override
- public V deserialize(final byte[] bytes, final String charsetName) throws SerializerException {
- return deserialize(bytes);
- }
-
- @Deprecated
- @Override
- public V deserialize(final byte[] bytes, final Charset charset) throws SerializerException {
- return deserialize(bytes);
- }
-
}
diff --git a/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java b/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java
index 9f47f156a..19ad9f4f6 100644
--- a/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java
+++ b/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java
@@ -19,13 +19,11 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2023 Buession.com Inc. |
+ * | Copyright @ 2013-2024 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.serializer;
-import com.buession.core.deserializer.DefaultByteArrayDeserializer;
-import com.buession.core.deserializer.DeserializerException;
import com.buession.core.utils.Assert;
import java.io.ByteArrayOutputStream;
@@ -46,7 +44,7 @@ public class DefaultByteArraySerializer extends AbstractByteArraySerializer {
private final static int BYTE_ARRAY_OUTPUT_STREAM_SIZE = 128;
@Override
- public String serialize(final V object, final String charsetName) throws SerializerException{
+ public