mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
c4627a339d
commit
b30bf90210
@ -115,7 +115,7 @@ public class PercentCodec implements Encoder<byte[], byte[]>, Serializable {
|
|||||||
*/
|
*/
|
||||||
public String encode(final CharSequence path, final Charset charset, final char... customSafeChar) {
|
public String encode(final CharSequence path, final Charset charset, final char... customSafeChar) {
|
||||||
if (null == charset || StrUtil.isEmpty(path)) {
|
if (null == charset || StrUtil.isEmpty(path)) {
|
||||||
return StrUtil.str(path);
|
return StrUtil.toStringOrNull(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder rewrittenPath = new StringBuilder(path.length() * 3);
|
final StringBuilder rewrittenPath = new StringBuilder(path.length() * 3);
|
||||||
|
@ -15,6 +15,7 @@ package org.dromara.hutool.core.collection.iter;
|
|||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import org.dromara.hutool.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.collection.ListUtil;
|
import org.dromara.hutool.core.collection.ListUtil;
|
||||||
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.math.NumberUtil;
|
import org.dromara.hutool.core.math.NumberUtil;
|
||||||
@ -906,7 +907,7 @@ public class IterUtil {
|
|||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
*/
|
*/
|
||||||
public static <E> String toStr(final Iterator<E> iterator) {
|
public static <E> String toStr(final Iterator<E> iterator) {
|
||||||
return toStr(iterator, ObjUtil::toString);
|
return toStr(iterator, Convert::toStrOrNullStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,7 +206,7 @@ public class ZipWriter implements Closeable {
|
|||||||
* @throws IORuntimeException IO异常
|
* @throws IORuntimeException IO异常
|
||||||
*/
|
*/
|
||||||
public ZipWriter add(String path, final InputStream in) throws IORuntimeException {
|
public ZipWriter add(String path, final InputStream in) throws IORuntimeException {
|
||||||
path = StrUtil.emptyIfNull(path);
|
path = StrUtil.toStringOrEmpty(path);
|
||||||
if (null == in) {
|
if (null == in) {
|
||||||
// 空目录需要检查路径规范性,目录以"/"结尾
|
// 空目录需要检查路径规范性,目录以"/"结尾
|
||||||
path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
|
path = StrUtil.addSuffixIfNot(path, StrUtil.SLASH);
|
||||||
|
@ -57,7 +57,7 @@ public class Convert {
|
|||||||
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -77,6 +77,18 @@ public class Convert {
|
|||||||
return toStr(value, null);
|
return toStr(value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为字符串<br>
|
||||||
|
* 如果给定的值为{@code null},或者转换失败,返回默认值"null"(即null这个字符串)<br>
|
||||||
|
* 转换失败不会报错
|
||||||
|
*
|
||||||
|
* @param value 被转换的值
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static String toStrOrNullStr(final Object value) {
|
||||||
|
return toStr(value, StrUtil.NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为String数组
|
* 转换为String数组
|
||||||
*
|
*
|
||||||
@ -93,7 +105,7 @@ public class Convert {
|
|||||||
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -129,7 +141,7 @@ public class Convert {
|
|||||||
* 如果给定的值为{@code null},或者转换失败,返回默认值<br>
|
* 如果给定的值为{@code null},或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -176,7 +188,7 @@ public class Convert {
|
|||||||
* 如果给定的值为{@code null},或者转换失败,返回默认值<br>
|
* 如果给定的值为{@code null},或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -212,7 +224,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -248,7 +260,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -283,7 +295,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -318,7 +330,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -353,7 +365,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -388,7 +400,7 @@ public class Convert {
|
|||||||
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
|
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -423,7 +435,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -448,7 +460,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@ -473,7 +485,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @since 4.1.6
|
* @since 4.1.6
|
||||||
@ -487,7 +499,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @since 5.0.7
|
* @since 5.0.7
|
||||||
@ -513,7 +525,7 @@ public class Convert {
|
|||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
* 转换失败不会报错
|
* 转换失败不会报错
|
||||||
*
|
*
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @param defaultValue 转换错误时的默认值
|
* @param defaultValue 转换错误时的默认值
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @since 5.0.7
|
* @since 5.0.7
|
||||||
@ -539,17 +551,17 @@ public class Convert {
|
|||||||
* 转换为Enum对象<br>
|
* 转换为Enum对象<br>
|
||||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||||
*
|
*
|
||||||
* @param <E> 枚举类型
|
* @param <E> 枚举类型
|
||||||
* @param clazz Enum的Class
|
* @param clazz Enum的Class
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return Enum
|
* @return Enum
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <E extends Enum<E>> E toEnum(final Class<E> clazz, final Object value, final E defaultValue) {
|
public static <E extends Enum<E>> E toEnum(final Class<E> clazz, final Object value, final E defaultValue) {
|
||||||
try{
|
try {
|
||||||
return (E) EnumConverter.INSTANCE.convert(clazz, value);
|
return (E) EnumConverter.INSTANCE.convert(clazz, value);
|
||||||
} catch (final Exception ignore){
|
} catch (final Exception ignore) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,7 +570,7 @@ public class Convert {
|
|||||||
* 转换为Enum对象<br>
|
* 转换为Enum对象<br>
|
||||||
* 如果给定的值为空,或者转换失败,返回默认值{@code null}<br>
|
* 如果给定的值为空,或者转换失败,返回默认值{@code null}<br>
|
||||||
*
|
*
|
||||||
* @param <E> 枚举类型
|
* @param <E> 枚举类型
|
||||||
* @param clazz Enum的Class
|
* @param clazz Enum的Class
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return Enum
|
* @return Enum
|
||||||
@ -571,8 +583,8 @@ public class Convert {
|
|||||||
* 转换为集合类
|
* 转换为集合类
|
||||||
*
|
*
|
||||||
* @param collectionType 集合类型
|
* @param collectionType 集合类型
|
||||||
* @param elementType 集合中元素类型
|
* @param elementType 集合中元素类型
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @return {@link Collection}
|
* @return {@link Collection}
|
||||||
* @since 3.0.8
|
* @since 3.0.8
|
||||||
*/
|
*/
|
||||||
@ -594,9 +606,9 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 转换为ArrayList
|
* 转换为ArrayList
|
||||||
*
|
*
|
||||||
* @param <T> 元素类型
|
* @param <T> 元素类型
|
||||||
* @param elementType 集合中元素类型
|
* @param elementType 集合中元素类型
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @return {@link ArrayList}
|
* @return {@link ArrayList}
|
||||||
* @since 4.1.20
|
* @since 4.1.20
|
||||||
*/
|
*/
|
||||||
@ -608,9 +620,9 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 转换为HashSet
|
* 转换为HashSet
|
||||||
*
|
*
|
||||||
* @param <T> 元素类型
|
* @param <T> 元素类型
|
||||||
* @param elementType 集合中元素类型
|
* @param elementType 集合中元素类型
|
||||||
* @param value 被转换的值
|
* @param value 被转换的值
|
||||||
* @return {@link HashSet}
|
* @return {@link HashSet}
|
||||||
* @since 5.7.3
|
* @since 5.7.3
|
||||||
*/
|
*/
|
||||||
@ -657,78 +669,78 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 转换值为指定类型,类型采用字符串表示
|
* 转换值为指定类型,类型采用字符串表示
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param className 类的字符串表示
|
* @param className 类的字符串表示
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 4.0.7
|
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
|
* @since 4.0.7
|
||||||
*/
|
*/
|
||||||
public static <T> T convertByClassName(final String className, final Object value) throws ConvertException{
|
public static <T> T convertByClassName(final String className, final Object value) throws ConvertException {
|
||||||
return convert(ClassLoaderUtil.loadClass(className), value);
|
return convert(ClassLoaderUtil.loadClass(className), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换值为指定类型
|
* 转换值为指定类型
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 4.0.0
|
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public static <T> T convert(final Class<T> type, final Object value) throws ConvertException{
|
public static <T> T convert(final Class<T> type, final Object value) throws ConvertException {
|
||||||
return convert((Type)type, value);
|
return convert((Type) type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换值为指定类型
|
* 转换值为指定类型
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param reference 类型参考,用于持有转换后的泛型类型
|
* @param reference 类型参考,用于持有转换后的泛型类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
*/
|
*/
|
||||||
public static <T> T convert(final TypeReference<T> reference, final Object value) throws ConvertException{
|
public static <T> T convert(final TypeReference<T> reference, final Object value) throws ConvertException {
|
||||||
return convert(reference.getType(), value, null);
|
return convert(reference.getType(), value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换值为指定类型
|
* 转换值为指定类型
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
*/
|
*/
|
||||||
public static <T> T convert(final Type type, final Object value) throws ConvertException{
|
public static <T> T convert(final Type type, final Object value) throws ConvertException {
|
||||||
return convert(type, value, null);
|
return convert(type, value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换值为指定类型
|
* 转换值为指定类型
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public static <T> T convert(final Class<T> type, final Object value, final T defaultValue) throws ConvertException {
|
public static <T> T convert(final Class<T> type, final Object value, final T defaultValue) throws ConvertException {
|
||||||
return convert((Type)type, value, defaultValue);
|
return convert((Type) type, value, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换值为指定类型
|
* 转换值为指定类型
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 类型
|
* @param type 类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @throws ConvertException 转换器不存在
|
* @throws ConvertException 转换器不存在
|
||||||
@ -741,8 +753,8 @@ public class Convert {
|
|||||||
* 转换值为指定类型,不抛异常转换<br>
|
* 转换值为指定类型,不抛异常转换<br>
|
||||||
* 当转换失败时返回{@code null}
|
* 当转换失败时返回{@code null}
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 目标类型
|
* @param type 目标类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 转换后的值,转换失败返回null
|
* @return 转换后的值,转换失败返回null
|
||||||
* @since 4.5.10
|
* @since 4.5.10
|
||||||
@ -755,9 +767,9 @@ public class Convert {
|
|||||||
* 转换值为指定类型,不抛异常转换<br>
|
* 转换值为指定类型,不抛异常转换<br>
|
||||||
* 当转换失败时返回默认值
|
* 当转换失败时返回默认值
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 目标类型
|
* @param type 目标类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 4.5.10
|
* @since 4.5.10
|
||||||
@ -770,11 +782,11 @@ public class Convert {
|
|||||||
* 转换值为指定类型,可选是否不抛异常转换<br>
|
* 转换值为指定类型,可选是否不抛异常转换<br>
|
||||||
* 当转换失败时返回默认值
|
* 当转换失败时返回默认值
|
||||||
*
|
*
|
||||||
* @param <T> 目标类型
|
* @param <T> 目标类型
|
||||||
* @param type 目标类型
|
* @param type 目标类型
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @param quietly 是否静默转换,true不抛异常
|
* @param quietly 是否静默转换,true不抛异常
|
||||||
* @return 转换后的值
|
* @return 转换后的值
|
||||||
* @since 5.3.2
|
* @since 5.3.2
|
||||||
*/
|
*/
|
||||||
@ -783,7 +795,7 @@ public class Convert {
|
|||||||
try {
|
try {
|
||||||
return compositeConverter.convert(type, value, defaultValue);
|
return compositeConverter.convert(type, value, defaultValue);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
if(quietly){
|
if (quietly) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
@ -791,6 +803,7 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- 全角半角转换
|
// ----------------------------------------------------------------------- 全角半角转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 半角转全角
|
* 半角转全角
|
||||||
*
|
*
|
||||||
@ -804,12 +817,12 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 半角转全角,{@code null}返回{@code null}
|
* 半角转全角,{@code null}返回{@code null}
|
||||||
*
|
*
|
||||||
* @param input String
|
* @param input String
|
||||||
* @param notConvertSet 不替换的字符集合
|
* @param notConvertSet 不替换的字符集合
|
||||||
* @return 全角字符串,{@code null}返回{@code null}
|
* @return 全角字符串,{@code null}返回{@code null}
|
||||||
*/
|
*/
|
||||||
public static String toSBC(final String input, final Set<Character> notConvertSet) {
|
public static String toSBC(final String input, final Set<Character> notConvertSet) {
|
||||||
if(StrUtil.isEmpty(input)){
|
if (StrUtil.isEmpty(input)) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
final char[] c = input.toCharArray();
|
final char[] c = input.toCharArray();
|
||||||
@ -841,13 +854,13 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 替换全角为半角
|
* 替换全角为半角
|
||||||
*
|
*
|
||||||
* @param text 文本
|
* @param text 文本
|
||||||
* @param notConvertSet 不替换的字符集合
|
* @param notConvertSet 不替换的字符集合
|
||||||
* @return 替换后的字符
|
* @return 替换后的字符
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||||
public static String toDBC(final String text, final Set<Character> notConvertSet) {
|
public static String toDBC(final String text, final Set<Character> notConvertSet) {
|
||||||
if(StrUtil.isBlank(text)) {
|
if (StrUtil.isBlank(text)) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
final char[] c = text.toCharArray();
|
final char[] c = text.toCharArray();
|
||||||
@ -869,10 +882,11 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------- hex
|
// --------------------------------------------------------------------- hex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串转换成十六进制字符串,结果为小写
|
* 字符串转换成十六进制字符串,结果为小写
|
||||||
*
|
*
|
||||||
* @param str 待转换的ASCII字符串
|
* @param str 待转换的ASCII字符串
|
||||||
* @param charset 编码
|
* @param charset 编码
|
||||||
* @return 16进制字符串
|
* @return 16进制字符串
|
||||||
* @see HexUtil#encodeStr(String, Charset)
|
* @see HexUtil#encodeStr(String, Charset)
|
||||||
@ -906,7 +920,7 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 十六进制转换字符串
|
* 十六进制转换字符串
|
||||||
*
|
*
|
||||||
* @param hexStr Byte字符串(Byte之间无分隔符 如:[616C6B])
|
* @param hexStr Byte字符串(Byte之间无分隔符 如:[616C6B])
|
||||||
* @param charset 编码 {@link Charset}
|
* @param charset 编码 {@link Charset}
|
||||||
* @return 对应的字符串
|
* @return 对应的字符串
|
||||||
* @see HexUtil#decodeStr(String, Charset)
|
* @see HexUtil#decodeStr(String, Charset)
|
||||||
@ -942,9 +956,9 @@ public class Convert {
|
|||||||
* 给定字符串转换字符编码<br>
|
* 给定字符串转换字符编码<br>
|
||||||
* 如果参数为空,则返回原字符串,不报错。
|
* 如果参数为空,则返回原字符串,不报错。
|
||||||
*
|
*
|
||||||
* @param str 被转码的字符串
|
* @param str 被转码的字符串
|
||||||
* @param sourceCharset 原字符集
|
* @param sourceCharset 原字符集
|
||||||
* @param destCharset 目标字符集
|
* @param destCharset 目标字符集
|
||||||
* @return 转换后的字符串
|
* @return 转换后的字符串
|
||||||
* @see CharsetUtil#convert(String, String, String)
|
* @see CharsetUtil#convert(String, String, String)
|
||||||
*/
|
*/
|
||||||
@ -960,8 +974,8 @@ public class Convert {
|
|||||||
* 转换时间单位
|
* 转换时间单位
|
||||||
*
|
*
|
||||||
* @param sourceDuration 时长
|
* @param sourceDuration 时长
|
||||||
* @param sourceUnit 源单位
|
* @param sourceUnit 源单位
|
||||||
* @param destUnit 目标单位
|
* @param destUnit 目标单位
|
||||||
* @return 目标单位的时长
|
* @return 目标单位的时长
|
||||||
*/
|
*/
|
||||||
public static long convertTime(final long sourceDuration, final TimeUnit sourceUnit, final TimeUnit destUnit) {
|
public static long convertTime(final long sourceDuration, final TimeUnit sourceUnit, final TimeUnit destUnit) {
|
||||||
@ -971,13 +985,14 @@ public class Convert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------- 原始包装类型转换
|
// --------------------------------------------------------------- 原始包装类型转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原始类转为包装类,非原始类返回原类
|
* 原始类转为包装类,非原始类返回原类
|
||||||
*
|
*
|
||||||
* @see BasicType#wrap(Class)
|
|
||||||
* @param clazz 原始类
|
* @param clazz 原始类
|
||||||
* @return 包装类
|
* @return 包装类
|
||||||
* @see BasicType#wrap(Class)
|
* @see BasicType#wrap(Class)
|
||||||
|
* @see BasicType#wrap(Class)
|
||||||
*/
|
*/
|
||||||
public static Class<?> wrap(final Class<?> clazz) {
|
public static Class<?> wrap(final Class<?> clazz) {
|
||||||
return BasicType.wrap(clazz);
|
return BasicType.wrap(clazz);
|
||||||
@ -986,16 +1001,17 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 包装类转为原始类,非包装类返回原类
|
* 包装类转为原始类,非包装类返回原类
|
||||||
*
|
*
|
||||||
* @see BasicType#unWrap(Class)
|
|
||||||
* @param clazz 包装类
|
* @param clazz 包装类
|
||||||
* @return 原始类
|
* @return 原始类
|
||||||
* @see BasicType#unWrap(Class)
|
* @see BasicType#unWrap(Class)
|
||||||
|
* @see BasicType#unWrap(Class)
|
||||||
*/
|
*/
|
||||||
public static Class<?> unWrap(final Class<?> clazz) {
|
public static Class<?> unWrap(final Class<?> clazz) {
|
||||||
return BasicType.unWrap(clazz);
|
return BasicType.unWrap(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- 数字和英文转换
|
// -------------------------------------------------------------------------- 数字和英文转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将阿拉伯数字转为英文表达方式
|
* 将阿拉伯数字转为英文表达方式
|
||||||
*
|
*
|
||||||
@ -1025,7 +1041,7 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 将阿拉伯数字转为中文表达方式
|
* 将阿拉伯数字转为中文表达方式
|
||||||
*
|
*
|
||||||
* @param number 数字
|
* @param number 数字
|
||||||
* @param isUseTraditional 是否使用繁体字(金额形式)
|
* @param isUseTraditional 是否使用繁体字(金额形式)
|
||||||
* @return 中文
|
* @return 中文
|
||||||
* @since 3.2.3
|
* @since 3.2.3
|
||||||
@ -1047,7 +1063,7 @@ public class Convert {
|
|||||||
* @return 数字
|
* @return 数字
|
||||||
* @since 5.6.0
|
* @since 5.6.0
|
||||||
*/
|
*/
|
||||||
public static BigDecimal chineseToNumber(final String number){
|
public static BigDecimal chineseToNumber(final String number) {
|
||||||
return ChineseNumberParser.parseFromChineseNumber(number);
|
return ChineseNumberParser.parseFromChineseNumber(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,7 +1075,7 @@ public class Convert {
|
|||||||
* @since 3.2.3
|
* @since 3.2.3
|
||||||
*/
|
*/
|
||||||
public static String digitToChinese(final Number n) {
|
public static String digitToChinese(final Number n) {
|
||||||
if(null == n) {
|
if (null == n) {
|
||||||
return "零";
|
return "零";
|
||||||
}
|
}
|
||||||
return ChineseNumberFormatter.of()
|
return ChineseNumberFormatter.of()
|
||||||
@ -1071,18 +1087,19 @@ public class Convert {
|
|||||||
/**
|
/**
|
||||||
* 中文大写数字金额转换为数字,返回结果以元为单位的BigDecimal类型数字
|
* 中文大写数字金额转换为数字,返回结果以元为单位的BigDecimal类型数字
|
||||||
* 如:
|
* 如:
|
||||||
* “陆万柒仟伍佰伍拾陆元叁角贰分”返回“67556.32”
|
* “陆万柒仟伍佰伍拾陆元叁角贰分”返回“67556.32”
|
||||||
* “叁角贰分”返回“0.32”
|
* “叁角贰分”返回“0.32”
|
||||||
*
|
*
|
||||||
* @param chineseMoneyAmount 中文大写数字金额
|
* @param chineseMoneyAmount 中文大写数字金额
|
||||||
* @return 返回结果以元为单位的BigDecimal类型数字
|
* @return 返回结果以元为单位的BigDecimal类型数字
|
||||||
* @since 5.8.5
|
* @since 5.8.5
|
||||||
*/
|
*/
|
||||||
public static BigDecimal chineseMoneyToNumber(final String chineseMoneyAmount){
|
public static BigDecimal chineseMoneyToNumber(final String chineseMoneyAmount) {
|
||||||
return ChineseNumberParser.parseFromChineseMoney(chineseMoneyAmount);
|
return ChineseNumberParser.parseFromChineseMoney(chineseMoneyAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- 数字转换
|
// -------------------------------------------------------------------------- 数字转换
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* int转byte
|
* int转byte
|
||||||
*
|
*
|
||||||
|
@ -228,7 +228,7 @@ public class BetweenFormatter implements Serializable {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public BetweenFormatter setSeparator(final String separator) {
|
public BetweenFormatter setSeparator(final String separator) {
|
||||||
this.separator = StrUtil.emptyIfNull(separator);
|
this.separator = StrUtil.toStringOrEmpty(separator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,11 +799,13 @@ public class CalendarUtil {
|
|||||||
* @since 5.7.14
|
* @since 5.7.14
|
||||||
*/
|
*/
|
||||||
public static Calendar parse(final CharSequence str, final boolean lenient, final PositionDateParser parser) {
|
public static Calendar parse(final CharSequence str, final boolean lenient, final PositionDateParser parser) {
|
||||||
|
Assert.notBlank(str, "Date str must be not blank!");
|
||||||
|
Assert.notNull(parser, "Parser must be not null!");
|
||||||
final Calendar calendar = Calendar.getInstance(parser.getTimeZone(), parser.getLocale());
|
final Calendar calendar = Calendar.getInstance(parser.getTimeZone(), parser.getLocale());
|
||||||
calendar.clear();
|
calendar.clear();
|
||||||
calendar.setLenient(lenient);
|
calendar.setLenient(lenient);
|
||||||
|
|
||||||
return parser.parse(StrUtil.str(str), new ParsePosition(0), calendar) ? calendar : null;
|
return parser.parse(str.toString(), new ParsePosition(0), calendar) ? calendar : null;
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class CharSequenceResource implements Resource, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return StrUtil.str(this.name);
|
return StrUtil.toString(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -225,7 +225,7 @@ public class ResourceUtil {
|
|||||||
* @return {@link URL}
|
* @return {@link URL}
|
||||||
*/
|
*/
|
||||||
public static URL getResourceUrl(String resource, final Class<?> baseClass) {
|
public static URL getResourceUrl(String resource, final Class<?> baseClass) {
|
||||||
resource = StrUtil.emptyIfNull(resource);
|
resource = StrUtil.toStringOrEmpty(resource);
|
||||||
return (null != baseClass) ? baseClass.getResource(resource) : ClassLoaderUtil.getClassLoader().getResource(resource);
|
return (null != baseClass) ? baseClass.getResource(resource) : ClassLoaderUtil.getClassLoader().getResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +893,7 @@ public class Validator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new java.net.URL(StrUtil.str(value));
|
new java.net.URL(value.toString());
|
||||||
} catch (final MalformedURLException e) {
|
} catch (final MalformedURLException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class UrlPath {
|
public class UrlPath {
|
||||||
|
|
||||||
private List<String> segments;
|
private List<CharSequence> segments;
|
||||||
private boolean withEngTag;
|
private boolean withEngTag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +72,7 @@ public class UrlPath {
|
|||||||
*
|
*
|
||||||
* @return 节点列表
|
* @return 节点列表
|
||||||
*/
|
*/
|
||||||
public List<String> getSegments() {
|
public List<CharSequence> getSegments() {
|
||||||
return ObjUtil.defaultIfNull(this.segments, ListUtil.empty());
|
return ObjUtil.defaultIfNull(this.segments, ListUtil.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ public class UrlPath {
|
|||||||
* @param index 节点位置
|
* @param index 节点位置
|
||||||
* @return 节点,无节点或者越界返回null
|
* @return 节点,无节点或者越界返回null
|
||||||
*/
|
*/
|
||||||
public String getSegment(final int index) {
|
public CharSequence getSegment(final int index) {
|
||||||
if (null == this.segments || index >= this.segments.size()) {
|
if (null == this.segments || index >= this.segments.size()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ public class UrlPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
for (final String segment : segments) {
|
for (final CharSequence segment : segments) {
|
||||||
// https://www.ietf.org/rfc/rfc3986.html#section-3.3
|
// https://www.ietf.org/rfc/rfc3986.html#section-3.3
|
||||||
// 此处Path中是允许有`:`的,之前理解有误,应该是相对URI的第一个segment中不允许有`:`
|
// 此处Path中是允许有`:`的,之前理解有误,应该是相对URI的第一个segment中不允许有`:`
|
||||||
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT.encode(segment, charset));
|
builder.append(CharUtil.SLASH).append(RFC3986.SEGMENT.encode(segment, charset));
|
||||||
@ -189,11 +189,10 @@ public class UrlPath {
|
|||||||
this.segments = new LinkedList<>();
|
this.segments = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String seg = StrUtil.str(segment);
|
|
||||||
if (before) {
|
if (before) {
|
||||||
this.segments.add(0, seg);
|
this.segments.add(0, segment);
|
||||||
} else {
|
} else {
|
||||||
this.segments.add(seg);
|
this.segments.add(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ public class UrlQuery {
|
|||||||
final boolean isFormUrlEncoded = EncodeMode.FORM_URL_ENCODED == this.encodeMode;
|
final boolean isFormUrlEncoded = EncodeMode.FORM_URL_ENCODED == this.encodeMode;
|
||||||
if (null != key) {
|
if (null != key) {
|
||||||
final String actualKey = UrlDecoder.decode(key, charset, isFormUrlEncoded);
|
final String actualKey = UrlDecoder.decode(key, charset, isFormUrlEncoded);
|
||||||
this.query.put(actualKey, StrUtil.emptyIfNull(UrlDecoder.decode(value, charset, isFormUrlEncoded)));
|
this.query.put(actualKey, StrUtil.toStringOrEmpty(UrlDecoder.decode(value, charset, isFormUrlEncoded)));
|
||||||
} else if (null != value) {
|
} else if (null != value) {
|
||||||
// name为空,value作为name,value赋值null
|
// name为空,value作为name,value赋值null
|
||||||
this.query.put(UrlDecoder.decode(value, charset, isFormUrlEncoded), null);
|
this.query.put(UrlDecoder.decode(value, charset, isFormUrlEncoded), null);
|
||||||
|
@ -213,9 +213,11 @@ public class UrlQueryUtil {
|
|||||||
|
|
||||||
final Map<String, List<String>> params = new LinkedHashMap<>();
|
final Map<String, List<String>> params = new LinkedHashMap<>();
|
||||||
queryMap.forEach((key, value) -> {
|
queryMap.forEach((key, value) -> {
|
||||||
final List<String> values = params.computeIfAbsent(StrUtil.str(key), k -> new ArrayList<>(1));
|
if(null != key && null != value){
|
||||||
// 一般是一个参数
|
final List<String> values = params.computeIfAbsent(key.toString(), k -> new ArrayList<>(1));
|
||||||
values.add(StrUtil.str(value));
|
// 一般是一个参数
|
||||||
|
values.add(key.toString());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
@ -531,7 +531,7 @@ public class UrlUtil {
|
|||||||
if (isEncodePath) {
|
if (isEncodePath) {
|
||||||
path = RFC3986.PATH.encode(path, CharsetUtil.UTF_8);
|
path = RFC3986.PATH.encode(path, CharsetUtil.UTF_8);
|
||||||
}
|
}
|
||||||
return protocol + domain + StrUtil.emptyIfNull(path) + StrUtil.emptyIfNull(params);
|
return protocol + domain + StrUtil.toStringOrEmpty(path) + StrUtil.toStringOrEmpty(params);
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ public class ClassScanner implements Serializable {
|
|||||||
* @param charset 编码
|
* @param charset 编码
|
||||||
*/
|
*/
|
||||||
public ClassScanner(String packageName, final Predicate<Class<?>> classPredicate, final Charset charset) {
|
public ClassScanner(String packageName, final Predicate<Class<?>> classPredicate, final Charset charset) {
|
||||||
packageName = StrUtil.emptyIfNull(packageName);
|
packageName = StrUtil.toStringOrEmpty(packageName);
|
||||||
this.packageName = packageName;
|
this.packageName = packageName;
|
||||||
this.packageNameWithDot = StrUtil.addSuffixIfNot(packageName, StrUtil.DOT);
|
this.packageNameWithDot = StrUtil.addSuffixIfNot(packageName, StrUtil.DOT);
|
||||||
this.packageDirName = packageName.replace(CharUtil.DOT, File.separatorChar);
|
this.packageDirName = packageName.replace(CharUtil.DOT, File.separatorChar);
|
||||||
|
@ -381,8 +381,8 @@ public class ReUtil {
|
|||||||
* @return 删除后剩余的内容
|
* @return 删除后剩余的内容
|
||||||
*/
|
*/
|
||||||
public static String delFirst(final String regex, final CharSequence content) {
|
public static String delFirst(final String regex, final CharSequence content) {
|
||||||
if (ArrayUtil.hasBlank(regex, content)) {
|
if (StrUtil.hasEmpty(regex, content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
||||||
@ -411,7 +411,7 @@ public class ReUtil {
|
|||||||
*/
|
*/
|
||||||
public static String replaceFirst(final Pattern pattern, final CharSequence content, final String replacement) {
|
public static String replaceFirst(final Pattern pattern, final CharSequence content, final String replacement) {
|
||||||
if (null == pattern || StrUtil.isEmpty(content)) {
|
if (null == pattern || StrUtil.isEmpty(content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pattern.matcher(content).replaceFirst(replacement);
|
return pattern.matcher(content).replaceFirst(replacement);
|
||||||
@ -426,8 +426,8 @@ public class ReUtil {
|
|||||||
* @since 5.6.5
|
* @since 5.6.5
|
||||||
*/
|
*/
|
||||||
public static String delLast(final String regex, final CharSequence str) {
|
public static String delLast(final String regex, final CharSequence str) {
|
||||||
if (ArrayUtil.hasBlank(regex, str)) {
|
if (StrUtil.isEmpty(regex) || StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
||||||
@ -450,7 +450,7 @@ public class ReUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -462,7 +462,7 @@ public class ReUtil {
|
|||||||
*/
|
*/
|
||||||
public static String delAll(final String regex, final CharSequence content) {
|
public static String delAll(final String regex, final CharSequence content) {
|
||||||
if (StrUtil.hasEmpty(regex, content)) {
|
if (StrUtil.hasEmpty(regex, content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
||||||
@ -478,7 +478,7 @@ public class ReUtil {
|
|||||||
*/
|
*/
|
||||||
public static String delAll(final Pattern pattern, final CharSequence content) {
|
public static String delAll(final Pattern pattern, final CharSequence content) {
|
||||||
if (null == pattern || StrUtil.isEmpty(content)) {
|
if (null == pattern || StrUtil.isEmpty(content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pattern.matcher(content).replaceAll(StrUtil.EMPTY);
|
return pattern.matcher(content).replaceAll(StrUtil.EMPTY);
|
||||||
@ -493,7 +493,7 @@ public class ReUtil {
|
|||||||
*/
|
*/
|
||||||
public static String delPre(final String regex, final CharSequence content) {
|
public static String delPre(final String regex, final CharSequence content) {
|
||||||
if (null == content || null == regex) {
|
if (null == content || null == regex) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
final Pattern pattern = PatternPool.get(regex, Pattern.DOTALL);
|
||||||
@ -508,15 +508,14 @@ public class ReUtil {
|
|||||||
* @return 删除前缀后的新内容
|
* @return 删除前缀后的新内容
|
||||||
*/
|
*/
|
||||||
public static String delPre(final Pattern pattern, final CharSequence content) {
|
public static String delPre(final Pattern pattern, final CharSequence content) {
|
||||||
if (null == content || null == pattern) {
|
if (null != pattern && StrUtil.isNotEmpty(content)) {
|
||||||
return StrUtil.str(content);
|
final Matcher matcher = pattern.matcher(content);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return StrUtil.sub(content, matcher.end(), content.length());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Matcher matcher = pattern.matcher(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
if (matcher.find()) {
|
|
||||||
return StrUtil.sub(content, matcher.end(), content.length());
|
|
||||||
}
|
|
||||||
return StrUtil.str(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -873,32 +872,28 @@ public class ReUtil {
|
|||||||
* @since 3.0.4
|
* @since 3.0.4
|
||||||
*/
|
*/
|
||||||
public static String replaceAll(final CharSequence content, final Pattern pattern, final String replacementTemplate) {
|
public static String replaceAll(final CharSequence content, final Pattern pattern, final String replacementTemplate) {
|
||||||
if (StrUtil.isEmpty(content)) {
|
if(null != pattern && StrUtil.isNotEmpty(content) && StrUtil.isNotEmpty(replacementTemplate)){
|
||||||
return StrUtil.str(content);
|
final Matcher matcher = pattern.matcher(content);
|
||||||
|
boolean result = matcher.find();
|
||||||
|
if (result) {
|
||||||
|
final Set<String> varNums = findAll(PatternPool.GROUP_VAR, replacementTemplate, 1,
|
||||||
|
new TreeSet<>(StrLengthComparator.INSTANCE.reversed()));
|
||||||
|
final StringBuffer sb = new StringBuffer();
|
||||||
|
do {
|
||||||
|
String replacement = replacementTemplate;
|
||||||
|
for (final String var : varNums) {
|
||||||
|
final int group = Integer.parseInt(var);
|
||||||
|
replacement = replacement.replace("$" + var, matcher.group(group));
|
||||||
|
}
|
||||||
|
matcher.appendReplacement(sb, escape(replacement));
|
||||||
|
result = matcher.find();
|
||||||
|
} while (result);
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replacementTemplate字段不能为null,否则无法抉择如何处理结果
|
return StrUtil.toStringOrNull(replacementTemplate);
|
||||||
Assert.notNull(replacementTemplate, "ReplacementTemplate must be not null !");
|
|
||||||
|
|
||||||
final Matcher matcher = pattern.matcher(content);
|
|
||||||
boolean result = matcher.find();
|
|
||||||
if (result) {
|
|
||||||
final Set<String> varNums = findAll(PatternPool.GROUP_VAR, replacementTemplate, 1,
|
|
||||||
new TreeSet<>(StrLengthComparator.INSTANCE.reversed()));
|
|
||||||
final StringBuffer sb = new StringBuffer();
|
|
||||||
do {
|
|
||||||
String replacement = replacementTemplate;
|
|
||||||
for (final String var : varNums) {
|
|
||||||
final int group = Integer.parseInt(var);
|
|
||||||
replacement = replacement.replace("$" + var, matcher.group(group));
|
|
||||||
}
|
|
||||||
matcher.appendReplacement(sb, escape(replacement));
|
|
||||||
result = matcher.find();
|
|
||||||
} while (result);
|
|
||||||
matcher.appendTail(sb);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
return StrUtil.str(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -933,9 +928,13 @@ public class ReUtil {
|
|||||||
* @return 替换后的字符串
|
* @return 替换后的字符串
|
||||||
* @since 4.2.2
|
* @since 4.2.2
|
||||||
*/
|
*/
|
||||||
public static String replaceAll(final CharSequence str, final Pattern pattern, final SerFunction<Matcher, String> replaceFun) {
|
public static String replaceAll(final CharSequence str, final Pattern pattern, SerFunction<Matcher, String> replaceFun) {
|
||||||
if (StrUtil.isEmpty(str)) {
|
if (null == pattern || StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(null == replaceFun){
|
||||||
|
replaceFun = Matcher::group;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Matcher matcher = pattern.matcher(str);
|
final Matcher matcher = pattern.matcher(str);
|
||||||
@ -970,7 +969,7 @@ public class ReUtil {
|
|||||||
*/
|
*/
|
||||||
public static String escape(final CharSequence content) {
|
public static String escape(final CharSequence content) {
|
||||||
if (StrUtil.isBlank(content)) {
|
if (StrUtil.isBlank(content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
@ -30,7 +30,6 @@ import org.dromara.hutool.core.text.replacer.SearchReplacer;
|
|||||||
import org.dromara.hutool.core.text.split.SplitUtil;
|
import org.dromara.hutool.core.text.split.SplitUtil;
|
||||||
import org.dromara.hutool.core.util.ByteUtil;
|
import org.dromara.hutool.core.util.ByteUtil;
|
||||||
import org.dromara.hutool.core.util.CharsetUtil;
|
import org.dromara.hutool.core.util.CharsetUtil;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
@ -94,28 +93,46 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static final String SPACE = " ";
|
public static final String SPACE = " ";
|
||||||
|
|
||||||
|
// region toString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CharSequence} 转为字符串,null安全
|
* 调用对象的toString方法,null会返回“null”
|
||||||
*
|
*
|
||||||
* @param cs {@link CharSequence}
|
* @param obj 对象
|
||||||
* @return 字符串
|
* @return 字符串
|
||||||
|
* @since 4.1.3
|
||||||
|
* @see String#valueOf(Object)
|
||||||
*/
|
*/
|
||||||
public static String str(final CharSequence cs) {
|
public static String toString(final Object obj) {
|
||||||
return null == cs ? null : cs.toString();
|
return String.valueOf(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用对象的toString方法,{@code null}会返回{@code null}
|
||||||
|
*
|
||||||
|
* @param obj 对象
|
||||||
|
* @return 字符串 or {@code null}
|
||||||
|
* @since 5.7.17
|
||||||
|
*/
|
||||||
|
public static String toStringOrNull(final Object obj) {
|
||||||
|
return null == obj ? null : obj.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用对象的toString方法,{@code null}会返回空字符串 ""
|
||||||
|
*
|
||||||
|
* @param obj 对象
|
||||||
|
* @return {@link String }
|
||||||
|
* @author Junwei Xu
|
||||||
|
*/
|
||||||
|
public static String toStringOrEmpty(final Object obj) {
|
||||||
|
// obj为空时, 返回 null 或 "null" 都不适用部分场景, 此处返回 "" 空字符串
|
||||||
|
return null == obj ? EMPTY : obj.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
// region ----- defaultIf
|
// region ----- defaultIf
|
||||||
|
|
||||||
/**
|
|
||||||
* 当给定字符串为null时,转换为Empty
|
|
||||||
*
|
|
||||||
* @param str 被转换的字符串
|
|
||||||
* @return 转换后的字符串
|
|
||||||
*/
|
|
||||||
public static String emptyIfNull(final CharSequence str) {
|
|
||||||
return ObjUtil.defaultIfNull(str, EMPTY).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当给定字符串为空字符串时,转换为{@code null}
|
* 当给定字符串为空字符串时,转换为{@code null}
|
||||||
*
|
*
|
||||||
@ -215,9 +232,9 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* 注意,和{@link String#trim()}不同,此方法使用{@link CharUtil#isBlankChar(char)} 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
|
* 注意,和{@link String#trim()}不同,此方法使用{@link CharUtil#isBlankChar(char)} 来判定空白, 因而可以除去英文字符集之外的其它空白,如中文空格。
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>去除字符串空格罗列相关如下:</li>
|
* <li>去除字符串空格罗列相关如下:</li>
|
||||||
* <li>{@link StrUtil#trimPrefix(CharSequence)}去除头部空格</li>
|
* <li>{@link #trimPrefix(CharSequence)}去除头部空格</li>
|
||||||
* <li>{@link StrUtil#trimSuffix(CharSequence)}去除尾部空格</li>
|
* <li>{@link #trimSuffix(CharSequence)}去除尾部空格</li>
|
||||||
* <li>{@link StrUtil#cleanBlank(CharSequence)}去除头部、尾部、中间空格</li>
|
* <li>{@link #cleanBlank(CharSequence)}去除头部、尾部、中间空格</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
@ -653,7 +670,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* <li>str 不是 null,testChars 是 null,直接返回 false</li>
|
* <li>str 不是 null,testChars 是 null,直接返回 false</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* StrUtil.containsOnly("asdas", 'a', 'd', 's','l'); --> true
|
* CharSequenceUtil.containsOnly("asdas", 'a', 'd', 's','l'); --> true
|
||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
*
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
@ -1035,7 +1052,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
public static String removeAll(final CharSequence str, final CharSequence strToRemove) {
|
public static String removeAll(final CharSequence str, final CharSequence strToRemove) {
|
||||||
// strToRemove如果为空, 也不用继续后面的逻辑
|
// strToRemove如果为空, 也不用继续后面的逻辑
|
||||||
if (isEmpty(str) || isEmpty(strToRemove)) {
|
if (isEmpty(str) || isEmpty(strToRemove)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return str.toString().replace(strToRemove, EMPTY);
|
return str.toString().replace(strToRemove, EMPTY);
|
||||||
}
|
}
|
||||||
@ -1050,7 +1067,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* @since 5.3.8
|
* @since 5.3.8
|
||||||
*/
|
*/
|
||||||
public static String removeAny(final CharSequence str, final CharSequence... strsToRemove) {
|
public static String removeAny(final CharSequence str, final CharSequence... strsToRemove) {
|
||||||
String result = str(str);
|
String result = toStringOrNull(str);
|
||||||
if (isNotEmpty(str)) {
|
if (isNotEmpty(str)) {
|
||||||
for (final CharSequence strToRemove : strsToRemove) {
|
for (final CharSequence strToRemove : strsToRemove) {
|
||||||
result = removeAll(result, strToRemove);
|
result = removeAll(result, strToRemove);
|
||||||
@ -1068,8 +1085,8 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* @since 4.2.2
|
* @since 4.2.2
|
||||||
*/
|
*/
|
||||||
public static String removeAll(final CharSequence str, final char... chars) {
|
public static String removeAll(final CharSequence str, final char... chars) {
|
||||||
if (null == str || ArrayUtil.isEmpty(chars)) {
|
if (StrUtil.isEmpty(str) || ArrayUtil.isEmpty(chars)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return filter(str, (c) -> !ArrayUtil.contains(chars, c));
|
return filter(str, (c) -> !ArrayUtil.contains(chars, c));
|
||||||
}
|
}
|
||||||
@ -1157,7 +1174,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String removePrefix(final CharSequence str, final CharSequence prefix, final boolean ignoreCase) {
|
public static String removePrefix(final CharSequence str, final CharSequence prefix, final boolean ignoreCase) {
|
||||||
if (isEmpty(str) || isEmpty(prefix)) {
|
if (isEmpty(str) || isEmpty(prefix)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String str2 = str.toString();
|
final String str2 = str.toString();
|
||||||
@ -1176,7 +1193,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String removeSuffix(final CharSequence str, final CharSequence suffix) {
|
public static String removeSuffix(final CharSequence str, final CharSequence suffix) {
|
||||||
if (isEmpty(str) || isEmpty(suffix)) {
|
if (isEmpty(str) || isEmpty(suffix)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String str2 = str.toString();
|
final String str2 = str.toString();
|
||||||
@ -1206,7 +1223,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String removeSuffixIgnoreCase(final CharSequence str, final CharSequence suffix) {
|
public static String removeSuffixIgnoreCase(final CharSequence str, final CharSequence suffix) {
|
||||||
if (isEmpty(str) || isEmpty(suffix)) {
|
if (isEmpty(str) || isEmpty(suffix)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String str2 = str.toString();
|
final String str2 = str.toString();
|
||||||
@ -1257,7 +1274,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String strip(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
public static String strip(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int from = 0;
|
int from = 0;
|
||||||
@ -1297,7 +1314,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String stripIgnoreCase(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
public static String stripIgnoreCase(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
int from = 0;
|
int from = 0;
|
||||||
int to = str.length();
|
int to = str.length();
|
||||||
@ -1384,7 +1401,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String sub(final CharSequence str, int fromIndexInclude, int toIndexExclude) {
|
public static String sub(final CharSequence str, int fromIndexInclude, int toIndexExclude) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final int len = str.length();
|
final int len = str.length();
|
||||||
|
|
||||||
@ -1429,7 +1446,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String subByCodePoint(final CharSequence str, final int fromIndex, final int toIndex) {
|
public static String subByCodePoint(final CharSequence str, final int fromIndex, final int toIndex) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromIndex < 0 || fromIndex > toIndex) {
|
if (fromIndex < 0 || fromIndex > toIndex) {
|
||||||
@ -1471,7 +1488,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String subPreGbk(final CharSequence str, int len, final boolean halfUp) {
|
public static String subPreGbk(final CharSequence str, int len, final boolean halfUp) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
int counterOfDoubleByte = 0;
|
int counterOfDoubleByte = 0;
|
||||||
@ -2214,7 +2231,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* @return 包装后的字符串
|
* @return 包装后的字符串
|
||||||
*/
|
*/
|
||||||
public static String wrap(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
public static String wrap(final CharSequence str, final CharSequence prefix, final CharSequence suffix) {
|
||||||
return emptyIfNull(prefix).concat(emptyIfNull(str)).concat(emptyIfNull(suffix));
|
return toStringOrEmpty(prefix).concat(toStringOrEmpty(str)).concat(toStringOrEmpty(suffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2226,7 +2243,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* @return 包装后的字符串
|
* @return 包装后的字符串
|
||||||
*/
|
*/
|
||||||
public static String wrap(final CharSequence str, final char prefix, final char suffix) {
|
public static String wrap(final CharSequence str, final char prefix, final char suffix) {
|
||||||
return prefix + emptyIfNull(str) + suffix;
|
return prefix + toStringOrEmpty(str) + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2347,7 +2364,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String unWrap(final CharSequence str, final char prefix, final char suffix) {
|
public static String unWrap(final CharSequence str, final char prefix, final char suffix) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
if (str.charAt(0) == prefix && str.charAt(str.length() - 1) == suffix) {
|
if (str.charAt(0) == prefix && str.charAt(str.length() - 1) == suffix) {
|
||||||
return sub(str, 1, str.length() - 1);
|
return sub(str, 1, str.length() - 1);
|
||||||
@ -2595,7 +2612,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String center(CharSequence str, final int size, final char padChar) {
|
public static String center(CharSequence str, final int size, final char padChar) {
|
||||||
if (str == null || size <= 0) {
|
if (str == null || size <= 0) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final int strLen = str.length();
|
final int strLen = str.length();
|
||||||
final int pads = size - strLen;
|
final int pads = size - strLen;
|
||||||
@ -2629,7 +2646,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String center(CharSequence str, final int size, CharSequence padStr) {
|
public static String center(CharSequence str, final int size, CharSequence padStr) {
|
||||||
if (str == null || size <= 0) {
|
if (str == null || size <= 0) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
if (isEmpty(padStr)) {
|
if (isEmpty(padStr)) {
|
||||||
padStr = SPACE;
|
padStr = SPACE;
|
||||||
@ -2796,7 +2813,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
* @since 4.0.2
|
* @since 4.0.2
|
||||||
*/
|
*/
|
||||||
public static int compareVersion(final CharSequence version1, final CharSequence version2) {
|
public static int compareVersion(final CharSequence version1, final CharSequence version2) {
|
||||||
return VersionComparator.INSTANCE.compare(str(version1), str(version2));
|
return VersionComparator.INSTANCE.compare(toStringOrNull(version1), toStringOrNull(version2));
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@ -2842,7 +2859,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String appendIfMissing(final CharSequence str, final CharSequence suffix, final boolean ignoreCase, final CharSequence... testSuffixes) {
|
public static String appendIfMissing(final CharSequence str, final CharSequence suffix, final boolean ignoreCase, final CharSequence... testSuffixes) {
|
||||||
if (str == null || isEmpty(suffix) || endWith(str, suffix, ignoreCase)) {
|
if (str == null || isEmpty(suffix) || endWith(str, suffix, ignoreCase)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
if (ArrayUtil.isNotEmpty(testSuffixes)) {
|
if (ArrayUtil.isNotEmpty(testSuffixes)) {
|
||||||
for (final CharSequence testSuffix : testSuffixes) {
|
for (final CharSequence testSuffix : testSuffixes) {
|
||||||
@ -2894,7 +2911,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String prependIfMissing(final CharSequence str, final CharSequence prefix, final boolean ignoreCase, final CharSequence... prefixes) {
|
public static String prependIfMissing(final CharSequence str, final CharSequence prefix, final boolean ignoreCase, final CharSequence... prefixes) {
|
||||||
if (str == null || isEmpty(prefix) || startWith(str, prefix, ignoreCase)) {
|
if (str == null || isEmpty(prefix) || startWith(str, prefix, ignoreCase)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
if (ArrayUtil.isNotEmpty(prefixes)) {
|
if (ArrayUtil.isNotEmpty(prefixes)) {
|
||||||
for (final CharSequence s : prefixes) {
|
for (final CharSequence s : prefixes) {
|
||||||
@ -2920,11 +2937,11 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String replaceFirst(final CharSequence str, final CharSequence searchStr, final CharSequence replacedStr, final boolean ignoreCase) {
|
public static String replaceFirst(final CharSequence str, final CharSequence searchStr, final CharSequence replacedStr, final boolean ignoreCase) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final int startInclude = indexOf(str, searchStr, 0, ignoreCase);
|
final int startInclude = indexOf(str, searchStr, 0, ignoreCase);
|
||||||
if (INDEX_NOT_FOUND == startInclude) {
|
if (INDEX_NOT_FOUND == startInclude) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return replaceByCodePoint(str, startInclude, startInclude + searchStr.length(), replacedStr);
|
return replaceByCodePoint(str, startInclude, startInclude + searchStr.length(), replacedStr);
|
||||||
}
|
}
|
||||||
@ -2940,11 +2957,11 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String replaceLast(final CharSequence str, final CharSequence searchStr, final CharSequence replacedStr, final boolean ignoreCase) {
|
public static String replaceLast(final CharSequence str, final CharSequence searchStr, final CharSequence replacedStr, final boolean ignoreCase) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final int lastIndex = lastIndexOf(str, searchStr, str.length(), ignoreCase);
|
final int lastIndex = lastIndexOf(str, searchStr, str.length(), ignoreCase);
|
||||||
if (INDEX_NOT_FOUND == lastIndex) {
|
if (INDEX_NOT_FOUND == lastIndex) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return replace(str, lastIndex, searchStr, replacedStr, ignoreCase);
|
return replace(str, lastIndex, searchStr, replacedStr, ignoreCase);
|
||||||
}
|
}
|
||||||
@ -3003,7 +3020,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String replace(final CharSequence str, final int fromIndex, final CharSequence searchStr, final CharSequence replacement, final boolean ignoreCase) {
|
public static String replace(final CharSequence str, final int fromIndex, final CharSequence searchStr, final CharSequence replacement, final boolean ignoreCase) {
|
||||||
if (isEmpty(str) || isEmpty(searchStr)) {
|
if (isEmpty(str) || isEmpty(searchStr)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return new SearchReplacer(fromIndex, searchStr, replacement, ignoreCase).apply(str);
|
return new SearchReplacer(fromIndex, searchStr, replacement, ignoreCase).apply(str);
|
||||||
}
|
}
|
||||||
@ -3108,7 +3125,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String replaceChars(final CharSequence str, final String chars, final CharSequence replacedStr) {
|
public static String replaceChars(final CharSequence str, final String chars, final CharSequence replacedStr) {
|
||||||
if (isEmpty(str) || isEmpty(chars)) {
|
if (isEmpty(str) || isEmpty(chars)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return replaceChars(str, chars.toCharArray(), replacedStr);
|
return replaceChars(str, chars.toCharArray(), replacedStr);
|
||||||
}
|
}
|
||||||
@ -3124,7 +3141,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String replaceChars(final CharSequence str, final char[] chars, final CharSequence replacedStr) {
|
public static String replaceChars(final CharSequence str, final char[] chars, final CharSequence replacedStr) {
|
||||||
if (isEmpty(str) || ArrayUtil.isEmpty(chars)) {
|
if (isEmpty(str) || ArrayUtil.isEmpty(chars)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<Character> set = new HashSet<>(chars.length);
|
final Set<Character> set = new HashSet<>(chars.length);
|
||||||
@ -3144,8 +3161,8 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
/**
|
/**
|
||||||
* 按照给定逻辑替换指定位置的字符,如字符大小写转换等
|
* 按照给定逻辑替换指定位置的字符,如字符大小写转换等
|
||||||
*
|
*
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @param index 位置,-1表示最后一个字符
|
* @param index 位置,-1表示最后一个字符
|
||||||
* @param operator 替换逻辑,给定原字符,返回新字符
|
* @param operator 替换逻辑,给定原字符,返回新字符
|
||||||
* @return 替换后的字符串
|
* @return 替换后的字符串
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
@ -3281,11 +3298,11 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
final int factor, final boolean appendDots) {
|
final int factor, final boolean appendDots) {
|
||||||
//字符数*速算因子<=最大字节数
|
//字符数*速算因子<=最大字节数
|
||||||
if (str == null || str.length() * factor <= maxBytesLength) {
|
if (str == null || str.length() * factor <= maxBytesLength) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final byte[] sba = ByteUtil.toBytes(str, charset);
|
final byte[] sba = ByteUtil.toBytes(str, charset);
|
||||||
if (sba.length <= maxBytesLength) {
|
if (sba.length <= maxBytesLength) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
//限制字节数
|
//限制字节数
|
||||||
final int limitBytes;
|
final int limitBytes;
|
||||||
@ -3430,7 +3447,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String filter(final CharSequence str, final Predicate<Character> predicate) {
|
public static String filter(final CharSequence str, final Predicate<Character> predicate) {
|
||||||
if (str == null || predicate == null) {
|
if (str == null || predicate == null) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int len = str.length();
|
final int len = str.length();
|
||||||
@ -3638,7 +3655,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
public static String concat(final boolean isNullToEmpty, final CharSequence... strs) {
|
public static String concat(final boolean isNullToEmpty, final CharSequence... strs) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (final CharSequence str : strs) {
|
for (final CharSequence str : strs) {
|
||||||
sb.append(isNullToEmpty ? emptyIfNull(str) : str);
|
sb.append(isNullToEmpty ? toStringOrEmpty(str) : str);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@ -3694,6 +3711,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// region ----- join
|
// region ----- join
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以 conjunction 为分隔符将多个对象转换为字符串
|
* 以 conjunction 为分隔符将多个对象转换为字符串
|
||||||
*
|
*
|
||||||
@ -3747,7 +3765,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
*/
|
*/
|
||||||
public static String move(final CharSequence str, final int startInclude, final int endExclude, int moveLength) {
|
public static String move(final CharSequence str, final int startInclude, final int endExclude, int moveLength) {
|
||||||
if (isEmpty(str)) {
|
if (isEmpty(str)) {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
final int len = str.length();
|
final int len = str.length();
|
||||||
if (Math.abs(moveLength) > len) {
|
if (Math.abs(moveLength) > len) {
|
||||||
@ -3768,7 +3786,7 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
.append(str.subSequence(startAfterMove, startInclude))//
|
.append(str.subSequence(startAfterMove, startInclude))//
|
||||||
.append(str.subSequence(endExclude, str.length()));
|
.append(str.subSequence(endExclude, str.length()));
|
||||||
} else {
|
} else {
|
||||||
return str(str);
|
return toStringOrNull(str);
|
||||||
}
|
}
|
||||||
return strBuilder.toString();
|
return strBuilder.toString();
|
||||||
}
|
}
|
||||||
@ -3865,4 +3883,19 @@ public class CharSequenceUtil extends StrValidator {
|
|||||||
}
|
}
|
||||||
return str1.subSequence(str1Index + 1, str1.length());
|
return str1.subSequence(str1Index + 1, str1.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串转换为字符数组
|
||||||
|
*
|
||||||
|
* @param str 字符串
|
||||||
|
* @param isCodePoint 是否为Unicode码点(即支持emoji等多char字符)
|
||||||
|
* @return 字符数组
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
public static int[] toChars(final CharSequence str, final boolean isCodePoint) {
|
||||||
|
if (null == str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (isCodePoint ? str.codePoints() : str.chars()).toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ package org.dromara.hutool.core.text;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
||||||
import org.dromara.hutool.core.collection.iter.IterUtil;
|
import org.dromara.hutool.core.collection.iter.IterUtil;
|
||||||
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.io.IORuntimeException;
|
import org.dromara.hutool.core.io.IORuntimeException;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import org.dromara.hutool.core.util.ObjUtil;
|
||||||
@ -234,7 +235,7 @@ public class StrJoiner implements Appendable, Serializable {
|
|||||||
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
|
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
|
||||||
append(entry.getKey()).append(entry.getValue());
|
append(entry.getKey()).append(entry.getValue());
|
||||||
} else {
|
} else {
|
||||||
append(ObjUtil.toString(obj));
|
append(Convert.toStr(obj));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class StrTrimer implements UnaryOperator<CharSequence>, Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public String apply(final CharSequence str) {
|
public String apply(final CharSequence str) {
|
||||||
if (StrUtil.isEmpty(str)) {
|
if (StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int length = str.length();
|
final int length = str.length();
|
||||||
|
@ -241,41 +241,6 @@ public class StrUtil extends CharSequenceUtil implements StrPool {
|
|||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用对象的toString方法,null会返回“null”
|
|
||||||
*
|
|
||||||
* @param obj 对象
|
|
||||||
* @return 字符串
|
|
||||||
* @since 4.1.3
|
|
||||||
* @see String#valueOf(Object)
|
|
||||||
*/
|
|
||||||
public static String toString(final Object obj) {
|
|
||||||
return String.valueOf(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用对象的toString方法,{@code null}会返回{@code null}
|
|
||||||
*
|
|
||||||
* @param obj 对象
|
|
||||||
* @return 字符串 or {@code null}
|
|
||||||
* @since 5.7.17
|
|
||||||
*/
|
|
||||||
public static String toStringOrNull(final Object obj) {
|
|
||||||
return null == obj ? null : obj.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用对象的toString方法,{@code null}会返回空字符串 ""
|
|
||||||
*
|
|
||||||
* @param obj 对象
|
|
||||||
* @return {@link String }
|
|
||||||
* @author Junwei Xu
|
|
||||||
*/
|
|
||||||
public static String toStringOrEmpty(final Object obj) {
|
|
||||||
// obj为空时, 返回 null 或 "null" 都不适用部分场景, 此处返回 "" 空字符串
|
|
||||||
return null == obj ? EMPTY : obj.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建StringBuilder对象
|
* 创建StringBuilder对象
|
||||||
*
|
*
|
||||||
|
@ -182,6 +182,68 @@ public class StrValidator {
|
|||||||
return !isEmpty(str);
|
return !isEmpty(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>指定字符串数组中,是否包含空字符串。</p>
|
||||||
|
* <p>如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。</p>
|
||||||
|
* <br>
|
||||||
|
*
|
||||||
|
* <p>例:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code hasBlank() // true}</li>
|
||||||
|
* <li>{@code hasBlank("", null, " ") // true}</li>
|
||||||
|
* <li>{@code hasBlank("123", " ") // true}</li>
|
||||||
|
* <li>{@code hasBlank("123", "abc") // false}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>注意:该方法与 {@link #isAllBlank(CharSequence...)} 的区别在于:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>hasBlank(CharSequence...) 等价于 {@code isBlank(...) || isBlank(...) || ...}</li>
|
||||||
|
* <li>{@link #isAllBlank(CharSequence...)} 等价于 {@code isBlank(...) && isBlank(...) && ...}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param strs 字符串列表
|
||||||
|
* @return 是否包含空字符串
|
||||||
|
*/
|
||||||
|
public static boolean hasBlank(final CharSequence... strs) {
|
||||||
|
return ArrayUtil.hasBlank(strs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存都不为{@code null}或空对象或空白符的对象,通过{@link #hasBlank(CharSequence...)} 判断元素
|
||||||
|
*
|
||||||
|
* @param args 被检查的对象,一个或者多个
|
||||||
|
* @return 是否都不为空
|
||||||
|
*/
|
||||||
|
public static boolean isAllNotBlank(final CharSequence... args) {
|
||||||
|
return ArrayUtil.isAllNotBlank(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>指定字符串数组中的元素,是否全部为空字符串。</p>
|
||||||
|
* <p>如果指定的字符串数组的长度为 0,或者所有元素都是空字符串,则返回 true。</p>
|
||||||
|
* <br>
|
||||||
|
*
|
||||||
|
* <p>例:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code isAllBlank() // true}</li>
|
||||||
|
* <li>{@code isAllBlank("", null, " ") // true}</li>
|
||||||
|
* <li>{@code isAllBlank("123", " ") // false}</li>
|
||||||
|
* <li>{@code isAllBlank("123", "abc") // false}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>注意:该方法与 {@link #hasBlank(CharSequence...)} 的区别在于:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link #hasBlank(CharSequence...)} 等价于 {@code isBlank(...) || isBlank(...) || ...}</li>
|
||||||
|
* <li>isAllBlank(CharSequence...) 等价于 {@code isBlank(...) && isBlank(...) && ...}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param strs 字符串列表
|
||||||
|
* @return 所有字符串是否为空白
|
||||||
|
*/
|
||||||
|
public static boolean isAllBlank(final CharSequence... strs) {
|
||||||
|
return ArrayUtil.isAllBlank(strs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>是否包含空字符串。</p>
|
* <p>是否包含空字符串。</p>
|
||||||
* <p>如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。</p>
|
* <p>如果指定的字符串数组的长度为 0,或者其中的任意一个元素是空字符串,则返回 true。</p>
|
||||||
|
@ -124,7 +124,7 @@ public class EscapeUtil {
|
|||||||
*/
|
*/
|
||||||
public static String escape(final CharSequence content, final Predicate<Character> filter) {
|
public static String escape(final CharSequence content, final Predicate<Character> filter) {
|
||||||
if (StrUtil.isEmpty(content)) {
|
if (StrUtil.isEmpty(content)) {
|
||||||
return StrUtil.str(content);
|
return StrUtil.toStringOrNull(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder tmp = new StringBuilder(content.length() * 6);
|
final StringBuilder tmp = new StringBuilder(content.length() * 6);
|
||||||
|
@ -46,11 +46,11 @@ public class RangeReplacerByChar extends StrReplacer {
|
|||||||
@Override
|
@Override
|
||||||
public String apply(final CharSequence str) {
|
public String apply(final CharSequence str) {
|
||||||
if (StrUtil.isEmpty(str)) {
|
if (StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String originalStr = StrUtil.str(str);
|
final String originalStr = str.toString();
|
||||||
final int[] chars = (isCodePoint ? originalStr.codePoints() : originalStr.chars()).toArray();
|
final int[] chars = StrUtil.toChars(originalStr, this.isCodePoint);
|
||||||
final int strLength = chars.length;
|
final int strLength = chars.length;
|
||||||
|
|
||||||
final int beginInclude = this.beginInclude;
|
final int beginInclude = this.beginInclude;
|
||||||
|
@ -46,11 +46,11 @@ public class RangeReplacerByStr extends StrReplacer {
|
|||||||
@Override
|
@Override
|
||||||
public String apply(final CharSequence str) {
|
public String apply(final CharSequence str) {
|
||||||
if (StrUtil.isEmpty(str)) {
|
if (StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String originalStr = StrUtil.str(str);
|
final String originalStr = str.toString();
|
||||||
final int[] chars = (isCodePoint ? originalStr.codePoints() : originalStr.chars()).toArray();
|
final int[] chars = StrUtil.toChars(originalStr, this.isCodePoint);
|
||||||
final int strLength = chars.length;
|
final int strLength = chars.length;
|
||||||
|
|
||||||
final int beginInclude = this.beginInclude;
|
final int beginInclude = this.beginInclude;
|
||||||
|
@ -46,20 +46,20 @@ public class SearchReplacer extends StrReplacer {
|
|||||||
this.fromIndex = Math.max(fromIndex, 0);
|
this.fromIndex = Math.max(fromIndex, 0);
|
||||||
this.searchStr = Assert.notEmpty(searchStr, "'searchStr' must be not empty!");
|
this.searchStr = Assert.notEmpty(searchStr, "'searchStr' must be not empty!");
|
||||||
this.searchStrLength = searchStr.length();
|
this.searchStrLength = searchStr.length();
|
||||||
this.replacement = StrUtil.emptyIfNull(replacement);
|
this.replacement = StrUtil.toStringOrEmpty(replacement);
|
||||||
this.ignoreCase = ignoreCase;
|
this.ignoreCase = ignoreCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apply(final CharSequence str) {
|
public String apply(final CharSequence str) {
|
||||||
if (StrUtil.isEmpty(str)) {
|
if (StrUtil.isEmpty(str)) {
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int strLength = str.length();
|
final int strLength = str.length();
|
||||||
if (strLength < this.searchStrLength) {
|
if (strLength < this.searchStrLength) {
|
||||||
// issue#I4M16G@Gitee
|
// issue#I4M16G@Gitee
|
||||||
return StrUtil.str(str);
|
return StrUtil.toStringOrNull(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int fromIndex = this.fromIndex;
|
final int fromIndex = this.fromIndex;
|
||||||
|
@ -15,7 +15,6 @@ package org.dromara.hutool.core.util;
|
|||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import org.dromara.hutool.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import org.dromara.hutool.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.collection.iter.IterUtil;
|
import org.dromara.hutool.core.collection.iter.IterUtil;
|
||||||
import org.dromara.hutool.core.convert.Convert;
|
|
||||||
import org.dromara.hutool.core.exception.HutoolException;
|
import org.dromara.hutool.core.exception.HutoolException;
|
||||||
import org.dromara.hutool.core.io.SerializeUtil;
|
import org.dromara.hutool.core.io.SerializeUtil;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
@ -500,27 +499,4 @@ public class ObjUtil {
|
|||||||
public static Class<?> getTypeArgument(final Object obj, final int index) {
|
public static Class<?> getTypeArgument(final Object obj, final int index) {
|
||||||
return ClassUtil.getTypeArgument(obj.getClass(), index);
|
return ClassUtil.getTypeArgument(obj.getClass(), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>将对象转为字符串
|
|
||||||
* <ul>
|
|
||||||
* <li>若对象为{@code null},则返回“null”;</li>
|
|
||||||
* <li>若对象为{@link Map},则返回{@code Map.toString()};</li>
|
|
||||||
* <li>若对象为其他类型,则调用{@link Convert#toStr(Object)}进行转换;</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param obj Bean对象
|
|
||||||
* @return 转换后的字符串
|
|
||||||
* @see Convert#toStr(Object)
|
|
||||||
* @since 3.2.0
|
|
||||||
*/
|
|
||||||
public static String toString(final Object obj) {
|
|
||||||
if (null == obj) {
|
|
||||||
return StrUtil.NULL;
|
|
||||||
}
|
|
||||||
if (obj instanceof Map) {
|
|
||||||
return obj.toString();
|
|
||||||
}
|
|
||||||
return Convert.toStr(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -972,12 +972,12 @@ public class XmlUtil extends XmlConstants {
|
|||||||
*
|
*
|
||||||
* @param doc {@link Document}
|
* @param doc {@link Document}
|
||||||
* @param node 节点
|
* @param node 节点
|
||||||
* @param text 文本内容
|
* @param text 文本内容,{@code null}表示空节点
|
||||||
* @return 增加的子节点,即Text节点
|
* @return 增加的子节点,即Text节点
|
||||||
* @since 5.3.0
|
* @since 5.3.0
|
||||||
*/
|
*/
|
||||||
private static Node appendText(final Document doc, final Node node, final CharSequence text) {
|
private static Node appendText(final Document doc, final Node node, final CharSequence text) {
|
||||||
return node.appendChild(doc.createTextNode(StrUtil.str(text)));
|
return node.appendChild(doc.createTextNode(StrUtil.toStringOrEmpty(text)));
|
||||||
}
|
}
|
||||||
// ---------------------------------------------------------------------------------------- Private method end
|
// ---------------------------------------------------------------------------------------- Private method end
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ package org.dromara.hutool.core.util;
|
|||||||
import org.dromara.hutool.core.collection.ListUtil;
|
import org.dromara.hutool.core.collection.ListUtil;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.hutool.core.convert.Convert;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import org.dromara.hutool.core.util.ObjUtil;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -223,8 +224,8 @@ public class ObjUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toStringTest() {
|
public void toStringTest() {
|
||||||
Assertions.assertEquals("null", ObjUtil.toString(null));
|
Assertions.assertEquals("null", Convert.toStrOrNullStr(null));
|
||||||
Assertions.assertEquals(Collections.emptyMap().toString(), ObjUtil.toString(Collections.emptyMap()));
|
Assertions.assertEquals(Collections.emptyMap().toString(), Convert.toStrOrNullStr(Collections.emptyMap()));
|
||||||
Assertions.assertEquals("[1, 2]", Arrays.asList("1", "2").toString());
|
Assertions.assertEquals("[1, 2]", Arrays.asList("1", "2").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
@Override
|
@Override
|
||||||
public DbConfig parse(final String group) {
|
public DbConfig parse(final String group) {
|
||||||
final Setting setting = this.setting;
|
final Setting setting = this.setting;
|
||||||
final Setting subSetting = setting.getSetting(StrUtil.emptyIfNull(group));
|
final Setting subSetting = setting.getSetting(StrUtil.toStringOrEmpty(group));
|
||||||
if (MapUtil.isEmpty(subSetting)) {
|
if (MapUtil.isEmpty(subSetting)) {
|
||||||
throw new DbException("No config for group: [{}]", group);
|
throw new DbException("No config for group: [{}]", group);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class DSPool implements Closeable {
|
|||||||
* @return {@link DSWrapper} 数据源包装
|
* @return {@link DSWrapper} 数据源包装
|
||||||
*/
|
*/
|
||||||
private DSWrapper createDSWrapper(final String group) {
|
private DSWrapper createDSWrapper(final String group) {
|
||||||
final DbConfig dbConfig = this.configParser.parse(StrUtil.emptyIfNull(group));
|
final DbConfig dbConfig = this.configParser.parse(StrUtil.toStringOrEmpty(group));
|
||||||
return DSWrapper.wrap(factory.createDataSource(dbConfig), dbConfig);
|
return DSWrapper.wrap(factory.createDataSource(dbConfig), dbConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class AnalysisEngine implements TokenizerEngine {
|
|||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
final TokenStream stream;
|
final TokenStream stream;
|
||||||
try {
|
try {
|
||||||
stream = analyzer.tokenStream("text", StrUtil.str(text));
|
stream = analyzer.tokenStream("text", StrUtil.toStringOrEmpty(text));
|
||||||
stream.reset();
|
stream.reset();
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new TokenizerException(e);
|
throw new TokenizerException(e);
|
||||||
|
@ -48,7 +48,7 @@ public class AnsjEngine implements TokenizerEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
return new AnsjResult(analysis.parseStr(StrUtil.str(text)));
|
return new AnsjResult(analysis.parseStr(StrUtil.toStringOrEmpty(text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class HanLPEngine implements TokenizerEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
return new HanLPResult(this.seg.seg(StrUtil.str(text)));
|
return new HanLPResult(this.seg.seg(StrUtil.toStringOrEmpty(text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class JcsegEngine implements TokenizerEngine {
|
|||||||
// 依据给定的ADictionary和SegmenterConfig来创建ISegment
|
// 依据给定的ADictionary和SegmenterConfig来创建ISegment
|
||||||
final ISegment segment = ISegment.COMPLEX.factory.create(config, dic);
|
final ISegment segment = ISegment.COMPLEX.factory.create(config, dic);
|
||||||
try {
|
try {
|
||||||
segment.reset(new StringReader(StrUtil.str(text)));
|
segment.reset(new StringReader(StrUtil.toStringOrEmpty(text)));
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new TokenizerException(e);
|
throw new TokenizerException(e);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class JiebaEngine implements TokenizerEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
return new JiebaResult(jiebaSegmenter.process(StrUtil.str(text), mode));
|
return new JiebaResult(jiebaSegmenter.process(StrUtil.toStringOrEmpty(text), mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class MynlpEngine implements TokenizerEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
final Sentence sentence = this.lexer.scan(StrUtil.str(text));
|
final Sentence sentence = this.lexer.scan(StrUtil.toStringOrEmpty(text));
|
||||||
return new MynlpResult(sentence);
|
return new MynlpResult(sentence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class WordEngine implements TokenizerEngine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result parse(final CharSequence text) {
|
public Result parse(final CharSequence text) {
|
||||||
return new WordResult(this.segmentation.seg(StrUtil.str(text)));
|
return new WordResult(this.segmentation.seg(StrUtil.toStringOrEmpty(text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ public enum GlobalHeaders {
|
|||||||
for (final Entry<String, List<String>> entry : headers.entrySet()) {
|
for (final Entry<String, List<String>> entry : headers.entrySet()) {
|
||||||
name = entry.getKey();
|
name = entry.getKey();
|
||||||
for (final String value : entry.getValue()) {
|
for (final String value : entry.getValue()) {
|
||||||
this.header(name, StrUtil.emptyIfNull(value), false);
|
this.header(name, StrUtil.toStringOrEmpty(value), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -126,7 +126,7 @@ public interface HeaderOperation<T extends HeaderOperation<T>> {
|
|||||||
for (final Map.Entry<String, ? extends Collection<String>> entry : headerMap.entrySet()) {
|
for (final Map.Entry<String, ? extends Collection<String>> entry : headerMap.entrySet()) {
|
||||||
name = entry.getKey();
|
name = entry.getKey();
|
||||||
for (final String value : entry.getValue()) {
|
for (final String value : entry.getValue()) {
|
||||||
this.header(name, StrUtil.emptyIfNull(value), isOverride);
|
this.header(name, StrUtil.toStringOrEmpty(value), isOverride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ package org.dromara.hutool.json;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.io.ReaderWrapper;
|
import org.dromara.hutool.core.io.ReaderWrapper;
|
||||||
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.json.mapper.JSONValueMapper;
|
import org.dromara.hutool.json.mapper.JSONValueMapper;
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ public class JSONTokener extends ReaderWrapper {
|
|||||||
* @param config JSON配置
|
* @param config JSON配置
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final CharSequence s, final JSONConfig config) {
|
public JSONTokener(final CharSequence s, final JSONConfig config) {
|
||||||
this(new StringReader(StrUtil.str(s)), config);
|
this(new StringReader(Assert.notBlank(s).toString()), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +87,7 @@ public class JSONTokener extends ReaderWrapper {
|
|||||||
* @param config JSON配置
|
* @param config JSON配置
|
||||||
*/
|
*/
|
||||||
public JSONTokener(final Reader reader, final JSONConfig config) {
|
public JSONTokener(final Reader reader, final JSONConfig config) {
|
||||||
super(IoUtil.toMarkSupport(reader));
|
super(IoUtil.toMarkSupport(Assert.notNull(reader)));
|
||||||
this.eof = false;
|
this.eof = false;
|
||||||
this.usePrevious = false;
|
this.usePrevious = false;
|
||||||
this.previous = 0;
|
this.previous = 0;
|
||||||
|
@ -35,7 +35,7 @@ public class EscapeStrCellSetter extends CharSequenceCellSetter {
|
|||||||
* @param value 值
|
* @param value 值
|
||||||
*/
|
*/
|
||||||
public EscapeStrCellSetter(final CharSequence value) {
|
public EscapeStrCellSetter(final CharSequence value) {
|
||||||
super(escape(StrUtil.str(value)));
|
super(escape(StrUtil.toStringOrNull(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,9 +50,9 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
public String get(final CharSequence group, final CharSequence key) {
|
public String get(final CharSequence group, final CharSequence key) {
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> map = this.get(StrUtil.emptyIfNull(group));
|
final LinkedHashMap<String, String> map = this.get(StrUtil.toStringOrEmpty(group));
|
||||||
if (MapUtil.isNotEmpty(map)) {
|
if (MapUtil.isNotEmpty(map)) {
|
||||||
return map.get(StrUtil.str(key));
|
return map.get(StrUtil.toStringOrNull(key));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
readLock.unlock();
|
readLock.unlock();
|
||||||
@ -100,7 +100,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 此key之前存在的值,如果没有返回null
|
* @return 此key之前存在的值,如果没有返回null
|
||||||
*/
|
*/
|
||||||
public String put(String group, final String key, final String value) {
|
public String put(String group, final String key, final String value) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
writeLock.lock();
|
writeLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.computeIfAbsent(group, k -> new LinkedHashMap<>());
|
final LinkedHashMap<String, String> valueMap = this.computeIfAbsent(group, k -> new LinkedHashMap<>());
|
||||||
@ -133,7 +133,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 被删除的值,如果值不存在,返回null
|
* @return 被删除的值,如果值不存在,返回null
|
||||||
*/
|
*/
|
||||||
public String remove(String group, final String key) {
|
public String remove(String group, final String key) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
writeLock.lock();
|
writeLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -153,7 +153,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 是否为空
|
* @return 是否为空
|
||||||
*/
|
*/
|
||||||
public boolean isEmpty(String group) {
|
public boolean isEmpty(String group) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -184,7 +184,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 是否包含key
|
* @return 是否包含key
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(String group, final String key) {
|
public boolean containsKey(String group, final String key) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -205,7 +205,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 是否包含值
|
* @return 是否包含值
|
||||||
*/
|
*/
|
||||||
public boolean containsValue(String group, final String value) {
|
public boolean containsValue(String group, final String value) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -225,7 +225,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public GroupedMap clear(String group) {
|
public GroupedMap clear(String group) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
writeLock.lock();
|
writeLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -255,7 +255,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 键Set
|
* @return 键Set
|
||||||
*/
|
*/
|
||||||
public Set<String> keySet(String group) {
|
public Set<String> keySet(String group) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -275,7 +275,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public Collection<String> values(String group) {
|
public Collection<String> values(String group) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
@ -305,7 +305,7 @@ public class GroupedMap extends LinkedHashMap<String, LinkedHashMap<String, Stri
|
|||||||
* @return 键值对
|
* @return 键值对
|
||||||
*/
|
*/
|
||||||
public Set<Entry<String, String>> entrySet(String group) {
|
public Set<Entry<String, String>> entrySet(String group) {
|
||||||
group = StrUtil.emptyIfNull(group).trim();
|
group = StrUtil.toStringOrEmpty(group).trim();
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
final LinkedHashMap<String, String> valueMap = this.get(group);
|
final LinkedHashMap<String, String> valueMap = this.get(group);
|
||||||
|
@ -149,7 +149,7 @@ public class Profile implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String fixNameForProfile(final String name) {
|
private String fixNameForProfile(final String name) {
|
||||||
Assert.notBlank(name, "Setting name must be not blank !");
|
Assert.notBlank(name, "Setting name must be not blank !");
|
||||||
final String actralProfile = StrUtil.emptyIfNull(this.profile);
|
final String actralProfile = StrUtil.toStringOrEmpty(this.profile);
|
||||||
if (!name.contains(StrUtil.DOT)) {
|
if (!name.contains(StrUtil.DOT)) {
|
||||||
return StrUtil.format("{}/{}.setting", actralProfile, name);
|
return StrUtil.format("{}/{}.setting", actralProfile, name);
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,8 @@ public final class Props extends Properties implements TypeGetter<CharSequence>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getObj(final CharSequence key, final Object defaultValue) {
|
public Object getObj(final CharSequence key, final Object defaultValue) {
|
||||||
return ObjUtil.defaultIfNull(getProperty(StrUtil.str(key)), defaultValue);
|
Assert.notNull(key, "Key must be not null!");
|
||||||
|
return ObjUtil.defaultIfNull(getProperty(key.toString()), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -408,7 +409,7 @@ public final class Props extends Properties implements TypeGetter<CharSequence>
|
|||||||
* @since 4.6.3
|
* @since 4.6.3
|
||||||
*/
|
*/
|
||||||
public <T> T toBean(final T bean, String prefix) {
|
public <T> T toBean(final T bean, String prefix) {
|
||||||
prefix = StrUtil.emptyIfNull(StrUtil.addSuffixIfNot(prefix, StrUtil.DOT));
|
prefix = StrUtil.toStringOrEmpty(StrUtil.addSuffixIfNot(prefix, StrUtil.DOT));
|
||||||
|
|
||||||
String key;
|
String key;
|
||||||
for (final java.util.Map.Entry<Object, Object> entry : this.entrySet()) {
|
for (final java.util.Map.Entry<Object, Object> entry : this.entrySet()) {
|
||||||
|
@ -200,7 +200,7 @@ public class TomlWriter {
|
|||||||
indent();
|
indent();
|
||||||
writeKey(name);
|
writeKey(name);
|
||||||
write(" = ");
|
write(" = ");
|
||||||
writeString(StrUtil.emptyIfNull(ArrayUtil.toString(array)));
|
writeString(StrUtil.toStringOrEmpty(ArrayUtil.toString(array)));
|
||||||
}
|
}
|
||||||
} else if (value instanceof Map) {// table
|
} else if (value instanceof Map) {// table
|
||||||
if (simpleValues) {
|
if (simpleValues) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user