diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a958711e..5228e580f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,45 @@
===========================
+## [2.2.0](https://github.com/buession/buession-security/releases/tag/v2.2.0) (2023-03-10)
+
+### 🔨依赖升级
+
+- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v2.2.0)
+- **buession-geoip:** 升级 IP 库
+
+
+### ⭐ 新特性
+
+- **buession-core:** ListBuilder、MapBuilder、QueueBuilder、SetBuilder 增加可以直接传递 List、Map、Queue、Set 实例的 create 方法
+- **buession-core:** Assert isEmpty 和 notEmpty 增加基础类型数组判断
+- **buession-core:** StringUtils 增加 random 增加支持字符串
+- **buession-geoip:** 增加返回 autonomous system number、autonomous system organization
+- **buession-geoip:** 增加可支持设置 asn 库地址或流
+- **buession-httpclient:** 支持原生 RequestBody 子类转换
+- **buession-web:** 增加 web binder 转换器工厂 IgnoreCaseEnumConverterFactory 忽略大小写将字符串转换为枚举值
+- **buession-web:** 获取客户端真实 IP,增加标头 Client-IP 的支持
+
+
+### 🔔 变化
+- **buession-web:** 废弃 web binder 转换器 CaseTypeConverter、DomainTLDConverter、DomainTLDTypeConverter、GenderConverter、IpTypeConverter、ISBNTypeConverter、OrderConverter、StatusConverter,统一使用 web binder 转换器工厂 IgnoreCaseEnumConverterFactory
+- **buession-core:** Executor、Resolve 增加异常支持
+
+
+### 🐞 Bug 修复
+
+- **buession-core:** 修复 RandomDigitIdGenerator 最大值大于最小值时报错的问题
+- **buession-httpclient:** 修复 Response 返回错误的 statusCode 和 statusText
+- **buession-dao:** 修复 DefaultJsonTypeHandler 为 null 或空字符串反序列化出错的 BUG
+
+
+### ⏪ 优化
+- 其它优化
+
+
+---
+
+
## [2.1.2](https://github.com/buession/buessionframework/releases/tag/v2.1.2) (2022-11-13)
### 🔨依赖升级
@@ -18,6 +57,7 @@
- **buession-http:** 优化 Response,使 statusCode、statusText 与 statusLine 的值始终保持一致
- **buession-geoip:** 优化国家和地区词典解析,GeoIPResolverFactory 支持从默认词典返回文件对象或流对象,以及支持从 classpath 家长词典文件
- 其它优化
+- **buession-velocity:** 配置属性 resource.loader 替换 resource.loaders
### 🐞 Bug 修复
diff --git a/README.md b/README.md
index b22d74499..55858aa35 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,6 @@
- [https://mvnrepository.com/search?q=com.buession](https://mvnrepository.com/search?q=com.buession)
## Documentation
----
- 参考文档 [https://www.buession.com/](https://www.buession.com/)
- Wiki [https://github.com/buession/buessionframework/wiki](https://github.com/buession/buessionframework/wiki)
diff --git a/buession-aop/pom.xml b/buession-aop/pom.xml
index 01d633439..6bfc11f78 100644
--- a/buession-aop/pom.xml
+++ b/buession-aop/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.1.2
+ 2.2.0
buession-aop
https://github.com/buession/buessionframework
diff --git a/buession-beans/pom.xml b/buession-beans/pom.xml
index 29c78bcf0..5a2c60fe5 100644
--- a/buession-beans/pom.xml
+++ b/buession-beans/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.1.2
+ 2.2.0
buession-beans
https://github.com/buession/buessionframework
diff --git a/buession-beans/src/main/java/com/buession/beans/BeanUtils.java b/buession-beans/src/main/java/com/buession/beans/BeanUtils.java
index 861d115a9..469aa0d38 100644
--- a/buession-beans/src/main/java/com/buession/beans/BeanUtils.java
+++ b/buession-beans/src/main/java/com/buession/beans/BeanUtils.java
@@ -86,9 +86,7 @@ public static void populate(final Object target, final Object source, final Conv
try{
humpBeanUtilsBean.populate(target, (Map) source);
- }catch(IllegalAccessException e){
- logger.error("Copy Map to {} error: {}.", target.getClass().getName(), e.getMessage());
- }catch(InvocationTargetException e){
+ }catch(Exception e){
logger.error("Copy Map to {} error: {}.", target.getClass().getName(), e.getMessage());
}
return;
@@ -137,9 +135,7 @@ public static void copyProperties(final Object target, final Object source, fina
if(source instanceof Map){
try{
org.apache.commons.beanutils.BeanUtils.populate(target, (Map) source);
- }catch(IllegalAccessException e){
- logger.error("Copy Map to {} error: {}.", target.getClass().getName(), e.getMessage());
- }catch(InvocationTargetException e){
+ }catch(Exception e){
logger.error("Copy Map to {} error: {}.", target.getClass().getName(), e.getMessage());
}
return;
diff --git a/buession-core/pom.xml b/buession-core/pom.xml
index 5ed589729..16c6ab5de 100644
--- a/buession-core/pom.xml
+++ b/buession-core/pom.xml
@@ -7,7 +7,7 @@
com.buession
buession-parent
../buession-parent
- 2.1.2
+ 2.2.0
buession-core
https://github.com/buession/buessionframework
diff --git a/buession-core/src/main/java/com/buession/core/Executor.java b/buession-core/src/main/java/com/buession/core/Executor.java
index b92793ed3..06a05616e 100644
--- a/buession-core/src/main/java/com/buession/core/Executor.java
+++ b/buession-core/src/main/java/com/buession/core/Executor.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-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
@@ -44,7 +44,10 @@ public interface Executor {
* 命令执行器上下文
*
* @return 命令执行返回值,R 类型的实例
+ *
+ * @throws Exception
+ * 异常
*/
- R execute(C context);
+ R execute(C context) throws Exception;
}
diff --git a/buession-core/src/main/java/com/buession/core/Resolve.java b/buession-core/src/main/java/com/buession/core/Resolve.java
index e81ae5cc4..b67089c67 100644
--- a/buession-core/src/main/java/com/buession/core/Resolve.java
+++ b/buession-core/src/main/java/com/buession/core/Resolve.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-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core;
@@ -45,7 +45,10 @@ public interface Resolve {
* 待解析对象
*
* @return 解析结果
+ *
+ * @throws Exception
+ * 异常
*/
- T resolve(final S source);
+ T resolve(final S source) throws Exception;
}
diff --git a/buession-core/src/main/java/com/buession/core/builder/ListBuilder.java b/buession-core/src/main/java/com/buession/core/builder/ListBuilder.java
index 030616c22..e8645eebb 100644
--- a/buession-core/src/main/java/com/buession/core/builder/ListBuilder.java
+++ b/buession-core/src/main/java/com/buession/core/builder/ListBuilder.java
@@ -67,7 +67,7 @@ private ListBuilder(final List data){
* @return {@link ListBuilder} 实例
*/
public static ListBuilder create(){
- return create(16);
+ return new ListBuilder<>(new ArrayList<>());
}
/**
@@ -86,6 +86,22 @@ public static ListBuilder create(final int initialCapacity){
return new ListBuilder<>(new ArrayList<>(initialCapacity));
}
+ /**
+ * 创建默认为 {@link ArrayList} 类型的 {@link ListBuilder} 实例
+ *
+ * @param list
+ * the list whose elements are to be placed into this list
+ * @param
+ * Value 类型
+ *
+ * @return {@link ListBuilder} 实例
+ *
+ * @since 2.2.0
+ */
+ public static ListBuilder create(final List list){
+ return new ListBuilder<>(list);
+ }
+
/**
* 创建默认为 {@link ArrayList} 类型的 {@link ListBuilder} 实例
*
@@ -114,7 +130,7 @@ public static ListBuilder create(final Collection extends V> c){
*
* @return {@link ListBuilder} 实例
*/
- public static > ListBuilder create(Class clazz){
+ public static > ListBuilder create(final Class clazz){
Assert.isNull(clazz, "java.util.List class cloud not be null.");
List data;
diff --git a/buession-core/src/main/java/com/buession/core/builder/MapBuilder.java b/buession-core/src/main/java/com/buession/core/builder/MapBuilder.java
index 1c254a88b..c4ff2d191 100644
--- a/buession-core/src/main/java/com/buession/core/builder/MapBuilder.java
+++ b/buession-core/src/main/java/com/buession/core/builder/MapBuilder.java
@@ -46,7 +46,7 @@ private MapBuilder(final Map data){
* @return {@link MapBuilder} 实例
*/
public static MapBuilder create(){
- return create(16);
+ return new MapBuilder<>(new HashMap<>());
}
/**
@@ -101,8 +101,8 @@ public static MapBuilder create(final int initialCapacity, final fl
*
* @since 2.1.2
*/
- public static MapBuilder create(final Map extends K, ? extends V> m){
- return new MapBuilder<>(new HashMap<>(m));
+ public static MapBuilder create(final Map m){
+ return new MapBuilder<>(m);
}
/**
@@ -119,7 +119,7 @@ public static MapBuilder create(final Map extends K, ? extends V>
*
* @return {@link MapBuilder} 实例
*/
- public static > MapBuilder create(Class clazz){
+ public static > MapBuilder create(final Class clazz){
Assert.isNull(clazz, "java.util.Map class cloud not be null.");
Map data;
diff --git a/buession-core/src/main/java/com/buession/core/builder/QueueBuilder.java b/buession-core/src/main/java/com/buession/core/builder/QueueBuilder.java
index 2bfbb959d..59a4440c9 100644
--- a/buession-core/src/main/java/com/buession/core/builder/QueueBuilder.java
+++ b/buession-core/src/main/java/com/buession/core/builder/QueueBuilder.java
@@ -46,11 +46,27 @@ public static QueueBuilder create(){
return new QueueBuilder<>(new LinkedList<>());
}
+ /**
+ * 创建默认为 {@link LinkedList} 类型的 {@link QueueBuilder} 实例
+ *
+ * @param queue
+ * the queue whose elements are to be placed into this queue
+ * @param
+ * Value 类型
+ *
+ * @return {@link QueueBuilder} 实例
+ *
+ * @since 2.2.0
+ */
+ public static QueueBuilder create(final Queue queue){
+ return new QueueBuilder<>(queue);
+ }
+
/**
* 创建默认为 {@link LinkedList} 类型的 {@link QueueBuilder} 实例
*
* @param c
- * the collection whose elements are to be placed into this list
+ * the collection whose elements are to be placed into this queue
* @param
* Value 类型
*
@@ -74,7 +90,7 @@ public static QueueBuilder create(final Collection extends V> c){
*
* @return {@link QueueBuilder} 实例
*/
- public static > QueueBuilder create(Class clazz){
+ public static > QueueBuilder create(final Class clazz){
Assert.isNull(clazz, "java.util.Queue class cloud not be null.");
Queue data;
diff --git a/buession-core/src/main/java/com/buession/core/builder/SetBuilder.java b/buession-core/src/main/java/com/buession/core/builder/SetBuilder.java
index c9827fda2..f9ccea0e5 100644
--- a/buession-core/src/main/java/com/buession/core/builder/SetBuilder.java
+++ b/buession-core/src/main/java/com/buession/core/builder/SetBuilder.java
@@ -43,7 +43,7 @@ private SetBuilder(final Set data){
* @return {@link SetBuilder} 实例
*/
public static SetBuilder create(){
- return new SetBuilder<>(new HashSet<>(16));
+ return new SetBuilder<>(new HashSet<>());
}
/**
@@ -80,6 +80,22 @@ public static SetBuilder create(final int initialCapacity, final float lo
return new SetBuilder<>(new HashSet<>(initialCapacity, loadFactor));
}
+ /**
+ * 创建默认为 {@link HashSet} 类型的 {@link SetBuilder} 实例
+ *
+ * @param set
+ * the set whose elements are to be placed into this set
+ * @param
+ * Value 类型
+ *
+ * @return {@link SetBuilder} 实例
+ *
+ * @since 2.2.0
+ */
+ public static SetBuilder create(final Set set){
+ return new SetBuilder<>(set);
+ }
+
/**
* 创建默认为 {@link HashSet} 类型的 {@link SetBuilder} 实例
*
@@ -108,7 +124,7 @@ public static SetBuilder create(final Collection extends V> c){
*
* @return {@link SetBuilder} 实例
*/
- public static > SetBuilder create(Class clazz){
+ public static > SetBuilder create(final Class clazz){
Assert.isNull(clazz, "java.util.Set class cloud not be null.");
Set data;
diff --git a/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java b/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java
index 41953d2d6..9dc2a3daf 100644
--- a/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java
+++ b/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java
@@ -79,7 +79,9 @@ public Object postProcessAfterInitialization(Object bean, @Nullable String beanN
}
if(field.getType().isAssignableFrom(MessageObject.class) == false){
- throw new BeanCreationException("The field " + field.getName() + " is not subclass of " + MessageObject.class.getName() + ", on: " + beanName + "(" + bean.getClass().getName() + ").");
+ throw new BeanCreationException(
+ "The field " + field.getName() + " is not subclass of " + MessageObject.class.getName() +
+ ", on: " + beanName + "(" + bean.getClass().getName() + ").");
}
handleMessageInjected(clazz, bean, beanName, field, message);
@@ -88,22 +90,29 @@ public Object postProcessAfterInitialization(Object bean, @Nullable String beanN
return bean;
}
- private void handleMessageInjected(final Class> clazz, final Object bean, final String beanName, final Field field, final Message message) throws BeansException{
+ private void handleMessageInjected(final Class> clazz, final Object bean, final String beanName,
+ final Field field, final Message message) throws BeansException{
final String key = message.value();
final String text = getEnvironment().getProperty(buildProperty(key, message.textField()));
if(message.required() && text == null){
- throw new IllegalArgumentException("Could not resolve placeholder '" + key + "' in value \"${" + key + "}\", on: " + beanName + "(" + bean.getClass().getName() + ").");
+ throw new IllegalArgumentException(
+ "Could not resolve placeholder '" + key + "' in value \"${" + key + "}\", on: " + beanName + "(" +
+ bean.getClass().getName() + ").");
}
- final int code = getEnvironment().getProperty(buildProperty(key, message.codeField()), Integer.class);
+ final Integer code = getEnvironment().getProperty(buildProperty(key, message.codeField()), Integer.class);
- try{
- final Object beanObject = AopUtils.isCglibProxy(bean) ? getCglibProxyTargetObject(bean) : bean;
+ if(code != null){
+ try{
+ final Object beanObject = AopUtils.isCglibProxy(bean) ? getCglibProxyTargetObject(bean) : bean;
- FieldUtils.writeField(field, beanObject, new MessageObject(code, text), true);
- }catch(Exception e){
- throw new BeanCreationException("Exception thrown when handleMessageInjected, on: " + beanName + "(" + clazz.getName() + ")", e);
+ FieldUtils.writeField(field, beanObject, new MessageObject(code, text), true);
+ }catch(Exception e){
+ throw new BeanCreationException(
+ "Exception thrown when handleMessageInjected, on: " + beanName + "(" + clazz.getName() + ")",
+ e);
+ }
}
logger.debug("Parse message '{}', code: {}, text: {}", key, code, text);
}
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 cd0a0ff46..279dcb06f 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
@@ -247,12 +247,7 @@ public Source as(Function adapter){
Supplier test = ()->predicate.test(supplier.get());
Predicate predicate = (t)->test.get();
- Supplier supplier = ()->{
- if(test.get()){
- return adapter.apply(this.supplier.get());
- }
- return null;
- };
+ Supplier supplier = ()->test.get() ? adapter.apply(this.supplier.get()) : null;
return new Source<>(supplier, predicate);
}
@@ -381,11 +376,11 @@ public R toInstance(Function factory){
Assert.isNull(factory, "Factory cloud not be null");
T value = supplier.get();
- if(predicate.test(value) == false){
- throw new NoSuchElementException("No value present");
+ if(predicate.test(value)){
+ return factory.apply(value);
}
- return factory.apply(value);
+ throw new NoSuchElementException("No value present");
}
}
diff --git a/buession-core/src/main/java/com/buession/core/id/RandomDigitIdGenerator.java b/buession-core/src/main/java/com/buession/core/id/RandomDigitIdGenerator.java
index 89d802656..9abd7f235 100644
--- a/buession-core/src/main/java/com/buession/core/id/RandomDigitIdGenerator.java
+++ b/buession-core/src/main/java/com/buession/core/id/RandomDigitIdGenerator.java
@@ -36,39 +36,41 @@
*/
public class RandomDigitIdGenerator implements IdGenerator {
- /**
- * 最小值
- */
- private long min = 1L;
+ /**
+ * 最小值
+ */
+ private long min = 1L;
- /**
- * 最大值
- */
- private long max = Long.MAX_VALUE;
+ /**
+ * 最大值
+ */
+ private long max = Long.MAX_VALUE;
- /**
- * 构造函数,生成 1 到 Long.MAX_VALUE 间的随机 ID
- */
- public RandomDigitIdGenerator() {
- }
+ /**
+ * 构造函数,生成 1 到 Long.MAX_VALUE 间的随机 ID
+ */
+ public RandomDigitIdGenerator(){
+ }
- /**
- * 构造函数
- *
- * @param min 最小值
- * @param max 最大值
- */
- public RandomDigitIdGenerator(final long min, final long max) {
- Assert.isFalse(min >= 1 && min <= Long.MAX_VALUE, "Id min value must between 1 and " + Long.MAX_VALUE + ".");
- Assert.isFalse(max >= 1 && max <= Long.MAX_VALUE, "Id max value must between 1 and " + Long.MAX_VALUE + ".");
- Assert.isFalse(min > max, "Id max value has to be greater than or equal to id min value.");
- this.min = min;
- this.max = max;
- }
+ /**
+ * 构造函数
+ *
+ * @param min
+ * 最小值
+ * @param max
+ * 最大值
+ */
+ public RandomDigitIdGenerator(final long min, final long max){
+ Assert.isFalse(min >= 1 && min <= Long.MAX_VALUE, "Id min value must between 1 and " + Long.MAX_VALUE + ".");
+ Assert.isFalse(max >= 1 && max <= Long.MAX_VALUE, "Id max value must between 1 and " + Long.MAX_VALUE + ".");
+ Assert.isTrue(min > max, "Id max value has to be greater than or equal to id min value.");
+ this.min = min;
+ this.max = max;
+ }
- @Override
- public Long nextId() {
- return RandomUtils.nextLong(min, max);
- }
+ @Override
+ public Long nextId(){
+ return RandomUtils.nextLong(min, max);
+ }
}
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 dcdd1966e..4f8df623d 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,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.serializer;
@@ -147,7 +147,7 @@ protected static String baosWrite(final V value) throws IOException{
}
@SuppressWarnings("unchecked")
- protected final static V doDeserialize(final byte[] bytes, final String sourceType) throws SerializerException{
+ protected static V doDeserialize(final byte[] bytes, final String sourceType) throws SerializerException{
ByteArrayInputStream byteArrayInputStream = null;
ObjectInputStream objectInputStream = null;
diff --git a/buession-core/src/main/java/com/buession/core/utils/Assert.java b/buession-core/src/main/java/com/buession/core/utils/Assert.java
index 08c1512d7..912ced6d2 100644
--- a/buession-core/src/main/java/com/buession/core/utils/Assert.java
+++ b/buession-core/src/main/java/com/buession/core/utils/Assert.java
@@ -98,6 +98,134 @@ public static void notNull(final Object object, final String message){
}
}
+ /**
+ * 如果 shor 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final short[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 int 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final int[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 long 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final long[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 float 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final float[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 double 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final double[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 boolean 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final boolean[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 byte 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final byte[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 char 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ *
+ * @since 2.2.0
+ */
+ public static void isEmpty(final char[] objects, final String message){
+ if(Validate.isEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
/**
* 如果数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
*
@@ -168,6 +296,118 @@ public static void isEmpty(final Enumeration> enumeration, final String messag
}
}
+ /**
+ * 如果 short 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final short[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 int 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final int[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 long 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final long[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 float 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final float[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 double 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final double[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 boolean 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final boolean[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 byte 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final byte[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
+ /**
+ * 如果 char 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
+ *
+ * @param objects
+ * 数组对象
+ * @param message
+ * 异常信息
+ */
+ public static void notEmpty(final char[] objects, final String message){
+ if(Validate.isNotEmpty(objects)){
+ throw new IllegalArgumentException(message);
+ }
+ }
+
/**
* 如果数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常
*
diff --git a/buession-core/src/main/java/com/buession/core/utils/StringUtils.java b/buession-core/src/main/java/com/buession/core/utils/StringUtils.java
index 275205730..14c20f71c 100755
--- a/buession-core/src/main/java/com/buession/core/utils/StringUtils.java
+++ b/buession-core/src/main/java/com/buession/core/utils/StringUtils.java
@@ -114,7 +114,24 @@ public static boolean isFalse(final String str){
* @return 生成的随机字符串
*/
public static String random(final int length){
+ return random(length, Constants.ALNUM);
+ }
+
+ /**
+ * 生成随机字符串
+ *
+ * @param length
+ * 随机字符串长度
+ * @param chars
+ * 原字符
+ *
+ * @return 生成的随机字符串
+ *
+ * @since 2.2.0
+ */
+ public static String random(final int length, final char[] chars){
Assert.isNegative(length, "Length could not be negative.");
+ Assert.isEmpty(chars, "chars could not be negative.");
if(length == 0){
return EMPTY;
@@ -122,8 +139,8 @@ public static String random(final int length){
StringBuilder sb = new StringBuilder(length);
for(int i = 0; i < length; i++){
- int j = RandomUtils.nextInt(Constants.ALNUM.length);
- sb.append(Constants.ALNUM[j]);
+ int j = RandomUtils.nextInt(chars.length);
+ sb.append(chars[j]);
}
return sb.toString();
@@ -497,7 +514,8 @@ public static boolean regionMatches(final CharSequence cs, final boolean ignoreC
}
// The same check as in String.regionMatches():
- if(Character.toUpperCase(c1) != Character.toUpperCase(c2) && Character.toLowerCase(c1) != Character.toLowerCase(c2)){
+ if(Character.toUpperCase(c1) != Character.toUpperCase(c2) &&
+ Character.toLowerCase(c1) != Character.toLowerCase(c2)){
return false;
}
}
diff --git a/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/AlnumConstraintValidator.java b/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/AlnumConstraintValidator.java
index 3fc5e195c..9a5075ea1 100644
--- a/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/AlnumConstraintValidator.java
+++ b/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/AlnumConstraintValidator.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-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.validator.constraintvalidators;
@@ -35,10 +35,6 @@
*/
public abstract class AlnumConstraintValidator implements ConstraintValidator {
- @Override
- public void initialize(Alnum alnum){
- }
-
public final static class CharSequenceAlnumConstraintValidator extends AlnumConstraintValidator {
@Override
diff --git a/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/EmptyConstraintValidator.java b/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/EmptyConstraintValidator.java
index 696dcf983..5a71ed5cc 100644
--- a/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/EmptyConstraintValidator.java
+++ b/buession-core/src/main/java/com/buession/core/validator/constraintvalidators/EmptyConstraintValidator.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2020 Buession.com Inc. |
+ * | Copyright @ 2013-2022 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.core.validator.constraintvalidators;
@@ -57,37 +57,37 @@ public boolean isValid(Object[] value, ConstraintValidatorContext context){
}
- public final static class MapEmptyConstraintValidator extends EmptyConstraintValidator