Convert change to ConvertUtil

This commit is contained in:
Looly 2024-08-23 08:36:52 +08:00
parent c6777244a0
commit 3ddad8ff6c
92 changed files with 336 additions and 339 deletions

View File

@ -20,7 +20,7 @@ import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.collection.set.SetUtil; import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.collection.set.UniqueKeySet; import org.dromara.hutool.core.collection.set.UniqueKeySet;
import org.dromara.hutool.core.comparator.CompareUtil; import org.dromara.hutool.core.comparator.CompareUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.ExceptionUtil; import org.dromara.hutool.core.exception.ExceptionUtil;
import org.dromara.hutool.core.exception.HutoolException; import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
@ -658,7 +658,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
return (A) newElements; return (A) newElements;
} }
// 可变长参数可能为包装类型如果array是原始类型则此处强转不合适采用万能转换器完成转换 // 可变长参数可能为包装类型如果array是原始类型则此处强转不合适采用万能转换器完成转换
return (A) Convert.convert(array.getClass(), newElements); return (A) ConvertUtil.convert(array.getClass(), newElements);
} }
return insert(array, length(array), newElements); return insert(array, length(array), newElements);
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.array; package org.dromara.hutool.core.array;
import org.dromara.hutool.core.collection.iter.ArrayIter; import org.dromara.hutool.core.collection.iter.ArrayIter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.wrapper.Wrapper; import org.dromara.hutool.core.lang.wrapper.Wrapper;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Validator; import org.dromara.hutool.core.lang.Validator;
@ -402,7 +402,7 @@ public class ArrayWrapper<A, E> implements Wrapper<A>, Iterable<E> {
return this; return this;
} }
if (isEmpty()) { if (isEmpty()) {
setNewArray((A) Convert.convert(array.getClass(), arrayToInsert)); setNewArray((A) ConvertUtil.convert(array.getClass(), arrayToInsert));
return this; return this;
} }
@ -414,7 +414,7 @@ public class ArrayWrapper<A, E> implements Wrapper<A>, Iterable<E> {
// 已有数组的元素类型 // 已有数组的元素类型
// 如果 已有数组的元素类型是 原始类型则需要转换 新元素数组 为该类型避免ArrayStoreException // 如果 已有数组的元素类型是 原始类型则需要转换 新元素数组 为该类型避免ArrayStoreException
if (this.componentType.isPrimitive()) { if (this.componentType.isPrimitive()) {
arrayToInsert = (A) Convert.convert(array.getClass(), arrayToInsert); arrayToInsert = (A) ConvertUtil.convert(array.getClass(), arrayToInsert);
} }
final A result = (A) Array.newInstance(this.componentType, Math.max(len, index) + appendLength); final A result = (A) Array.newInstance(this.componentType, Math.max(len, index) + appendLength);
@ -451,7 +451,7 @@ public class ArrayWrapper<A, E> implements Wrapper<A>, Iterable<E> {
return this; return this;
} }
if (isEmpty()) { if (isEmpty()) {
setNewArray((A) Convert.convert(array.getClass(), values)); setNewArray((A) ConvertUtil.convert(array.getClass(), values));
} }
if (index < 0) { if (index < 0) {
// 从头部追加 // 从头部追加

View File

@ -22,7 +22,7 @@ import org.dromara.hutool.core.bean.copier.CopyOptions;
import org.dromara.hutool.core.bean.copier.ValueProvider; import org.dromara.hutool.core.bean.copier.ValueProvider;
import org.dromara.hutool.core.bean.path.BeanPath; import org.dromara.hutool.core.bean.path.BeanPath;
import org.dromara.hutool.core.collection.set.SetUtil; import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.impl.RecordConverter; import org.dromara.hutool.core.convert.impl.RecordConverter;
import org.dromara.hutool.core.lang.mutable.MutableEntry; import org.dromara.hutool.core.lang.mutable.MutableEntry;
import org.dromara.hutool.core.map.CaseInsensitiveMap; import org.dromara.hutool.core.map.CaseInsensitiveMap;
@ -524,7 +524,7 @@ public class BeanUtil {
// issue#3091 // issue#3091
if (ClassUtil.isBasicType(targetType) || String.class == targetType) { if (ClassUtil.isBasicType(targetType) || String.class == targetType) {
return Convert.toList(targetType, collection); return ConvertUtil.toList(targetType, collection);
} }
return collection.stream().map((source) -> { return collection.stream().map((source) -> {

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.core.bean;
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.convert.ConvertUtil;
import org.dromara.hutool.core.exception.CloneException; import org.dromara.hutool.core.exception.CloneException;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.reflect.ClassUtil; import org.dromara.hutool.core.reflect.ClassUtil;
@ -174,10 +174,10 @@ public class DynaBean implements Cloneable, Serializable {
if (Map.class.isAssignableFrom(beanClass)) { if (Map.class.isAssignableFrom(beanClass)) {
((Map) bean).put(fieldName, value); ((Map) bean).put(fieldName, value);
} else if (bean instanceof List) { } else if (bean instanceof List) {
ListUtil.setOrPadding((List) bean, Convert.toInt(fieldName), value); ListUtil.setOrPadding((List) bean, ConvertUtil.toInt(fieldName), value);
} else if (ArrayUtil.isArray(bean)) { } else if (ArrayUtil.isArray(bean)) {
// issue#3008追加产生新数组此处返回新数组 // issue#3008追加产生新数组此处返回新数组
this.bean = ArrayUtil.setOrPadding(bean, Convert.toInt(fieldName), value); this.bean = ArrayUtil.setOrPadding(bean, ConvertUtil.toInt(fieldName), value);
} else { } else {
final PropDesc prop = BeanUtil.getBeanDesc(beanClass).getProp(fieldName); final PropDesc prop = BeanUtil.getBeanDesc(beanClass).getProp(fieldName);
if (null == prop) { if (null == prop) {

View File

@ -18,7 +18,7 @@ package org.dromara.hutool.core.bean;
import org.dromara.hutool.core.annotation.AnnotationUtil; import org.dromara.hutool.core.annotation.AnnotationUtil;
import org.dromara.hutool.core.annotation.PropIgnore; import org.dromara.hutool.core.annotation.PropIgnore;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.*; import org.dromara.hutool.core.reflect.*;
import org.dromara.hutool.core.reflect.method.MethodUtil; import org.dromara.hutool.core.reflect.method.MethodUtil;
@ -217,7 +217,7 @@ public class PropDesc {
// 尝试将结果转换为目标类型如果转换失败返回null即跳过此属性值 // 尝试将结果转换为目标类型如果转换失败返回null即跳过此属性值
// 来自issues#I41WKP@Gitee当忽略错误情况下目标类型转换失败应返回null // 来自issues#I41WKP@Gitee当忽略错误情况下目标类型转换失败应返回null
// 如果返回原值在集合注入时会成功但是集合取值时会报类型转换错误 // 如果返回原值在集合注入时会成功但是集合取值时会报类型转换错误
return Convert.convertWithCheck(targetType, result, null, ignoreError); return ConvertUtil.convertWithCheck(targetType, result, null, ignoreError);
} }
return result; return result;
} }
@ -303,7 +303,7 @@ public class PropDesc {
if (null != value) { if (null != value) {
final Class<?> propClass = getFieldClass(); final Class<?> propClass = getFieldClass();
if (!propClass.isInstance(value)) { if (!propClass.isInstance(value)) {
value = Convert.convertWithCheck(propClass, value, null, ignoreError); value = ConvertUtil.convertWithCheck(propClass, value, null, ignoreError);
} }
} }

View File

@ -18,7 +18,7 @@ package org.dromara.hutool.core.bean.copier;
import org.dromara.hutool.core.bean.BeanDesc; import org.dromara.hutool.core.bean.BeanDesc;
import org.dromara.hutool.core.bean.PropDesc; import org.dromara.hutool.core.bean.PropDesc;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.Converter; import org.dromara.hutool.core.convert.Converter;
import org.dromara.hutool.core.func.LambdaUtil; import org.dromara.hutool.core.func.LambdaUtil;
import org.dromara.hutool.core.func.SerFunction; import org.dromara.hutool.core.func.SerFunction;
@ -105,7 +105,7 @@ public class CopyOptions implements Serializable {
* 自定义类型转换器默认使用全局万能转换器转换 * 自定义类型转换器默认使用全局万能转换器转换
*/ */
protected Converter converter = (type, value) -> protected Converter converter = (type, value) ->
Convert.convertWithCheck(type, value, null, ignoreError); ConvertUtil.convertWithCheck(type, value, null, ignoreError);
//region create //region create

View File

@ -20,7 +20,7 @@ import org.dromara.hutool.core.bean.BeanDesc;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.bean.PropDesc; import org.dromara.hutool.core.bean.PropDesc;
import org.dromara.hutool.core.bean.copier.ValueProvider; import org.dromara.hutool.core.bean.copier.ValueProvider;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -61,7 +61,7 @@ public class BeanValueProvider implements ValueProvider<String> {
public Object value(final String key, final Type valueType) { public Object value(final String key, final Type valueType) {
final PropDesc prop = beanDesc.getProp(key); final PropDesc prop = beanDesc.getProp(key);
if (null != prop) { if (null != prop) {
return Convert.convert(valueType, prop.getValue(bean)); return ConvertUtil.convert(valueType, prop.getValue(bean));
} }
return null; return null;
} }

View File

@ -18,7 +18,7 @@ package org.dromara.hutool.core.bean.copier.provider;
import org.dromara.hutool.core.bean.DynaBean; import org.dromara.hutool.core.bean.DynaBean;
import org.dromara.hutool.core.bean.copier.ValueProvider; import org.dromara.hutool.core.bean.copier.ValueProvider;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -47,7 +47,7 @@ public class DynaBeanValueProvider implements ValueProvider<String> {
@Override @Override
public Object value(final String key, final Type valueType) { public Object value(final String key, final Type valueType) {
final Object value = dynaBean.get(key); final Object value = dynaBean.get(key);
return Convert.convertWithCheck(valueType, value, null, this.ignoreError); return ConvertUtil.convertWithCheck(valueType, value, null, this.ignoreError);
} }
@Override @Override

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.bean.copier.provider; package org.dromara.hutool.core.bean.copier.provider;
import org.dromara.hutool.core.bean.copier.ValueProvider; import org.dromara.hutool.core.bean.copier.ValueProvider;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map; import java.util.Map;
@ -43,7 +43,7 @@ public class MapValueProvider implements ValueProvider<String> {
@Override @Override
public Object value(final String key, final Type valueType) { public Object value(final String key, final Type valueType) {
return Convert.convert(valueType, map.get(key)); return ConvertUtil.convert(valueType, map.get(key));
} }
@Override @Override

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.core.bean.path.node;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.CharUtil; import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -53,9 +53,9 @@ public class ListNode implements Node{
final List<String> names = this.names; final List<String> names = this.names;
if (bean instanceof Collection) { if (bean instanceof Collection) {
return CollUtil.getAny((Collection<?>) bean, Convert.convert(int[].class, names)); return CollUtil.getAny((Collection<?>) bean, ConvertUtil.convert(int[].class, names));
} else if (ArrayUtil.isArray(bean)) { } else if (ArrayUtil.isArray(bean)) {
return ArrayUtil.getAny(bean, Convert.convert(int[].class, names)); return ArrayUtil.getAny(bean, ConvertUtil.convert(int[].class, names));
} else { } else {
final String[] unWrappedNames = getUnWrappedNames(names); final String[] unWrappedNames = getUnWrappedNames(names);
if (bean instanceof Map) { if (bean instanceof Map) {

View File

@ -29,7 +29,7 @@ import org.dromara.hutool.core.comparator.CompareUtil;
import org.dromara.hutool.core.comparator.PinyinComparator; import org.dromara.hutool.core.comparator.PinyinComparator;
import org.dromara.hutool.core.comparator.PropertyComparator; import org.dromara.hutool.core.comparator.PropertyComparator;
import org.dromara.hutool.core.convert.CompositeConverter; import org.dromara.hutool.core.convert.CompositeConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.ExceptionUtil; import org.dromara.hutool.core.exception.ExceptionUtil;
import org.dromara.hutool.core.func.SerBiConsumer; import org.dromara.hutool.core.func.SerBiConsumer;
import org.dromara.hutool.core.func.SerConsumer3; import org.dromara.hutool.core.func.SerConsumer3;
@ -1159,7 +1159,7 @@ public class CollUtil {
*/ */
public static <T> List<T> getFieldValues(final Iterable<?> collection, final String fieldName, final Class<T> elementType) { public static <T> List<T> getFieldValues(final Iterable<?> collection, final String fieldName, final Class<T> elementType) {
final Collection<Object> fieldValues = getFieldValues(collection, fieldName); final Collection<Object> fieldValues = getFieldValues(collection, fieldName);
return Convert.toList(elementType, fieldValues); return ConvertUtil.toList(elementType, fieldValues);
} }
/** /**
@ -1341,7 +1341,7 @@ public class CollUtil {
* @since 5.2.5 * @since 5.2.5
*/ */
public static <T> int[] indexOfAll(final Collection<T> collection, final Predicate<T> predicate) { public static <T> int[] indexOfAll(final Collection<T> collection, final Predicate<T> predicate) {
return Convert.convert(int[].class, indexListOfAll(collection, predicate)); return ConvertUtil.convert(int[].class, indexListOfAll(collection, predicate));
} }
/** /**

View File

@ -19,7 +19,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.convert.ConvertUtil;
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;
@ -911,7 +911,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, Convert::toStrOrNullStr); return toStr(iterator, ConvertUtil::toStrOrNullStr);
} }
/** /**

View File

@ -54,7 +54,7 @@ import java.util.concurrent.TimeUnit;
* *
* @author looly * @author looly
*/ */
public class Convert { public class ConvertUtil {
/** /**
* 转换为字符串<br> * 转换为字符串<br>

View File

@ -21,7 +21,7 @@ import org.dromara.hutool.core.codec.binary.Base64;
import org.dromara.hutool.core.collection.ListUtil; import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.collection.iter.IterUtil; import org.dromara.hutool.core.collection.iter.IterUtil;
import org.dromara.hutool.core.convert.AbstractConverter; import org.dromara.hutool.core.convert.AbstractConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.SerializeUtil; import org.dromara.hutool.core.io.SerializeUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.text.split.SplitUtil; import org.dromara.hutool.core.text.split.SplitUtil;
@ -223,7 +223,7 @@ public class ArrayConverter extends AbstractConverter {
* @since 5.4.3 * @since 5.4.3
*/ */
private Object convertComponentType(final Class<?> targetComponentType, final Object value) { private Object convertComponentType(final Class<?> targetComponentType, final Object value) {
return Convert.convertWithCheck(targetComponentType, value, null, this.ignoreElementError); return ConvertUtil.convertWithCheck(targetComponentType, value, null, this.ignoreElementError);
} }
// -------------------------------------------------------------------------------------- Private method end // -------------------------------------------------------------------------------------- Private method end
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.convert.impl; package org.dromara.hutool.core.convert.impl;
import org.dromara.hutool.core.convert.AbstractConverter; import org.dromara.hutool.core.convert.AbstractConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.util.concurrent.atomic.AtomicIntegerArray; import java.util.concurrent.atomic.AtomicIntegerArray;
@ -32,7 +32,7 @@ public class AtomicIntegerArrayConverter extends AbstractConverter {
@Override @Override
protected AtomicIntegerArray convertInternal(final Class<?> targetClass, final Object value) { protected AtomicIntegerArray convertInternal(final Class<?> targetClass, final Object value) {
return new AtomicIntegerArray(Convert.convert(int[].class, value)); return new AtomicIntegerArray(ConvertUtil.convert(int[].class, value));
} }
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.convert.impl; package org.dromara.hutool.core.convert.impl;
import org.dromara.hutool.core.convert.AbstractConverter; import org.dromara.hutool.core.convert.AbstractConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.util.concurrent.atomic.AtomicLongArray; import java.util.concurrent.atomic.AtomicLongArray;
@ -32,7 +32,7 @@ public class AtomicLongArrayConverter extends AbstractConverter {
@Override @Override
protected AtomicLongArray convertInternal(final Class<?> targetClass, final Object value) { protected AtomicLongArray convertInternal(final Class<?> targetClass, final Object value) {
return new AtomicLongArray(Convert.convert(long[].class, value)); return new AtomicLongArray(ConvertUtil.convert(long[].class, value));
} }
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.convert.impl; package org.dromara.hutool.core.convert.impl;
import org.dromara.hutool.core.convert.AbstractConverter; import org.dromara.hutool.core.convert.AbstractConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.ConvertException; import org.dromara.hutool.core.convert.ConvertException;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil; import org.dromara.hutool.core.util.ObjUtil;
@ -88,9 +88,9 @@ public class PrimitiveConverter extends AbstractConverter {
} else if (double.class == primitiveClass) { } else if (double.class == primitiveClass) {
return ObjUtil.defaultIfNull(NumberConverter.convert(value, Double.class, toStringFunc), 0); return ObjUtil.defaultIfNull(NumberConverter.convert(value, Double.class, toStringFunc), 0);
} else if (char.class == primitiveClass) { } else if (char.class == primitiveClass) {
return Convert.convert(Character.class, value); return ConvertUtil.convert(Character.class, value);
} else if (boolean.class == primitiveClass) { } else if (boolean.class == primitiveClass) {
return Convert.convert(Boolean.class, value); return ConvertUtil.convert(Boolean.class, value);
} }
throw new ConvertException("Unsupported target type: {}", primitiveClass); throw new ConvertException("Unsupported target type: {}", primitiveClass);

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.io; package org.dromara.hutool.core.io;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
@ -53,7 +53,7 @@ public class CharsetDetector {
"BIG5", "BIG5",
"UNICODE", "UNICODE",
"US-ASCII"}; "US-ASCII"};
DEFAULT_CHARSETS = Convert.convert(Charset[].class, names); DEFAULT_CHARSETS = ConvertUtil.convert(Charset[].class, names);
} }
/** /**

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.lang; package org.dromara.hutool.core.lang;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.text.CharUtil; import org.dromara.hutool.core.text.CharUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -116,7 +116,7 @@ public class ConsoleTable {
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
column = StrUtil.toString(columns[i]); column = StrUtil.toString(columns[i]);
if (isSBCMode) { if (isSBCMode) {
column = Convert.toSBC(column); column = ConvertUtil.toSBC(column);
} }
l.add(column); l.add(column);
final int width = column.length(); final int width = column.length();

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.lang.getter; package org.dromara.hutool.core.lang.getter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -77,7 +77,7 @@ public interface GroupedTypeGetter<K, G> {
* @return 结果值 * @return 结果值
*/ */
default <T> T getByGroup(final K key, final G group, final Type type, final T defaultValue) { default <T> T getByGroup(final K key, final G group, final Type type, final T defaultValue) {
return Convert.convert(type, getObjByGroup(key, group), defaultValue); return ConvertUtil.convert(type, getObjByGroup(key, group), defaultValue);
} }
/** /**

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.lang.getter; package org.dromara.hutool.core.lang.getter;
import org.dromara.hutool.core.convert.CompositeConverter; import org.dromara.hutool.core.convert.CompositeConverter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.Converter; import org.dromara.hutool.core.convert.Converter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -57,7 +57,7 @@ import java.util.Date;
* <li>LocalTime</li> * <li>LocalTime</li>
* </ul> * </ul>
* 通过实现此接口最简单方式为通过实现{@link #getObj(Object, Object)}方法完成所有类型的值获取获取默认采用 * 通过实现此接口最简单方式为通过实现{@link #getObj(Object, Object)}方法完成所有类型的值获取获取默认采用
* {@link Convert}方式自动转换如果有自定义实现重写对应getXXX方法即可 * {@link ConvertUtil}方式自动转换如果有自定义实现重写对应getXXX方法即可
* *
* @param <K> 键类型 * @param <K> 键类型
* @author Looly * @author Looly

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.lang.range; package org.dromara.hutool.core.lang.range;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.math.NumberUtil; import org.dromara.hutool.core.math.NumberUtil;
@ -53,6 +53,6 @@ public interface Segment<T extends Number> {
default T length(){ default T length(){
final T start = Assert.notNull(getBeginIndex(), "Start index must be not null!"); final T start = Assert.notNull(getBeginIndex(), "Start index must be not null!");
final T end = Assert.notNull(getEndIndex(), "End index must be not null!"); final T end = Assert.notNull(getEndIndex(), "End index must be not null!");
return Convert.convert((Type) start.getClass(), NumberUtil.sub(end, start).abs()); return ConvertUtil.convert((Type) start.getClass(), NumberUtil.sub(end, start).abs());
} }
} }

View File

@ -20,7 +20,7 @@ import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.bean.copier.CopyOptions; import org.dromara.hutool.core.bean.copier.CopyOptions;
import org.dromara.hutool.core.bean.path.BeanPath; import org.dromara.hutool.core.bean.path.BeanPath;
import org.dromara.hutool.core.collection.set.SetUtil; import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.CloneException; import org.dromara.hutool.core.exception.CloneException;
import org.dromara.hutool.core.func.LambdaInfo; import org.dromara.hutool.core.func.LambdaInfo;
import org.dromara.hutool.core.func.LambdaUtil; import org.dromara.hutool.core.func.LambdaUtil;
@ -111,7 +111,7 @@ public class Dict extends CustomKeyMap<String, Object> implements TypeGetter<Str
for (int i = 0; i < keysAndValues.length; i++) { for (int i = 0; i < keysAndValues.length; i++) {
// 偶数 // 偶数
if ((i & 1) == 0) { if ((i & 1) == 0) {
key = Convert.toStr(keysAndValues[i]); key = ConvertUtil.toStr(keysAndValues[i]);
} else { } else {
dict.put(key, keysAndValues[i]); dict.put(key, keysAndValues[i]);
} }
@ -431,7 +431,7 @@ public class Dict extends CustomKeyMap<String, Object> implements TypeGetter<Str
* @since 5.7.14 * @since 5.7.14
*/ */
public <T> T getByPath(final String expression, final Type resultType) { public <T> T getByPath(final String expression, final Type resultType) {
return Convert.convert(resultType, getByPath(expression)); return ConvertUtil.convert(resultType, getByPath(expression));
} }
// -------------------------------------------------------------------- Get end // -------------------------------------------------------------------- Get end

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.map; package org.dromara.hutool.core.map;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import java.util.Date; import java.util.Date;
@ -280,7 +280,7 @@ public class MapGetUtil {
* @since 5.3.11 * @since 5.3.11
*/ */
public static <T> T get(final Map<?, ?> map, final Object key, final Class<T> type, final T defaultValue) { public static <T> T get(final Map<?, ?> map, final Object key, final Class<T> type, final T defaultValue) {
return null == map ? defaultValue : Convert.convert(type, map.get(key), defaultValue); return null == map ? defaultValue : ConvertUtil.convert(type, map.get(key), defaultValue);
} }
/** /**
@ -295,7 +295,7 @@ public class MapGetUtil {
* @since 5.5.3 * @since 5.5.3
*/ */
public static <T> T getQuietly(final Map<?, ?> map, final Object key, final Class<T> type, final T defaultValue) { public static <T> T getQuietly(final Map<?, ?> map, final Object key, final Class<T> type, final T defaultValue) {
return null == map ? defaultValue : Convert.convertQuietly(type, map.get(key), defaultValue); return null == map ? defaultValue : ConvertUtil.convertQuietly(type, map.get(key), defaultValue);
} }
/** /**
@ -324,7 +324,7 @@ public class MapGetUtil {
* @since 5.3.11 * @since 5.3.11
*/ */
public static <T> T get(final Map<?, ?> map, final Object key, final TypeReference<T> type, final T defaultValue) { public static <T> T get(final Map<?, ?> map, final Object key, final TypeReference<T> type, final T defaultValue) {
return null == map ? defaultValue : Convert.convert(type, map.get(key), defaultValue); return null == map ? defaultValue : ConvertUtil.convert(type, map.get(key), defaultValue);
} }
/** /**
@ -339,6 +339,6 @@ public class MapGetUtil {
* @since 5.5.3 * @since 5.5.3
*/ */
public static <T> T getQuietly(final Map<?, ?> map, final Object key, final TypeReference<T> type, final T defaultValue) { public static <T> T getQuietly(final Map<?, ?> map, final Object key, final TypeReference<T> type, final T defaultValue) {
return null == map ? defaultValue : Convert.convertQuietly(type, map.get(key), defaultValue); return null == map ? defaultValue : ConvertUtil.convertQuietly(type, map.get(key), defaultValue);
} }
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.map; package org.dromara.hutool.core.map;
import org.dromara.hutool.core.classloader.ClassLoaderUtil; import org.dromara.hutool.core.classloader.ClassLoaderUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.getter.TypeGetter; import org.dromara.hutool.core.lang.getter.TypeGetter;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
@ -160,7 +160,7 @@ public class MapProxy implements Map<Object, Object>, TypeGetter<Object>, Invoca
// 驼峰不存在转下划线尝试 // 驼峰不存在转下划线尝试
fieldName = StrUtil.toUnderlineCase(fieldName); fieldName = StrUtil.toUnderlineCase(fieldName);
} }
return Convert.convert(method.getGenericReturnType(), this.get(fieldName)); return ConvertUtil.convert(method.getGenericReturnType(), this.get(fieldName));
} }
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.net.multipart; package org.dromara.hutool.core.net.multipart;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.map.multi.ListValueMap; import org.dromara.hutool.core.map.multi.ListValueMap;
import org.dromara.hutool.core.map.multi.MultiValueMap; import org.dromara.hutool.core.map.multi.MultiValueMap;
@ -163,7 +163,7 @@ public class MultipartFormData {
* @return 所有属性的集合 * @return 所有属性的集合
*/ */
public Map<String, String[]> getParamMap() { public Map<String, String[]> getParamMap() {
return Convert.toMap(String.class, String[].class, getParamListMap()); return ConvertUtil.toMap(String.class, String[].class, getParamListMap());
} }
/** /**
@ -232,7 +232,7 @@ public class MultipartFormData {
* @return 文件映射 * @return 文件映射
*/ */
public Map<String, UploadFile[]> getFileMap() { public Map<String, UploadFile[]> getFileMap() {
return Convert.toMap(String.class, UploadFile[].class, getFileListValueMap()); return ConvertUtil.toMap(String.class, UploadFile[].class, getFileListValueMap());
} }
/** /**

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.core.net.url;
import org.dromara.hutool.core.codec.PercentCodec; import org.dromara.hutool.core.codec.PercentCodec;
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.convert.ConvertUtil;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.map.TableMap; import org.dromara.hutool.core.map.TableMap;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -386,7 +386,7 @@ public class UrlQuery {
} else if (value instanceof Iterator) { } else if (value instanceof Iterator) {
result = IterUtil.join((Iterator<?>) value, ","); result = IterUtil.join((Iterator<?>) value, ",");
} else { } else {
result = Convert.toStr(value); result = ConvertUtil.toStr(value);
} }
return result; return result;
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.net.url; package org.dromara.hutool.core.net.url;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -199,7 +199,7 @@ public class UrlQueryUtil {
if (MapUtil.isEmpty(queryMap)) { if (MapUtil.isEmpty(queryMap)) {
return MapUtil.empty(); return MapUtil.empty();
} }
return Convert.toMap(String.class, String.class, queryMap); return ConvertUtil.toMap(String.class, String.class, queryMap);
} }
/** /**

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.reflect; package org.dromara.hutool.core.reflect;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.map.reference.WeakConcurrentMap; import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@ -53,7 +53,7 @@ public class ActualTypeMapperPool {
* @since 5.7.16 * @since 5.7.16
*/ */
public static Map<String, Type> getStrKeyMap(final Type type){ public static Map<String, Type> getStrKeyMap(final Type type){
return Convert.toMap(String.class, Type.class, get(type)); return ConvertUtil.toMap(String.class, Type.class, get(type));
} }
/** /**

View File

@ -18,7 +18,7 @@ package org.dromara.hutool.core.reflect;
import org.dromara.hutool.core.annotation.Alias; import org.dromara.hutool.core.annotation.Alias;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.HutoolException; import org.dromara.hutool.core.exception.HutoolException;
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;
@ -341,7 +341,7 @@ public class FieldUtil {
if (null != value) { if (null != value) {
if (!fieldType.isAssignableFrom(value.getClass())) { if (!fieldType.isAssignableFrom(value.getClass())) {
//对于类型不同的字段尝试转换转换失败则使用原对象类型 //对于类型不同的字段尝试转换转换失败则使用原对象类型
final Object targetValue = Convert.convert(fieldType, value); final Object targetValue = ConvertUtil.convert(fieldType, value);
if (null != targetValue) { if (null != targetValue) {
value = targetValue; value = targetValue;
} }

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.core.reflect.method;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.bean.NullWrapperBean; import org.dromara.hutool.core.bean.NullWrapperBean;
import org.dromara.hutool.core.classloader.ClassLoaderUtil; import org.dromara.hutool.core.classloader.ClassLoaderUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.ExceptionUtil; import org.dromara.hutool.core.exception.ExceptionUtil;
import org.dromara.hutool.core.exception.HutoolException; import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
@ -749,7 +749,7 @@ public class MethodUtil {
actualArgs[i] = null; actualArgs[i] = null;
} else if (!parameterTypes[i].isAssignableFrom(args[i].getClass())) { } else if (!parameterTypes[i].isAssignableFrom(args[i].getClass())) {
//对于类型不同的字段尝试转换转换失败则使用原对象类型 //对于类型不同的字段尝试转换转换失败则使用原对象类型
final Object targetValue = Convert.convert(parameterTypes[i], args[i], args[i]); final Object targetValue = ConvertUtil.convert(parameterTypes[i], args[i], args[i]);
if (null != targetValue) { if (null != targetValue) {
actualArgs[i] = targetValue; actualArgs[i] = targetValue;
} }

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.core.regex;
import org.dromara.hutool.core.collection.set.SetUtil; import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.comparator.CompareUtil; import org.dromara.hutool.core.comparator.CompareUtil;
import org.dromara.hutool.core.comparator.StrLengthComparator; import org.dromara.hutool.core.comparator.StrLengthComparator;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.func.SerFunction; import org.dromara.hutool.core.func.SerFunction;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Validator; import org.dromara.hutool.core.lang.Validator;
@ -801,7 +801,7 @@ public class ReUtil {
* @return 整数 * @return 整数
*/ */
public static Integer getFirstNumber(final CharSequence stringWithNumber) { public static Integer getFirstNumber(final CharSequence stringWithNumber) {
return Convert.toInt(get(PatternPool.NUMBERS, stringWithNumber, 0), null); return ConvertUtil.toInt(get(PatternPool.NUMBERS, stringWithNumber, 0), null);
} }
/** /**

View File

@ -18,10 +18,9 @@ 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.convert.ConvertUtil;
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 java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
@ -239,7 +238,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(Convert.toStr(obj)); append(ConvertUtil.toStr(obj));
} }
return this; return this;
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.core.text.split; package org.dromara.hutool.core.text.split;
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.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.regex.PatternPool; import org.dromara.hutool.core.regex.PatternPool;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -54,7 +54,7 @@ public class SplitUtil {
* @return long数组 * @return long数组
*/ */
public static <T> T splitTo(final CharSequence str, final CharSequence separator, final Class<T> resultType) { public static <T> T splitTo(final CharSequence str, final CharSequence separator, final Class<T> resultType) {
return Convert.convert(resultType, splitTrim(str, separator)); return ConvertUtil.convert(resultType, splitTrim(str, separator));
} }
// endregion // endregion

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.util; package org.dromara.hutool.core.util;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.HutoolException; import org.dromara.hutool.core.exception.HutoolException;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
@ -52,7 +52,7 @@ public class JNDIUtil {
if (MapUtil.isEmpty(environment)) { if (MapUtil.isEmpty(environment)) {
return new InitialDirContext(); return new InitialDirContext();
} }
return new InitialDirContext(Convert.convert(Hashtable.class, environment)); return new InitialDirContext(ConvertUtil.convert(Hashtable.class, environment));
} catch (final NamingException e) { } catch (final NamingException e) {
throw new HutoolException(e); throw new HutoolException(e);
} }
@ -69,7 +69,7 @@ public class JNDIUtil {
if (MapUtil.isEmpty(environment)) { if (MapUtil.isEmpty(environment)) {
return new InitialContext(); return new InitialContext();
} }
return new InitialContext(Convert.convert(Hashtable.class, environment)); return new InitialContext(ConvertUtil.convert(Hashtable.class, environment));
} catch (final NamingException e) { } catch (final NamingException e) {
throw new HutoolException(e); throw new HutoolException(e);
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.core.util; package org.dromara.hutool.core.util;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.lang.Console;
import java.util.Properties; import java.util.Properties;
@ -134,7 +134,7 @@ public class SystemUtil {
* @return * @return
*/ */
public static int getInt(final String key, final int defaultValue) { public static int getInt(final String key, final int defaultValue) {
return Convert.toInt(get(key), defaultValue); return ConvertUtil.toInt(get(key), defaultValue);
} }
/** /**
@ -145,7 +145,7 @@ public class SystemUtil {
* @return * @return
*/ */
public static long getLong(final String key, final long defaultValue) { public static long getLong(final String key, final long defaultValue) {
return Convert.toLong(get(key), defaultValue); return ConvertUtil.toLong(get(key), defaultValue);
} }
/** /**

View File

@ -27,7 +27,7 @@ public class ConvertKBeanTest {
map.put("age", 18); map.put("age", 18);
map.put("id", "VampireAchao"); map.put("id", "VampireAchao");
final TestKBean testKBean = Convert.convert(TestKBean.class, map); final TestKBean testKBean = ConvertUtil.convert(TestKBean.class, map);
Assertions.assertEquals("VampireAchao", testKBean.getId()); Assertions.assertEquals("VampireAchao", testKBean.getId());
Assertions.assertEquals("中国", testKBean.getCountry()); Assertions.assertEquals("中国", testKBean.getCountry());

View File

@ -27,10 +27,10 @@ public class ConvertOtherTest {
@Test @Test
public void hexTest() { public void hexTest() {
final String a = "我是一个小小的可爱的字符串"; final String a = "我是一个小小的可爱的字符串";
final String hex = Convert.toHex(a, CharsetUtil.UTF_8); final String hex = ConvertUtil.toHex(a, CharsetUtil.UTF_8);
Assertions.assertEquals("e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2", hex); Assertions.assertEquals("e68891e698afe4b880e4b8aae5b08fe5b08fe79a84e58fafe788b1e79a84e5ad97e7aca6e4b8b2", hex);
final String raw = Convert.hexToStr(hex, CharsetUtil.UTF_8); final String raw = ConvertUtil.hexToStr(hex, CharsetUtil.UTF_8);
Assertions.assertEquals(a, raw); Assertions.assertEquals(a, raw);
} }
@ -38,18 +38,18 @@ public class ConvertOtherTest {
public void unicodeTest() { public void unicodeTest() {
final String a = "我是一个小小的可爱的字符串"; final String a = "我是一个小小的可爱的字符串";
final String unicode = Convert.strToUnicode(a); final String unicode = ConvertUtil.strToUnicode(a);
Assertions.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode); Assertions.assertEquals("\\u6211\\u662f\\u4e00\\u4e2a\\u5c0f\\u5c0f\\u7684\\u53ef\\u7231\\u7684\\u5b57\\u7b26\\u4e32", unicode);
final String raw = Convert.unicodeToStr(unicode); final String raw = ConvertUtil.unicodeToStr(unicode);
Assertions.assertEquals(raw, a); Assertions.assertEquals(raw, a);
// 针对有特殊空白符的Unicode // 针对有特殊空白符的Unicode
final String str = "你 好"; final String str = "你 好";
final String unicode2 = Convert.strToUnicode(str); final String unicode2 = ConvertUtil.strToUnicode(str);
Assertions.assertEquals("\\u4f60\\u00a0\\u597d", unicode2); Assertions.assertEquals("\\u4f60\\u00a0\\u597d", unicode2);
final String str2 = Convert.unicodeToStr(unicode2); final String str2 = ConvertUtil.unicodeToStr(unicode2);
Assertions.assertEquals(str, str2); Assertions.assertEquals(str, str2);
} }
@ -57,15 +57,15 @@ public class ConvertOtherTest {
public void convertCharsetTest() { public void convertCharsetTest() {
final String a = "我不是乱码"; final String a = "我不是乱码";
// 转换后result为乱码 // 转换后result为乱码
final String result = Convert.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1); final String result = ConvertUtil.convertCharset(a, CharsetUtil.NAME_UTF_8, CharsetUtil.NAME_ISO_8859_1);
final String raw = Convert.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8"); final String raw = ConvertUtil.convertCharset(result, CharsetUtil.NAME_ISO_8859_1, "UTF-8");
Assertions.assertEquals(raw, a); Assertions.assertEquals(raw, a);
} }
@Test @Test
public void convertTimeTest() { public void convertTimeTest() {
final long a = 4535345; final long a = 4535345;
final long minutes = Convert.convertTime(a, TimeUnit.MILLISECONDS, TimeUnit.MINUTES); final long minutes = ConvertUtil.convertTime(a, TimeUnit.MILLISECONDS, TimeUnit.MINUTES);
Assertions.assertEquals(75, minutes); Assertions.assertEquals(75, minutes);
} }
@ -73,12 +73,12 @@ public class ConvertOtherTest {
public void wrapUnwrapTest() { public void wrapUnwrapTest() {
// 去包装 // 去包装
final Class<?> wrapClass = Integer.class; final Class<?> wrapClass = Integer.class;
final Class<?> unWraped = Convert.unWrap(wrapClass); final Class<?> unWraped = ConvertUtil.unWrap(wrapClass);
Assertions.assertEquals(int.class, unWraped); Assertions.assertEquals(int.class, unWraped);
// 包装 // 包装
final Class<?> primitiveClass = long.class; final Class<?> primitiveClass = long.class;
final Class<?> wraped = Convert.wrap(primitiveClass); final Class<?> wraped = ConvertUtil.wrap(primitiveClass);
Assertions.assertEquals(Long.class, wraped); Assertions.assertEquals(Long.class, wraped);
} }
} }

View File

@ -52,7 +52,7 @@ public class ConvertTest {
@Test @Test
public void toObjectTest() { public void toObjectTest() {
final Object result = Convert.convert(Object.class, "aaaa"); final Object result = ConvertUtil.convert(Object.class, "aaaa");
assertEquals("aaaa", result); assertEquals("aaaa", result);
} }
@ -72,24 +72,24 @@ public class ConvertTest {
final int a = 1; final int a = 1;
final long[] b = { 1, 2, 3, 4, 5 }; final long[] b = { 1, 2, 3, 4, 5 };
assertEquals("[1, 2, 3, 4, 5]", Convert.convert(String.class, b)); assertEquals("[1, 2, 3, 4, 5]", ConvertUtil.convert(String.class, b));
final String aStr = Convert.toStr(a); final String aStr = ConvertUtil.toStr(a);
assertEquals("1", aStr); assertEquals("1", aStr);
final String bStr = Convert.toStr(b); final String bStr = ConvertUtil.toStr(b);
assertEquals("[1, 2, 3, 4, 5]", Convert.toStr(bStr)); assertEquals("[1, 2, 3, 4, 5]", ConvertUtil.toStr(bStr));
} }
@Test @Test
public void toStrTest2() { public void toStrTest2() {
final String result = Convert.convert(String.class, "aaaa"); final String result = ConvertUtil.convert(String.class, "aaaa");
assertEquals("aaaa", result); assertEquals("aaaa", result);
} }
@Test @Test
public void toStrTest3() { public void toStrTest3() {
final char a = 'a'; final char a = 'a';
final String result = Convert.convert(String.class, a); final String result = ConvertUtil.convert(String.class, a);
assertEquals("a", result); assertEquals("a", result);
} }
@ -97,7 +97,7 @@ public class ConvertTest {
public void toStrTest4() { public void toStrTest4() {
// 被当作八进制 // 被当作八进制
@SuppressWarnings("OctalInteger") @SuppressWarnings("OctalInteger")
final String result = Convert.toStr(001200); final String result = ConvertUtil.toStr(001200);
assertEquals("640", result); assertEquals("640", result);
} }
@ -106,47 +106,47 @@ public class ConvertTest {
// 被转化的对象有值正常转换 // 被转化的对象有值正常转换
final String a = "aaaa"; final String a = "aaaa";
final String aDefaultValue = "aDefault"; final String aDefaultValue = "aDefault";
final String aResult = Convert.toStr(a, aDefaultValue); final String aResult = ConvertUtil.toStr(a, aDefaultValue);
assertEquals(aResult, a); assertEquals(aResult, a);
// 被转化的对象为null返回默认值 // 被转化的对象为null返回默认值
final String b = null; final String b = null;
final String bDefaultValue = "bDefault"; final String bDefaultValue = "bDefault";
final String bResult = Convert.toStr(b, bDefaultValue); final String bResult = ConvertUtil.toStr(b, bDefaultValue);
assertEquals(bResult, bDefaultValue); assertEquals(bResult, bDefaultValue);
// 转换失败返回默认值 // 转换失败返回默认值
final TestExceptionClass c = new TestExceptionClass(); final TestExceptionClass c = new TestExceptionClass();
final String cDefaultValue = "cDefault"; final String cDefaultValue = "cDefault";
final String cResult = Convert.toStr(c, cDefaultValue); final String cResult = ConvertUtil.toStr(c, cDefaultValue);
assertEquals(cResult, cDefaultValue); assertEquals(cResult, cDefaultValue);
} }
@Test @Test
public void toIntTest() { public void toIntTest() {
final String a = " 34232"; final String a = " 34232";
final Integer aInteger = Convert.toInt(a); final Integer aInteger = ConvertUtil.toInt(a);
assertEquals(Integer.valueOf(34232), aInteger); assertEquals(Integer.valueOf(34232), aInteger);
final int aInt = (int) CompositeConverter.getInstance().convert(int.class, a); final int aInt = (int) CompositeConverter.getInstance().convert(int.class, a);
assertEquals(34232, aInt); assertEquals(34232, aInt);
// 带小数测试 // 带小数测试
final String b = " 34232.00"; final String b = " 34232.00";
final Integer bInteger = Convert.toInt(b); final Integer bInteger = ConvertUtil.toInt(b);
assertEquals(Integer.valueOf(34232), bInteger); assertEquals(Integer.valueOf(34232), bInteger);
final int bInt = (int) CompositeConverter.getInstance().convert(int.class, b); final int bInt = (int) CompositeConverter.getInstance().convert(int.class, b);
assertEquals(34232, bInt); assertEquals(34232, bInt);
// boolean测试 // boolean测试
final boolean c = true; final boolean c = true;
final Integer cInteger = Convert.toInt(c); final Integer cInteger = ConvertUtil.toInt(c);
assertEquals(Integer.valueOf(1), cInteger); assertEquals(Integer.valueOf(1), cInteger);
final int cInt = (int) CompositeConverter.getInstance().convert(int.class, c); final int cInt = (int) CompositeConverter.getInstance().convert(int.class, c);
assertEquals(1, cInt); assertEquals(1, cInt);
// boolean测试 // boolean测试
final String d = "08"; final String d = "08";
final Integer dInteger = Convert.toInt(d); final Integer dInteger = ConvertUtil.toInt(d);
assertEquals(Integer.valueOf(8), dInteger); assertEquals(Integer.valueOf(8), dInteger);
final int dInt = (int) CompositeConverter.getInstance().convert(int.class, d); final int dInt = (int) CompositeConverter.getInstance().convert(int.class, d);
assertEquals(8, dInt); assertEquals(8, dInt);
@ -155,14 +155,14 @@ public class ConvertTest {
@Test @Test
public void toIntTest2() { public void toIntTest2() {
final ArrayList<String> array = new ArrayList<>(); final ArrayList<String> array = new ArrayList<>();
final Integer aInt = Convert.convertQuietly(Integer.class, array, -1); final Integer aInt = ConvertUtil.convertQuietly(Integer.class, array, -1);
assertEquals(Integer.valueOf(-1), aInt); assertEquals(Integer.valueOf(-1), aInt);
} }
@Test @Test
public void toIntOfExceptionTest(){ public void toIntOfExceptionTest(){
Assertions.assertThrows(NumberFormatException.class, ()->{ Assertions.assertThrows(NumberFormatException.class, ()->{
final Integer d = Convert.convert(Integer.class, "d"); final Integer d = ConvertUtil.convert(Integer.class, "d");
Assertions.assertNotNull(d); Assertions.assertNotNull(d);
}); });
} }
@ -170,28 +170,28 @@ public class ConvertTest {
@Test @Test
public void toLongTest() { public void toLongTest() {
final String a = " 342324545435435"; final String a = " 342324545435435";
final Long aLong = Convert.toLong(a); final Long aLong = ConvertUtil.toLong(a);
assertEquals(Long.valueOf(342324545435435L), aLong); assertEquals(Long.valueOf(342324545435435L), aLong);
final long aLong2 = (long) CompositeConverter.getInstance().convert(long.class, a); final long aLong2 = (long) CompositeConverter.getInstance().convert(long.class, a);
assertEquals(342324545435435L, aLong2); assertEquals(342324545435435L, aLong2);
// 带小数测试 // 带小数测试
final String b = " 342324545435435.245435435"; final String b = " 342324545435435.245435435";
final Long bLong = Convert.toLong(b); final Long bLong = ConvertUtil.toLong(b);
assertEquals(Long.valueOf(342324545435435L), bLong); assertEquals(Long.valueOf(342324545435435L), bLong);
final long bLong2 = (long) CompositeConverter.getInstance().convert(long.class, b); final long bLong2 = (long) CompositeConverter.getInstance().convert(long.class, b);
assertEquals(342324545435435L, bLong2); assertEquals(342324545435435L, bLong2);
// boolean测试 // boolean测试
final boolean c = true; final boolean c = true;
final Long cLong = Convert.toLong(c); final Long cLong = ConvertUtil.toLong(c);
assertEquals(Long.valueOf(1), cLong); assertEquals(Long.valueOf(1), cLong);
final long cLong2 = (long) CompositeConverter.getInstance().convert(long.class, c); final long cLong2 = (long) CompositeConverter.getInstance().convert(long.class, c);
assertEquals(1, cLong2); assertEquals(1, cLong2);
// boolean测试 // boolean测试
final String d = "08"; final String d = "08";
final Long dLong = Convert.toLong(d); final Long dLong = ConvertUtil.toLong(d);
assertEquals(Long.valueOf(8), dLong); assertEquals(Long.valueOf(8), dLong);
final long dLong2 = (long) CompositeConverter.getInstance().convert(long.class, d); final long dLong2 = (long) CompositeConverter.getInstance().convert(long.class, d);
assertEquals(8, dLong2); assertEquals(8, dLong2);
@ -200,26 +200,26 @@ public class ConvertTest {
@Test @Test
public void toCharTest() { public void toCharTest() {
final String str = "aadfdsfs"; final String str = "aadfdsfs";
final Character c = Convert.toChar(str); final Character c = ConvertUtil.toChar(str);
assertEquals(Character.valueOf('a'), c); assertEquals(Character.valueOf('a'), c);
// 转换失败 // 转换失败
final Object str2 = ""; final Object str2 = "";
final Character c2 = Convert.toChar(str2); final Character c2 = ConvertUtil.toChar(str2);
Assertions.assertNull(c2); Assertions.assertNull(c2);
} }
@Test @Test
public void toNumberTest() { public void toNumberTest() {
final Object a = "12.45"; final Object a = "12.45";
final Number number = Convert.toNumber(a); final Number number = ConvertUtil.toNumber(a);
assertEquals(12.45D, number.doubleValue(), 0); assertEquals(12.45D, number.doubleValue(), 0);
} }
@Test @Test
public void emptyToNumberTest() { public void emptyToNumberTest() {
final Object a = ""; final Object a = "";
final Number number = Convert.toNumber(a); final Number number = ConvertUtil.toNumber(a);
Assertions.assertNull(number); Assertions.assertNull(number);
} }
@ -227,10 +227,10 @@ public class ConvertTest {
public void intAndByteConvertTest() { public void intAndByteConvertTest() {
// 测试 int byte // 测试 int byte
final int int0 = 234; final int int0 = 234;
final byte byte0 = Convert.intToByte(int0); final byte byte0 = ConvertUtil.intToByte(int0);
assertEquals(-22, byte0); assertEquals(-22, byte0);
final int int1 = Convert.byteToUnsignedInt(byte0); final int int1 = ConvertUtil.byteToUnsignedInt(byte0);
assertEquals(int0, int1); assertEquals(int0, int1);
} }
@ -238,10 +238,10 @@ public class ConvertTest {
public void intAndBytesTest() { public void intAndBytesTest() {
// 测试 int byte 数组 // 测试 int byte 数组
final int int2 = 1417; final int int2 = 1417;
final byte[] bytesInt = Convert.intToBytes(int2); final byte[] bytesInt = ConvertUtil.intToBytes(int2);
// 测试 byte 数组转 int // 测试 byte 数组转 int
final int int3 = Convert.bytesToInt(bytesInt); final int int3 = ConvertUtil.bytesToInt(bytesInt);
assertEquals(int2, int3); assertEquals(int2, int3);
} }
@ -250,8 +250,8 @@ public class ConvertTest {
// 测试 long byte 数组 // 测试 long byte 数组
final long long1 = 2223; final long long1 = 2223;
final byte[] bytesLong = Convert.longToBytes(long1); final byte[] bytesLong = ConvertUtil.longToBytes(long1);
final long long2 = Convert.bytesToLong(bytesLong); final long long2 = ConvertUtil.bytesToLong(bytesLong);
assertEquals(long1, long2); assertEquals(long1, long2);
} }
@ -259,8 +259,8 @@ public class ConvertTest {
@Test @Test
public void shortAndBytesTest() { public void shortAndBytesTest() {
final short short1 = 122; final short short1 = 122;
final byte[] bytes = Convert.shortToBytes(short1); final byte[] bytes = ConvertUtil.shortToBytes(short1);
final short short2 = Convert.bytesToShort(bytes); final short short2 = ConvertUtil.bytesToShort(bytes);
assertEquals(short2, short1); assertEquals(short2, short1);
} }
@ -268,12 +268,12 @@ public class ConvertTest {
@Test @Test
public void toListTest() { public void toListTest() {
final List<String> list = Arrays.asList("1", "2"); final List<String> list = Arrays.asList("1", "2");
final String str = Convert.toStr(list); final String str = ConvertUtil.toStr(list);
final List<String> list2 = Convert.toList(String.class, str); final List<String> list2 = ConvertUtil.toList(String.class, str);
assertEquals("1", list2.get(0)); assertEquals("1", list2.get(0));
assertEquals("2", list2.get(1)); assertEquals("2", list2.get(1));
final List<Integer> list3 = Convert.toList(Integer.class, str); final List<Integer> list3 = ConvertUtil.toList(Integer.class, str);
assertEquals(1, list3.get(0).intValue()); assertEquals(1, list3.get(0).intValue());
assertEquals(2, list3.get(1).intValue()); assertEquals(2, list3.get(1).intValue());
} }
@ -281,11 +281,11 @@ public class ConvertTest {
@Test @Test
public void toListTest2(){ public void toListTest2(){
final String str = "1,2"; final String str = "1,2";
final List<String> list2 = Convert.toList(String.class, str); final List<String> list2 = ConvertUtil.toList(String.class, str);
assertEquals("1", list2.get(0)); assertEquals("1", list2.get(0));
assertEquals("2", list2.get(1)); assertEquals("2", list2.get(1));
final List<Integer> list3 = Convert.toList(Integer.class, str); final List<Integer> list3 = ConvertUtil.toList(Integer.class, str);
assertEquals(1, list3.get(0).intValue()); assertEquals(1, list3.get(0).intValue());
assertEquals(2, list3.get(1).intValue()); assertEquals(2, list3.get(1).intValue());
} }
@ -293,10 +293,10 @@ public class ConvertTest {
@Test @Test
public void toByteArrayTest(){ public void toByteArrayTest(){
// 测试Serializable转换为bytes调用序列化转换 // 测试Serializable转换为bytes调用序列化转换
final byte[] bytes = Convert.toPrimitiveByteArray(new Product("zhangsan", "张三", "5.1.1")); final byte[] bytes = ConvertUtil.toPrimitiveByteArray(new Product("zhangsan", "张三", "5.1.1"));
Assertions.assertNotNull(bytes); Assertions.assertNotNull(bytes);
final Product product = Convert.convert(Product.class, bytes); final Product product = ConvertUtil.convert(Product.class, bytes);
assertEquals("zhangsan", product.getName()); assertEquals("zhangsan", product.getName());
assertEquals("张三", product.getCName()); assertEquals("张三", product.getCName());
assertEquals("5.1.1", product.getVersion()); assertEquals("5.1.1", product.getVersion());
@ -305,27 +305,27 @@ public class ConvertTest {
@Test @Test
public void numberToByteArrayTest(){ public void numberToByteArrayTest(){
// 测试Serializable转换为bytes调用序列化转换 // 测试Serializable转换为bytes调用序列化转换
final byte[] bytes = Convert.toPrimitiveByteArray(12L); final byte[] bytes = ConvertUtil.toPrimitiveByteArray(12L);
Assertions.assertArrayEquals(ByteUtil.toBytes(12L), bytes); Assertions.assertArrayEquals(ByteUtil.toBytes(12L), bytes);
} }
@Test @Test
public void toAtomicIntegerArrayTest(){ public void toAtomicIntegerArrayTest(){
final String str = "1,2"; final String str = "1,2";
final AtomicIntegerArray atomicIntegerArray = Convert.convert(AtomicIntegerArray.class, str); final AtomicIntegerArray atomicIntegerArray = ConvertUtil.convert(AtomicIntegerArray.class, str);
assertEquals("[1, 2]", atomicIntegerArray.toString()); assertEquals("[1, 2]", atomicIntegerArray.toString());
} }
@Test @Test
public void toAtomicLongArrayTest(){ public void toAtomicLongArrayTest(){
final String str = "1,2"; final String str = "1,2";
final AtomicLongArray atomicLongArray = Convert.convert(AtomicLongArray.class, str); final AtomicLongArray atomicLongArray = ConvertUtil.convert(AtomicLongArray.class, str);
assertEquals("[1, 2]", atomicLongArray.toString()); assertEquals("[1, 2]", atomicLongArray.toString());
} }
@Test @Test
public void toClassTest(){ public void toClassTest(){
final Class<?> convert = Convert.convert(Class.class, "org.dromara.hutool.core.convert.ConvertTest.Product"); final Class<?> convert = ConvertUtil.convert(Class.class, "org.dromara.hutool.core.convert.ConvertTest.Product");
Assertions.assertSame(Product.class, convert); Assertions.assertSame(Product.class, convert);
} }
@ -341,13 +341,13 @@ public class ConvertTest {
@Test @Test
public void enumToIntTest(){ public void enumToIntTest(){
final Integer integer = Convert.toInt(BuildingType.CUO); final Integer integer = ConvertUtil.toInt(BuildingType.CUO);
assertEquals(1, integer.intValue()); assertEquals(1, integer.intValue());
} }
@Test @Test
public void toSetTest(){ public void toSetTest(){
final Set<Integer> result = Convert.convert(new TypeReference<Set<Integer>>() { final Set<Integer> result = ConvertUtil.convert(new TypeReference<Set<Integer>>() {
}, "1,2,3"); }, "1,2,3");
assertEquals(SetUtil.of(1,2,3), result); assertEquals(SetUtil.of(1,2,3), result);
} }
@ -374,19 +374,19 @@ public class ConvertTest {
public void toDateTest(){ public void toDateTest(){
Assertions.assertThrows(DateException.class, ()->{ Assertions.assertThrows(DateException.class, ()->{
// 默认转换失败报错而不是返回null // 默认转换失败报错而不是返回null
Convert.convert(Date.class, "aaaa"); ConvertUtil.convert(Date.class, "aaaa");
}); });
} }
@Test @Test
public void toDateTest2(){ public void toDateTest2(){
final Date date = Convert.toDate("2021-01"); final Date date = ConvertUtil.toDate("2021-01");
assertEquals("2021-01-01", DateUtil.formatDate(date)); assertEquals("2021-01-01", DateUtil.formatDate(date));
} }
@Test @Test
public void toSqlDateTest(){ public void toSqlDateTest(){
final java.sql.Date date = Convert.convert(java.sql.Date.class, DateUtil.parse("2021-07-28")); final java.sql.Date date = ConvertUtil.convert(java.sql.Date.class, DateUtil.parse("2021-07-28"));
assertEquals("2021-07-28", date.toString()); assertEquals("2021-07-28", date.toString());
} }
@ -398,7 +398,7 @@ public class ConvertTest {
map.put("a3", "v3"); map.put("a3", "v3");
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Hashtable<String, String> hashtable = Convert.convert(Hashtable.class, map); final Hashtable<String, String> hashtable = ConvertUtil.convert(Hashtable.class, map);
assertEquals("v1", hashtable.get("a1")); assertEquals("v1", hashtable.get("a1"));
assertEquals("v2", hashtable.get("a2")); assertEquals("v2", hashtable.get("a2"));
assertEquals("v3", hashtable.get("a3")); assertEquals("v3", hashtable.get("a3"));
@ -408,10 +408,10 @@ public class ConvertTest {
public void toBigDecimalTest(){ public void toBigDecimalTest(){
// https://github.com/dromara/hutool/issues/1818 // https://github.com/dromara/hutool/issues/1818
final String str = "33020000210909112800000124"; final String str = "33020000210909112800000124";
final BigDecimal bigDecimal = Convert.toBigDecimal(str); final BigDecimal bigDecimal = ConvertUtil.toBigDecimal(str);
assertEquals(str, bigDecimal.toPlainString()); assertEquals(str, bigDecimal.toPlainString());
Assertions.assertNull(Convert.toBigDecimal(" ")); Assertions.assertNull(ConvertUtil.toBigDecimal(" "));
} }
@Test @Test
@ -419,63 +419,63 @@ public class ConvertTest {
// https://gitee.com/dromara/hutool/issues/I4M0E4 // https://gitee.com/dromara/hutool/issues/I4M0E4
final String hex2 = "CD0CCB43"; final String hex2 = "CD0CCB43";
final byte[] value = HexUtil.decode(hex2); final byte[] value = HexUtil.decode(hex2);
final float f = Convert.toFloat(value); final float f = ConvertUtil.toFloat(value);
assertEquals(406.1F, f, 0); assertEquals(406.1F, f, 0);
} }
@Test @Test
public void floatToDoubleTest(){ public void floatToDoubleTest(){
final float a = 0.45f; final float a = 0.45f;
final double b = Convert.toDouble(a); final double b = ConvertUtil.toDouble(a);
assertEquals(0.45D, b, 0); assertEquals(0.45D, b, 0);
} }
@Test @Test
public void floatToDoubleAddrTest(){ public void floatToDoubleAddrTest(){
final float a = 0.45f; final float a = 0.45f;
final DoubleAdder adder = Convert.convert(DoubleAdder.class, a); final DoubleAdder adder = ConvertUtil.convert(DoubleAdder.class, a);
assertEquals(0.45D, adder.doubleValue(), 0); assertEquals(0.45D, adder.doubleValue(), 0);
} }
@Test @Test
public void doubleToFloatTest(){ public void doubleToFloatTest(){
final double a = 0.45f; final double a = 0.45f;
final float b = Convert.toFloat(a); final float b = ConvertUtil.toFloat(a);
assertEquals(a, b, 0); assertEquals(a, b, 0);
} }
@Test @Test
public void localDateTimeToLocalDateTest(){ public void localDateTimeToLocalDateTest(){
final LocalDateTime localDateTime = LocalDateTime.now(); final LocalDateTime localDateTime = LocalDateTime.now();
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime); final LocalDate convert = ConvertUtil.convert(LocalDate.class, localDateTime);
assertEquals(localDateTime.toLocalDate(), convert); assertEquals(localDateTime.toLocalDate(), convert);
} }
@Test @Test
public void toSBCTest(){ public void toSBCTest(){
final String s = Convert.toSBC(null); final String s = ConvertUtil.toSBC(null);
Assertions.assertNull(s); Assertions.assertNull(s);
} }
@Test @Test
public void toDBCTest(){ public void toDBCTest(){
final String s = Convert.toDBC(null); final String s = ConvertUtil.toDBC(null);
Assertions.assertNull(s); Assertions.assertNull(s);
} }
@Test @Test
public void convertQuietlyTest(){ public void convertQuietlyTest(){
final String a = "12"; final String a = "12";
final Object s = Convert.convertQuietly(int.class, a, a); final Object s = ConvertUtil.convertQuietly(int.class, a, a);
assertEquals(12, s); assertEquals(12, s);
} }
@Test @Test
public void issue3662Test() { public void issue3662Test() {
String s = Convert.digitToChinese(0); String s = ConvertUtil.digitToChinese(0);
assertEquals("零元整", s); assertEquals("零元整", s);
s = Convert.digitToChinese(null); s = ConvertUtil.digitToChinese(null);
assertEquals("零元整", s); assertEquals("零元整", s);
} }
} }

View File

@ -36,14 +36,14 @@ public class ConvertToArrayTest {
public void toIntArrayTest() { public void toIntArrayTest() {
final String[] b = { "1", "2", "3", "4" }; final String[] b = { "1", "2", "3", "4" };
final Integer[] integerArray = Convert.toIntArray(b); final Integer[] integerArray = ConvertUtil.toIntArray(b);
Assertions.assertArrayEquals(integerArray, new Integer[]{1,2,3,4}); Assertions.assertArrayEquals(integerArray, new Integer[]{1,2,3,4});
final int[] intArray = Convert.convert(int[].class, b); final int[] intArray = ConvertUtil.convert(int[].class, b);
Assertions.assertArrayEquals(intArray, new int[]{1,2,3,4}); Assertions.assertArrayEquals(intArray, new int[]{1,2,3,4});
final long[] c = {1,2,3,4,5}; final long[] c = {1,2,3,4,5};
final Integer[] intArray2 = Convert.toIntArray(c); final Integer[] intArray2 = ConvertUtil.toIntArray(c);
Assertions.assertArrayEquals(intArray2, new Integer[]{1,2,3,4,5}); Assertions.assertArrayEquals(intArray2, new Integer[]{1,2,3,4,5});
} }
@ -60,14 +60,14 @@ public class ConvertToArrayTest {
public void toLongArrayTest() { public void toLongArrayTest() {
final String[] b = { "1", "2", "3", "4" }; final String[] b = { "1", "2", "3", "4" };
final Long[] longArray = Convert.toLongArray(b); final Long[] longArray = ConvertUtil.toLongArray(b);
Assertions.assertArrayEquals(longArray, new Long[]{1L,2L,3L,4L}); Assertions.assertArrayEquals(longArray, new Long[]{1L,2L,3L,4L});
final long[] longArray2 = Convert.convert(long[].class, b); final long[] longArray2 = ConvertUtil.convert(long[].class, b);
Assertions.assertArrayEquals(longArray2, new long[]{1L,2L,3L,4L}); Assertions.assertArrayEquals(longArray2, new long[]{1L,2L,3L,4L});
final int[] c = {1,2,3,4,5}; final int[] c = {1,2,3,4,5};
final Long[] intArray2 = Convert.toLongArray(c); final Long[] intArray2 = ConvertUtil.toLongArray(c);
Assertions.assertArrayEquals(intArray2, new Long[]{1L,2L,3L,4L,5L}); Assertions.assertArrayEquals(intArray2, new Long[]{1L,2L,3L,4L,5L});
} }
@ -75,14 +75,14 @@ public class ConvertToArrayTest {
public void toDoubleArrayTest() { public void toDoubleArrayTest() {
final String[] b = { "1", "2", "3", "4" }; final String[] b = { "1", "2", "3", "4" };
final Double[] doubleArray = Convert.toDoubleArray(b); final Double[] doubleArray = ConvertUtil.toDoubleArray(b);
Assertions.assertArrayEquals(doubleArray, new Double[]{1D,2D,3D,4D}); Assertions.assertArrayEquals(doubleArray, new Double[]{1D,2D,3D,4D});
final double[] doubleArray2 = Convert.convert(double[].class, b); final double[] doubleArray2 = ConvertUtil.convert(double[].class, b);
Assertions.assertArrayEquals(doubleArray2, new double[]{1D,2D,3D,4D}, 2); Assertions.assertArrayEquals(doubleArray2, new double[]{1D,2D,3D,4D}, 2);
final int[] c = {1,2,3,4,5}; final int[] c = {1,2,3,4,5};
final Double[] intArray2 = Convert.toDoubleArray(c); final Double[] intArray2 = ConvertUtil.toDoubleArray(c);
Assertions.assertArrayEquals(intArray2, new Double[]{1D,2D,3D,4D,5D}); Assertions.assertArrayEquals(intArray2, new Double[]{1D,2D,3D,4D,5D});
} }
@ -113,7 +113,7 @@ public class ConvertToArrayTest {
list.add("b"); list.add("b");
list.add("c"); list.add("c");
final String[] result = Convert.toStrArray(list); final String[] result = ConvertUtil.toStrArray(list);
Assertions.assertEquals(list.get(0), result[0]); Assertions.assertEquals(list.get(0), result[0]);
Assertions.assertEquals(list.get(1), result[1]); Assertions.assertEquals(list.get(1), result[1]);
Assertions.assertEquals(list.get(2), result[2]); Assertions.assertEquals(list.get(2), result[2]);
@ -122,7 +122,7 @@ public class ConvertToArrayTest {
@Test @Test
public void strToCharArrayTest() { public void strToCharArrayTest() {
final String testStr = "abcde"; final String testStr = "abcde";
final Character[] array = Convert.toCharArray(testStr); final Character[] array = ConvertUtil.toCharArray(testStr);
//包装类型数组 //包装类型数组
Assertions.assertEquals(new Character('a'), array[0]); Assertions.assertEquals(new Character('a'), array[0]);
@ -132,7 +132,7 @@ public class ConvertToArrayTest {
Assertions.assertEquals(new Character('e'), array[4]); Assertions.assertEquals(new Character('e'), array[4]);
//原始类型数组 //原始类型数组
final char[] array2 = Convert.convert(char[].class, testStr); final char[] array2 = ConvertUtil.convert(char[].class, testStr);
Assertions.assertEquals('a', array2[0]); Assertions.assertEquals('a', array2[0]);
Assertions.assertEquals('b', array2[1]); Assertions.assertEquals('b', array2[1]);
Assertions.assertEquals('c', array2[2]); Assertions.assertEquals('c', array2[2]);
@ -146,7 +146,7 @@ public class ConvertToArrayTest {
public void toUrlArrayTest() { public void toUrlArrayTest() {
final File[] files = FileUtil.file("D:\\workspace").listFiles(); final File[] files = FileUtil.file("D:\\workspace").listFiles();
final URL[] urls = Convert.convert(URL[].class, files); final URL[] urls = ConvertUtil.convert(URL[].class, files);
for (final URL url : urls) { for (final URL url : urls) {
Console.log(url.getPath()); Console.log(url.getPath());

View File

@ -39,7 +39,7 @@ public class ConvertToBeanTest {
person.setName("测试A11"); person.setName("测试A11");
person.setSubName("sub名字"); person.setSubName("sub名字");
final Map<?, ?> map = Convert.convert(Map.class, person); final Map<?, ?> map = ConvertUtil.convert(Map.class, person);
Assertions.assertEquals(map.get("name"), "测试A11"); Assertions.assertEquals(map.get("name"), "测试A11");
Assertions.assertEquals(map.get("age"), 14); Assertions.assertEquals(map.get("age"), 14);
Assertions.assertEquals("11213232", map.get("openid")); Assertions.assertEquals("11213232", map.get("openid"));
@ -53,12 +53,12 @@ public class ConvertToBeanTest {
person.setName("测试A11"); person.setName("测试A11");
person.setSubName("sub名字"); person.setSubName("sub名字");
final Map<String, String> map = Convert.toMap(String.class, String.class, person); final Map<String, String> map = ConvertUtil.toMap(String.class, String.class, person);
Assertions.assertEquals("测试A11", map.get("name")); Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals("14", map.get("age")); Assertions.assertEquals("14", map.get("age"));
Assertions.assertEquals("11213232", map.get("openid")); Assertions.assertEquals("11213232", map.get("openid"));
final LinkedHashMap<String, String> map2 = Convert.convert( final LinkedHashMap<String, String> map2 = ConvertUtil.convert(
new TypeReference<LinkedHashMap<String, String>>() {}, person); new TypeReference<LinkedHashMap<String, String>>() {}, person);
Assertions.assertEquals("测试A11", map2.get("name")); Assertions.assertEquals("测试A11", map2.get("name"));
Assertions.assertEquals("14", map2.get("age")); Assertions.assertEquals("14", map2.get("age"));
@ -73,7 +73,7 @@ public class ConvertToBeanTest {
map1.put("key3", 3); map1.put("key3", 3);
map1.put("key4", 4); map1.put("key4", 4);
final Map<String, String> map2 = Convert.toMap(String.class, String.class, map1); final Map<String, String> map2 = ConvertUtil.toMap(String.class, String.class, map1);
Assertions.assertEquals("1", map2.get("key1")); Assertions.assertEquals("1", map2.get("key1"));
Assertions.assertEquals("2", map2.get("key2")); Assertions.assertEquals("2", map2.get("key2"));
@ -90,7 +90,7 @@ public class ConvertToBeanTest {
map.put("name", "测试A11"); map.put("name", "测试A11");
map.put("subName", "sub名字"); map.put("subName", "sub名字");
final SubPerson subPerson = Convert.convert(SubPerson.class, map); final SubPerson subPerson = ConvertUtil.convert(SubPerson.class, map);
Assertions.assertEquals("88dc4b28-91b1-4a1a-bab5-444b795c7ecd", subPerson.getId().toString()); Assertions.assertEquals("88dc4b28-91b1-4a1a-bab5-444b795c7ecd", subPerson.getId().toString());
Assertions.assertEquals(14, subPerson.getAge()); Assertions.assertEquals(14, subPerson.getAge());
Assertions.assertEquals("11213232", subPerson.getOpenid()); Assertions.assertEquals("11213232", subPerson.getOpenid());
@ -101,7 +101,7 @@ public class ConvertToBeanTest {
@Test @Test
public void nullStrToBeanTest(){ public void nullStrToBeanTest(){
final String nullStr = "null"; final String nullStr = "null";
final SubPerson subPerson = Convert.convertQuietly(SubPerson.class, nullStr); final SubPerson subPerson = ConvertUtil.convertQuietly(SubPerson.class, nullStr);
Assertions.assertNull(subPerson); Assertions.assertNull(subPerson);
} }
@ -112,7 +112,7 @@ public class ConvertToBeanTest {
caseInsensitiveMap.put("Jerry", 2); caseInsensitiveMap.put("Jerry", 2);
caseInsensitiveMap.put("tom", 3); caseInsensitiveMap.put("tom", 3);
Map<String, String> map = Convert.toMap(String.class, String.class, caseInsensitiveMap); Map<String, String> map = ConvertUtil.toMap(String.class, String.class, caseInsensitiveMap);
Assertions.assertEquals("2", map.get("jerry")); Assertions.assertEquals("2", map.get("jerry"));
Assertions.assertEquals("2", map.get("Jerry")); Assertions.assertEquals("2", map.get("Jerry"));
Assertions.assertEquals("3", map.get("tom")); Assertions.assertEquals("3", map.get("tom"));
@ -125,7 +125,7 @@ public class ConvertToBeanTest {
person.setName("测试A11"); person.setName("测试A11");
person.setSubName("sub名字"); person.setSubName("sub名字");
Map<String, String> map = Convert.toMap(LinkedHashMap.class, String.class, String.class, person); Map<String, String> map = ConvertUtil.toMap(LinkedHashMap.class, String.class, String.class, person);
Assertions.assertEquals("测试A11", map.get("name")); Assertions.assertEquals("测试A11", map.get("name"));
Assertions.assertEquals("14", map.get("age")); Assertions.assertEquals("14", map.get("age"));
Assertions.assertEquals("11213232", map.get("openid")); Assertions.assertEquals("11213232", map.get("openid"));

View File

@ -20,17 +20,17 @@ public class ConvertToBooleanTest {
@Test @Test
public void intToBooleanTest() { public void intToBooleanTest() {
final int a = 100; final int a = 100;
final Boolean aBoolean = Convert.toBoolean(a); final Boolean aBoolean = ConvertUtil.toBoolean(a);
Assertions.assertTrue(aBoolean); Assertions.assertTrue(aBoolean);
final int b = 0; final int b = 0;
final Boolean bBoolean = Convert.toBoolean(b); final Boolean bBoolean = ConvertUtil.toBoolean(b);
Assertions.assertFalse(bBoolean); Assertions.assertFalse(bBoolean);
} }
@Test @Test
public void issueI65P8ATest() { public void issueI65P8ATest() {
final Boolean bool = Convert.toBoolean("", Boolean.TRUE); final Boolean bool = ConvertUtil.toBoolean("", Boolean.TRUE);
Assertions.assertFalse(bool); Assertions.assertFalse(bool);
} }

View File

@ -35,7 +35,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toCollectionTest() { public void toCollectionTest() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<?> list = (List<?>) Convert.convert(Collection.class, a); final List<?> list = (List<?>) ConvertUtil.convert(Collection.class, a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -46,7 +46,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toListTest() { public void toListTest() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<?> list = Convert.toList(a); final List<?> list = ConvertUtil.toList(a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -57,7 +57,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toListTest2() { public void toListTest2() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.toList(String.class, a); final List<String> list = ConvertUtil.toList(String.class, a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -68,7 +68,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toListTest3() { public void toListTest3() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.toList(String.class, a); final List<String> list = ConvertUtil.toList(String.class, a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -79,7 +79,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toListTest4() { public void toListTest4() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<String> list = Convert.convert(new TypeReference<List<String>>() {}, a); final List<String> list = ConvertUtil.convert(new TypeReference<List<String>>() {}, a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -90,7 +90,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void strToListTest() { public void strToListTest() {
final String a = "a,你,好,123"; final String a = "a,你,好,123";
final List<?> list = Convert.toList(a); final List<?> list = ConvertUtil.toList(a);
Assertions.assertEquals(4, list.size()); Assertions.assertEquals(4, list.size());
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
@ -98,7 +98,7 @@ public class ConvertToCollectionTest {
Assertions.assertEquals("123", list.get(3)); Assertions.assertEquals("123", list.get(3));
final String b = "a"; final String b = "a";
final List<?> list2 = Convert.toList(b); final List<?> list2 = ConvertUtil.toList(b);
Assertions.assertEquals(1, list2.size()); Assertions.assertEquals(1, list2.size());
Assertions.assertEquals("a", list2.get(0)); Assertions.assertEquals("a", list2.get(0));
} }
@ -106,7 +106,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void strToListTest2() { public void strToListTest2() {
final String a = "a,你,好,123"; final String a = "a,你,好,123";
final List<String> list = Convert.toList(String.class, a); final List<String> list = ConvertUtil.toList(String.class, a);
Assertions.assertEquals(4, list.size()); Assertions.assertEquals(4, list.size());
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
@ -117,18 +117,18 @@ public class ConvertToCollectionTest {
@Test @Test
public void numberToListTest() { public void numberToListTest() {
final Integer i = 1; final Integer i = 1;
final ArrayList<?> list = Convert.convert(ArrayList.class, i); final ArrayList<?> list = ConvertUtil.convert(ArrayList.class, i);
Assertions.assertSame(i, list.get(0)); Assertions.assertSame(i, list.get(0));
final BigDecimal b = BigDecimal.ONE; final BigDecimal b = BigDecimal.ONE;
final ArrayList<?> list2 = Convert.convert(ArrayList.class, b); final ArrayList<?> list2 = ConvertUtil.convert(ArrayList.class, b);
Assertions.assertEquals(b, list2.get(0)); Assertions.assertEquals(b, list2.get(0));
} }
@Test @Test
public void toLinkedListTest() { public void toLinkedListTest() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final List<?> list = Convert.convert(LinkedList.class, a); final List<?> list = ConvertUtil.convert(LinkedList.class, a);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));
Assertions.assertEquals("", list.get(2)); Assertions.assertEquals("", list.get(2));
@ -139,7 +139,7 @@ public class ConvertToCollectionTest {
@Test @Test
public void toSetTest() { public void toSetTest() {
final Object[] a = { "a", "", "", "", 1 }; final Object[] a = { "a", "", "", "", 1 };
final LinkedHashSet<?> set = Convert.convert(LinkedHashSet.class, a); final LinkedHashSet<?> set = ConvertUtil.convert(LinkedHashSet.class, a);
final ArrayList<?> list = ListUtil.of(set); final ArrayList<?> list = ListUtil.of(set);
Assertions.assertEquals("a", list.get(0)); Assertions.assertEquals("a", list.get(0));
Assertions.assertEquals("", list.get(1)); Assertions.assertEquals("", list.get(1));

View File

@ -24,7 +24,7 @@ public class ConvertToNumberTest {
@Test @Test
public void dateToLongTest(){ public void dateToLongTest(){
final Date date = DateUtil.parse("2020-05-17 12:32:00"); final Date date = DateUtil.parse("2020-05-17 12:32:00");
final Long dateLong = Convert.toLong(date); final Long dateLong = ConvertUtil.toLong(date);
assert date != null; assert date != null;
Assertions.assertEquals(date.getTime(), dateLong.longValue()); Assertions.assertEquals(date.getTime(), dateLong.longValue());
} }
@ -32,7 +32,7 @@ public class ConvertToNumberTest {
@Test @Test
public void dateToIntTest(){ public void dateToIntTest(){
final Date date = DateUtil.parse("2020-05-17 12:32:00"); final Date date = DateUtil.parse("2020-05-17 12:32:00");
final Integer dateInt = Convert.toInt(date); final Integer dateInt = ConvertUtil.toInt(date);
assert date != null; assert date != null;
Assertions.assertEquals((int)date.getTime(), dateInt.intValue()); Assertions.assertEquals((int)date.getTime(), dateInt.intValue());
} }
@ -40,24 +40,24 @@ public class ConvertToNumberTest {
@Test @Test
public void dateToAtomicLongTest(){ public void dateToAtomicLongTest(){
final Date date = DateUtil.parse("2020-05-17 12:32:00"); final Date date = DateUtil.parse("2020-05-17 12:32:00");
final AtomicLong dateLong = Convert.convert(AtomicLong.class, date); final AtomicLong dateLong = ConvertUtil.convert(AtomicLong.class, date);
assert date != null; assert date != null;
Assertions.assertEquals(date.getTime(), dateLong.longValue()); Assertions.assertEquals(date.getTime(), dateLong.longValue());
} }
@Test @Test
public void toBigDecimalTest(){ public void toBigDecimalTest(){
BigDecimal bigDecimal = Convert.toBigDecimal("1.1f"); BigDecimal bigDecimal = ConvertUtil.toBigDecimal("1.1f");
Assertions.assertEquals(1.1f, bigDecimal.floatValue(), 0); Assertions.assertEquals(1.1f, bigDecimal.floatValue(), 0);
bigDecimal = Convert.toBigDecimal("1L"); bigDecimal = ConvertUtil.toBigDecimal("1L");
Assertions.assertEquals(1L, bigDecimal.longValue()); Assertions.assertEquals(1L, bigDecimal.longValue());
} }
@Test @Test
public void toNumberTest(){ public void toNumberTest(){
// 直接转换为抽象Number默认使用BigDecimal实现 // 直接转换为抽象Number默认使用BigDecimal实现
final Number number = Convert.toNumber("1"); final Number number = ConvertUtil.toNumber("1");
Assertions.assertEquals(BigDecimal.class, number.getClass()); Assertions.assertEquals(BigDecimal.class, number.getClass());
} }
} }

View File

@ -27,14 +27,14 @@ public class ConvertToSBCAndDBCTest {
@Test @Test
public void toSBCTest() { public void toSBCTest() {
final String a = "123456789"; final String a = "123456789";
final String sbc = Convert.toSBC(a); final String sbc = ConvertUtil.toSBC(a);
Assertions.assertEquals("", sbc); Assertions.assertEquals("", sbc);
} }
@Test @Test
public void toDBCTest() { public void toDBCTest() {
final String a = ""; final String a = "";
final String dbc = Convert.toDBC(a); final String dbc = ConvertUtil.toDBC(a);
Assertions.assertEquals("123456789", dbc); Assertions.assertEquals("123456789", dbc);
} }
} }

View File

@ -26,22 +26,22 @@ public class DateConvertTest {
@Test @Test
public void toDateTest() { public void toDateTest() {
final String a = "2017-05-06"; final String a = "2017-05-06";
final Date value = Convert.toDate(a); final Date value = ConvertUtil.toDate(a);
Assertions.assertEquals(a, DateUtil.formatDate(value)); Assertions.assertEquals(a, DateUtil.formatDate(value));
final long timeLong = DateUtil.now().getTime(); final long timeLong = DateUtil.now().getTime();
final Date value2 = Convert.toDate(timeLong); final Date value2 = ConvertUtil.toDate(timeLong);
Assertions.assertEquals(timeLong, value2.getTime()); Assertions.assertEquals(timeLong, value2.getTime());
} }
@Test @Test
public void toDateFromIntTest() { public void toDateFromIntTest() {
final int dateLong = -1497600000; final int dateLong = -1497600000;
final Date value = Convert.toDate(dateLong); final Date value = ConvertUtil.toDate(dateLong);
Assertions.assertNotNull(value); Assertions.assertNotNull(value);
Assertions.assertEquals("Mon Dec 15 00:00:00 CST 1969", value.toString().replace("GMT+08:00", "CST")); Assertions.assertEquals("Mon Dec 15 00:00:00 CST 1969", value.toString().replace("GMT+08:00", "CST"));
final java.sql.Date sqlDate = Convert.convert(java.sql.Date.class, dateLong); final java.sql.Date sqlDate = ConvertUtil.convert(java.sql.Date.class, dateLong);
Assertions.assertNotNull(sqlDate); Assertions.assertNotNull(sqlDate);
Assertions.assertEquals("1969-12-15", sqlDate.toString()); Assertions.assertEquals("1969-12-15", sqlDate.toString());
} }
@ -49,7 +49,7 @@ public class DateConvertTest {
@Test @Test
public void toDateFromLocalDateTimeTest() { public void toDateFromLocalDateTimeTest() {
final LocalDateTime localDateTime = LocalDateTime.parse("2017-05-06T08:30:00", DateTimeFormatter.ISO_DATE_TIME); final LocalDateTime localDateTime = LocalDateTime.parse("2017-05-06T08:30:00", DateTimeFormatter.ISO_DATE_TIME);
final Date value = Convert.toDate(localDateTime); final Date value = ConvertUtil.toDate(localDateTime);
Assertions.assertNotNull(value); Assertions.assertNotNull(value);
Assertions.assertEquals("2017-05-06", DateUtil.formatDate(value)); Assertions.assertEquals("2017-05-06", DateUtil.formatDate(value));
} }
@ -57,11 +57,11 @@ public class DateConvertTest {
@Test @Test
public void toSqlDateTest() { public void toSqlDateTest() {
final String a = "2017-05-06"; final String a = "2017-05-06";
final java.sql.Date value = Convert.convert(java.sql.Date.class, a); final java.sql.Date value = ConvertUtil.convert(java.sql.Date.class, a);
Assertions.assertEquals("2017-05-06", value.toString()); Assertions.assertEquals("2017-05-06", value.toString());
final long timeLong = DateUtil.now().getTime(); final long timeLong = DateUtil.now().getTime();
final java.sql.Date value2 = Convert.convert(java.sql.Date.class, timeLong); final java.sql.Date value2 = ConvertUtil.convert(java.sql.Date.class, timeLong);
Assertions.assertEquals(timeLong, value2.getTime()); Assertions.assertEquals(timeLong, value2.getTime());
} }
@ -69,15 +69,15 @@ public class DateConvertTest {
public void toLocalDateTimeTest() { public void toLocalDateTimeTest() {
final Date src = new Date(); final Date src = new Date();
LocalDateTime ldt = Convert.toLocalDateTime(src); LocalDateTime ldt = ConvertUtil.toLocalDateTime(src);
Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src)); Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src));
final Timestamp ts = Timestamp.from(src.toInstant()); final Timestamp ts = Timestamp.from(src.toInstant());
ldt = Convert.toLocalDateTime(ts); ldt = ConvertUtil.toLocalDateTime(ts);
Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src)); Assertions.assertEquals(ldt, DateUtil.toLocalDateTime(src));
final String str = "2020-12-12 12:12:12.0"; final String str = "2020-12-12 12:12:12.0";
ldt = Convert.toLocalDateTime(str); ldt = ConvertUtil.toLocalDateTime(str);
Assertions.assertEquals(ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")), str); Assertions.assertEquals(ldt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")), str);
} }
} }

View File

@ -22,19 +22,19 @@ public class EnumConvertTest {
@Test @Test
public void convertTest(){ public void convertTest(){
TestEnum bbb = Convert.convert(TestEnum.class, "BBB"); TestEnum bbb = ConvertUtil.convert(TestEnum.class, "BBB");
Assertions.assertEquals(TestEnum.B, bbb); Assertions.assertEquals(TestEnum.B, bbb);
bbb = Convert.convert(TestEnum.class, 22); bbb = ConvertUtil.convert(TestEnum.class, 22);
Assertions.assertEquals(TestEnum.B, bbb); Assertions.assertEquals(TestEnum.B, bbb);
} }
@Test @Test
public void toEnumTest(){ public void toEnumTest(){
TestEnum ccc = Convert.toEnum(TestEnum.class, "CCC"); TestEnum ccc = ConvertUtil.toEnum(TestEnum.class, "CCC");
Assertions.assertEquals(TestEnum.C, ccc); Assertions.assertEquals(TestEnum.C, ccc);
ccc = Convert.toEnum(TestEnum.class, 33); ccc = ConvertUtil.toEnum(TestEnum.class, 33);
Assertions.assertEquals(TestEnum.C, ccc); Assertions.assertEquals(TestEnum.C, ccc);
} }

View File

@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
public class Issue3105Test { public class Issue3105Test {
@Test @Test
void toLongTest() { void toLongTest() {
final Long aLong = Convert.toLong("0.a"); final Long aLong = ConvertUtil.toLong("0.a");
Assertions.assertEquals(0L, aLong); Assertions.assertEquals(0L, aLong);
} }
} }

View File

@ -22,7 +22,7 @@ public class IssueI7WJHHTest {
@Test @Test
public void toIntTest() { public void toIntTest() {
final Optional<Integer> optional = Optional.of(1); final Optional<Integer> optional = Optional.of(1);
final Integer integer = Convert.toInt(optional); final Integer integer = ConvertUtil.toInt(optional);
Assertions.assertEquals(Integer.valueOf(1), integer); Assertions.assertEquals(Integer.valueOf(1), integer);
} }
@ -30,7 +30,7 @@ public class IssueI7WJHHTest {
@Test @Test
public void toIntTest2() { public void toIntTest2() {
final Opt<Integer> optional = Opt.of(1); final Opt<Integer> optional = Opt.of(1);
final Integer integer = Convert.toInt(optional); final Integer integer = ConvertUtil.toInt(optional);
Assertions.assertEquals(Integer.valueOf(1), integer); Assertions.assertEquals(Integer.valueOf(1), integer);
} }

View File

@ -34,7 +34,7 @@ public class MapConvertTest {
user.setName("AAA"); user.setName("AAA");
user.setAge(45); user.setAge(45);
final HashMap<?, ?> map = Convert.convert(HashMap.class, user); final HashMap<?, ?> map = ConvertUtil.convert(HashMap.class, user);
Assertions.assertEquals("AAA", map.get("name")); Assertions.assertEquals("AAA", map.get("name"));
Assertions.assertEquals(45, map.get("age")); Assertions.assertEquals(45, map.get("age"));
} }
@ -46,7 +46,7 @@ public class MapConvertTest {
.put("name", "AAA") .put("name", "AAA")
.put("age", 45).map(); .put("age", 45).map();
final LinkedHashMap<?, ?> map = Convert.convert(LinkedHashMap.class, srcMap); final LinkedHashMap<?, ?> map = ConvertUtil.convert(LinkedHashMap.class, srcMap);
Assertions.assertEquals("AAA", map.get("name")); Assertions.assertEquals("AAA", map.get("name"));
Assertions.assertEquals(45, map.get("age")); Assertions.assertEquals(45, map.get("age"));
} }

View File

@ -20,14 +20,14 @@ public class PrimitiveConvertTest {
@Test @Test
public void toIntTest(){ public void toIntTest(){
final int convert = Convert.convert(int.class, "123"); final int convert = ConvertUtil.convert(int.class, "123");
Assertions.assertEquals(123, convert); Assertions.assertEquals(123, convert);
} }
@Test @Test
public void toIntErrorTest(){ public void toIntErrorTest(){
Assertions.assertThrows(IllegalArgumentException.class, ()->{ Assertions.assertThrows(IllegalArgumentException.class, ()->{
Convert.convert(int.class, "aaaa"); ConvertUtil.convert(int.class, "aaaa");
}); });
} }

View File

@ -21,7 +21,7 @@ public class StringConvertTest {
@Test @Test
public void timezoneToStrTest(){ public void timezoneToStrTest(){
final String s = Convert.toStr(TimeZone.getTimeZone("Asia/Shanghai")); final String s = ConvertUtil.toStr(TimeZone.getTimeZone("Asia/Shanghai"));
Assertions.assertEquals("Asia/Shanghai", s); Assertions.assertEquals("Asia/Shanghai", s);
} }
} }

View File

@ -32,44 +32,44 @@ public class TemporalAccessorConverterTest {
final String dateStr = "2019-02-18"; final String dateStr = "2019-02-18";
// 通过转换获取的Instant为UTC时间 // 通过转换获取的Instant为UTC时间
final Instant instant = Convert.convert(Instant.class, dateStr); final Instant instant = ConvertUtil.convert(Instant.class, dateStr);
final Instant instant1 = Objects.requireNonNull(DateUtil.parse(dateStr)).toInstant(); final Instant instant1 = Objects.requireNonNull(DateUtil.parse(dateStr)).toInstant();
Assertions.assertEquals(instant1, instant); Assertions.assertEquals(instant1, instant);
} }
@Test @Test
public void toLocalDateTimeTest(){ public void toLocalDateTimeTest(){
final LocalDateTime localDateTime = Convert.convert(LocalDateTime.class, "2019-02-18"); final LocalDateTime localDateTime = ConvertUtil.convert(LocalDateTime.class, "2019-02-18");
Assertions.assertEquals("2019-02-18T00:00", localDateTime.toString()); Assertions.assertEquals("2019-02-18T00:00", localDateTime.toString());
} }
@Test @Test
public void toLocalDateTest(){ public void toLocalDateTest(){
final LocalDate localDate = Convert.convert(LocalDate.class, "2019-02-18"); final LocalDate localDate = ConvertUtil.convert(LocalDate.class, "2019-02-18");
Assertions.assertEquals("2019-02-18", localDate.toString()); Assertions.assertEquals("2019-02-18", localDate.toString());
} }
@Test @Test
public void toLocalTimeTest(){ public void toLocalTimeTest(){
final LocalTime localTime = Convert.convert(LocalTime.class, "2019-02-18"); final LocalTime localTime = ConvertUtil.convert(LocalTime.class, "2019-02-18");
Assertions.assertEquals("00:00", localTime.toString()); Assertions.assertEquals("00:00", localTime.toString());
} }
@Test @Test
public void toZonedDateTimeTest(){ public void toZonedDateTimeTest(){
final ZonedDateTime zonedDateTime = Convert.convert(ZonedDateTime.class, "2019-02-18"); final ZonedDateTime zonedDateTime = ConvertUtil.convert(ZonedDateTime.class, "2019-02-18");
Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString().substring(0, 22)); Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString().substring(0, 22));
} }
@Test @Test
public void toOffsetDateTimeTest(){ public void toOffsetDateTimeTest(){
final OffsetDateTime zonedDateTime = Convert.convert(OffsetDateTime.class, "2019-02-18"); final OffsetDateTime zonedDateTime = ConvertUtil.convert(OffsetDateTime.class, "2019-02-18");
Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString()); Assertions.assertEquals("2019-02-18T00:00+08:00", zonedDateTime.toString());
} }
@Test @Test
public void toOffsetTimeTest(){ public void toOffsetTimeTest(){
final OffsetTime offsetTime = Convert.convert(OffsetTime.class, "2019-02-18"); final OffsetTime offsetTime = ConvertUtil.convert(OffsetTime.class, "2019-02-18");
Assertions.assertEquals("00:00+08:00", offsetTime.toString()); Assertions.assertEquals("00:00+08:00", offsetTime.toString());
} }
} }

View File

@ -22,7 +22,7 @@ public class XMLGregorianCalendarConverterTest {
@Test @Test
public void convertTest(){ public void convertTest(){
final XMLGregorianCalendar calendar = Convert.convert(XMLGregorianCalendar.class, DateUtil.parse("2022-01-03 04:00:00")); final XMLGregorianCalendar calendar = ConvertUtil.convert(XMLGregorianCalendar.class, DateUtil.parse("2022-01-03 04:00:00"));
Assertions.assertNotNull(calendar); Assertions.assertNotNull(calendar);
} }
} }

View File

@ -12,7 +12,7 @@
package org.dromara.hutool.core.exception; package org.dromara.hutool.core.exception;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -50,12 +50,12 @@ public class ExceptionUtilTest {
@Test @Test
public void bytesIntConvertTest(){ public void bytesIntConvertTest(){
final String s = Convert.toStr(12); final String s = ConvertUtil.toStr(12);
final int integer = Convert.toInt(s); final int integer = ConvertUtil.toInt(s);
Assertions.assertEquals(12, integer); Assertions.assertEquals(12, integer);
final byte[] bytes = Convert.intToBytes(12); final byte[] bytes = ConvertUtil.intToBytes(12);
final int i = Convert.bytesToInt(bytes); final int i = ConvertUtil.bytesToInt(bytes);
Assertions.assertEquals(12, i); Assertions.assertEquals(12, i);
} }
} }

View File

@ -12,7 +12,7 @@
package org.dromara.hutool.core.map; package org.dromara.hutool.core.map;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Opt; import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import lombok.Builder; import lombok.Builder;
@ -60,7 +60,7 @@ public class MapUtilTest {
map.put("c", "3"); map.put("c", "3");
map.put("d", "4"); map.put("d", "4");
final Map<String, String> map2 = MapUtil.filter(map, t -> Convert.toInt(t.getValue()) % 2 == 0); final Map<String, String> map2 = MapUtil.filter(map, t -> ConvertUtil.toInt(t.getValue()) % 2 == 0);
Assertions.assertEquals(2, map2.size()); Assertions.assertEquals(2, map2.size());
@ -119,7 +119,7 @@ public class MapUtilTest {
final Map<String, String> camelCaseMap = MapUtil.toCamelCaseMap(map); final Map<String, String> camelCaseMap = MapUtil.toCamelCaseMap(map);
final Map<String, String> map2 = MapUtil.filter(camelCaseMap, t -> Convert.toInt(t.getValue()) % 2 == 0); final Map<String, String> map2 = MapUtil.filter(camelCaseMap, t -> ConvertUtil.toInt(t.getValue()) % 2 == 0);
Assertions.assertEquals(2, map2.size()); Assertions.assertEquals(2, map2.size());

View File

@ -12,7 +12,7 @@
package org.dromara.hutool.core.math; package org.dromara.hutool.core.math;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -220,50 +220,50 @@ public class ChineseNumberFormatterTest {
@Test @Test
public void digitToChineseTest() { public void digitToChineseTest() {
String digitToChinese = Convert.digitToChinese(12_4124_1241_2421.12); String digitToChinese = ConvertUtil.digitToChinese(12_4124_1241_2421.12);
Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元壹角贰分", digitToChinese); Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元壹角贰分", digitToChinese);
digitToChinese = Convert.digitToChinese(12_0000_1241_2421L); digitToChinese = ConvertUtil.digitToChinese(12_0000_1241_2421L);
Assertions.assertEquals("壹拾贰万亿零壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese); Assertions.assertEquals("壹拾贰万亿零壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(12_0000_0000_2421L); digitToChinese = ConvertUtil.digitToChinese(12_0000_0000_2421L);
Assertions.assertEquals("壹拾贰万亿零贰仟肆佰贰拾壹元整", digitToChinese); Assertions.assertEquals("壹拾贰万亿零贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(12_4124_1241_2421D); digitToChinese = ConvertUtil.digitToChinese(12_4124_1241_2421D);
Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese); Assertions.assertEquals("壹拾贰万肆仟壹佰贰拾肆亿壹仟贰佰肆拾壹万贰仟肆佰贰拾壹元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2421.02); digitToChinese = ConvertUtil.digitToChinese(2421.02);
Assertions.assertEquals("贰仟肆佰贰拾壹元零贰分", digitToChinese); Assertions.assertEquals("贰仟肆佰贰拾壹元零贰分", digitToChinese);
} }
@Test @Test
public void digitToChineseTest2() { public void digitToChineseTest2() {
double a = 67556.32; double a = 67556.32;
String digitUppercase = Convert.digitToChinese(a); String digitUppercase = ConvertUtil.digitToChinese(a);
Assertions.assertEquals("陆万柒仟伍佰伍拾陆元叁角贰分", digitUppercase); Assertions.assertEquals("陆万柒仟伍佰伍拾陆元叁角贰分", digitUppercase);
a = 1024.00; a = 1024.00;
digitUppercase = Convert.digitToChinese(a); digitUppercase = ConvertUtil.digitToChinese(a);
Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase); Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase);
final double b = 1024; final double b = 1024;
digitUppercase = Convert.digitToChinese(b); digitUppercase = ConvertUtil.digitToChinese(b);
Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase); Assertions.assertEquals("壹仟零贰拾肆元整", digitUppercase);
} }
@Test @Test
public void digitToChineseTest3() { public void digitToChineseTest3() {
String digitToChinese = Convert.digitToChinese(2_0000_0000.00); String digitToChinese = ConvertUtil.digitToChinese(2_0000_0000.00);
Assertions.assertEquals("贰亿元整", digitToChinese); Assertions.assertEquals("贰亿元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2_0000.00); digitToChinese = ConvertUtil.digitToChinese(2_0000.00);
Assertions.assertEquals("贰万元整", digitToChinese); Assertions.assertEquals("贰万元整", digitToChinese);
digitToChinese = Convert.digitToChinese(2_0000_0000_0000.00); digitToChinese = ConvertUtil.digitToChinese(2_0000_0000_0000.00);
Assertions.assertEquals("贰万亿元整", digitToChinese); Assertions.assertEquals("贰万亿元整", digitToChinese);
} }
@Test @Test
public void digitToChineseTest4() { public void digitToChineseTest4() {
final String digitToChinese = Convert.digitToChinese(400_0000.00); final String digitToChinese = ConvertUtil.digitToChinese(400_0000.00);
Assertions.assertEquals("肆佰万元整", digitToChinese); Assertions.assertEquals("肆佰万元整", digitToChinese);
} }

View File

@ -15,8 +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.convert.ConvertUtil;
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;
@ -224,8 +223,8 @@ public class ObjUtilTest {
@Test @Test
public void toStringTest() { public void toStringTest() {
Assertions.assertEquals("null", Convert.toStrOrNullStr(null)); Assertions.assertEquals("null", ConvertUtil.toStrOrNullStr(null));
Assertions.assertEquals(Collections.emptyMap().toString(), Convert.toStrOrNullStr(Collections.emptyMap())); Assertions.assertEquals(Collections.emptyMap().toString(), ConvertUtil.toStrOrNullStr(Collections.emptyMap()));
Assertions.assertEquals("[1, 2]", Arrays.asList("1", "2").toString()); Assertions.assertEquals("[1, 2]", Arrays.asList("1", "2").toString());
} }

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.core.util; package org.dromara.hutool.core.util;
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.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.math.NumberUtil; import org.dromara.hutool.core.math.NumberUtil;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -95,7 +95,7 @@ public class RandomUtilTest {
public void generateRandomNumberTest(){ public void generateRandomNumberTest(){
final int[] ints = RandomUtil.randomPickInts(5, NumberUtil.range(5, 20)); final int[] ints = RandomUtil.randomPickInts(5, NumberUtil.range(5, 20));
Assertions.assertEquals(5, ints.length); Assertions.assertEquals(5, ints.length);
final Set<?> set = Convert.convert(Set.class, ints); final Set<?> set = ConvertUtil.convert(Set.class, ints);
Assertions.assertEquals(5, set.size()); Assertions.assertEquals(5, set.size());
} }
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.db.config; package org.dromara.hutool.db.config;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.resource.NoResourceException; import org.dromara.hutool.core.io.resource.NoResourceException;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -148,7 +148,7 @@ public class SettingConfigParser implements ConfigParser {
// 大小写等配置 // 大小写等配置
final String caseInsensitive = setting.getAndRemove(DSKeys.KEY_CASE_INSENSITIVE); final String caseInsensitive = setting.getAndRemove(DSKeys.KEY_CASE_INSENSITIVE);
if (StrUtil.isNotBlank(caseInsensitive)) { if (StrUtil.isNotBlank(caseInsensitive)) {
dbConfig.setCaseInsensitive(Convert.toBoolean(caseInsensitive)); dbConfig.setCaseInsensitive(ConvertUtil.toBoolean(caseInsensitive));
} }
// remarks等连接配置since 5.3.8 // remarks等连接配置since 5.3.8
@ -183,18 +183,18 @@ public class SettingConfigParser implements ConfigParser {
*/ */
private static SqlLogFilter getSqlLogFilter(final Setting setting) { private static SqlLogFilter getSqlLogFilter(final Setting setting) {
// 初始化SQL显示 // 初始化SQL显示
final boolean isShowSql = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false); final boolean isShowSql = ConvertUtil.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false);
if (!isShowSql) { if (!isShowSql) {
return null; return null;
} }
final boolean isFormatSql = Convert.toBoolean(setting.remove(DSKeys.KEY_FORMAT_SQL), false); final boolean isFormatSql = ConvertUtil.toBoolean(setting.remove(DSKeys.KEY_FORMAT_SQL), false);
final boolean isShowParams = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_PARAMS), false); final boolean isShowParams = ConvertUtil.toBoolean(setting.remove(DSKeys.KEY_SHOW_PARAMS), false);
String sqlLevelStr = setting.remove(DSKeys.KEY_SQL_LEVEL); String sqlLevelStr = setting.remove(DSKeys.KEY_SQL_LEVEL);
if (null != sqlLevelStr) { if (null != sqlLevelStr) {
sqlLevelStr = sqlLevelStr.toUpperCase(); sqlLevelStr = sqlLevelStr.toUpperCase();
} }
final Level level = Convert.toEnum(Level.class, sqlLevelStr, Level.DEBUG); final Level level = ConvertUtil.toEnum(Level.class, sqlLevelStr, Level.DEBUG);
final SqlLog sqlLog = new SqlLog(); final SqlLog sqlLog = new SqlLog();
sqlLog.init(isShowSql, isFormatSql, isShowParams, level); sqlLog.init(isShowSql, isFormatSql, isShowParams, level);

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.db.handler; package org.dromara.hutool.db.handler;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; 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.db.DbException; import org.dromara.hutool.db.DbException;
@ -59,7 +59,7 @@ public class ResultSetUtil {
} else if (Iterable.class.isAssignableFrom(beanClass)) { } else if (Iterable.class.isAssignableFrom(beanClass)) {
//集合 //集合
final Object[] objRow = toBean(meta, rs, Object[].class); final Object[] objRow = toBean(meta, rs, Object[].class);
return Convert.convert(beanClass, objRow); return ConvertUtil.convert(beanClass, objRow);
} else if (beanClass.isAssignableFrom(Entity.class)) { } else if (beanClass.isAssignableFrom(Entity.class)) {
//Entity的父类都可按照Entity返回 //Entity的父类都可按照Entity返回
return (T) new EntityRowHandler(meta, false, true).handle(rs); return (T) new EntityRowHandler(meta, false, true).handle(rs);
@ -191,7 +191,7 @@ public class ResultSetUtil {
return rawValue; return rawValue;
} else { } else {
// 按照返回值要求转换 // 按照返回值要求转换
return Convert.convert(targetColumnType, rawValue); return ConvertUtil.convert(targetColumnType, rawValue);
} }
} }
} }

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.db.meta; package org.dromara.hutool.db.meta;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.wrapper.SimpleWrapper; import org.dromara.hutool.core.lang.wrapper.SimpleWrapper;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil; import org.dromara.hutool.core.util.ObjUtil;
@ -123,7 +123,7 @@ public class DatabaseMetaDataWrapper extends SimpleWrapper<DatabaseMetaData> {
*/ */
public List<String> getTableNames(final String tableNamePattern, final TableType... types) { public List<String> getTableNames(final String tableNamePattern, final TableType... types) {
List<String> result = null; List<String> result = null;
try (final ResultSet rs = this.raw.getTables(catalog, schema, tableNamePattern, Convert.toStrArray(types))) { try (final ResultSet rs = this.raw.getTables(catalog, schema, tableNamePattern, ConvertUtil.toStrArray(types))) {
if (null != rs) { if (null != rs) {
// 初始化结果列表大小为ResultSet的获取大小 // 初始化结果列表大小为ResultSet的获取大小
result = new ArrayList<>(rs.getFetchSize()); result = new ArrayList<>(rs.getFetchSize());

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.db.sql; package org.dromara.hutool.db.sql;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.exception.CloneException; import org.dromara.hutool.core.exception.CloneException;
import org.dromara.hutool.core.math.NumberUtil; import org.dromara.hutool.core.math.NumberUtil;
import org.dromara.hutool.core.text.CharUtil; import org.dromara.hutool.core.text.CharUtil;
@ -456,7 +456,7 @@ public class Condition implements Cloneable, Serializable {
} else if (value instanceof CharSequence) { } else if (value instanceof CharSequence) {
valuesForIn = SplitUtil.split((CharSequence) value, StrUtil.COMMA); valuesForIn = SplitUtil.split((CharSequence) value, StrUtil.COMMA);
} else { } else {
valuesForIn = Arrays.asList(Convert.convert(Object[].class, value)); valuesForIn = Arrays.asList(ConvertUtil.convert(Object[].class, value));
} }
conditionStrBuilder.append(StrUtil.repeatAndJoin("?", valuesForIn.size(), StrUtil.COMMA)); conditionStrBuilder.append(StrUtil.repeatAndJoin("?", valuesForIn.size(), StrUtil.COMMA));
if (null != paramValues) { if (null != paramValues) {

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.db.sql;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.collection.ListUtil; import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.collection.iter.ArrayIter; import org.dromara.hutool.core.collection.iter.ArrayIter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.builder.Builder; import org.dromara.hutool.core.lang.builder.Builder;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
@ -219,7 +219,7 @@ public class StatementBuilder implements Builder<StatementWrapper> {
if (ArrayUtil.isNotEmpty(params) && 1 == params.length && params[0] instanceof Map) { if (ArrayUtil.isNotEmpty(params) && 1 == params.length && params[0] instanceof Map) {
// 检查参数是否为命名方式的参数 // 检查参数是否为命名方式的参数
final NamedSql namedSql = new NamedSql(sql, Convert.toMap(String.class, Object.class, params[0])); final NamedSql namedSql = new NamedSql(sql, ConvertUtil.toMap(String.class, Object.class, params[0]));
sql = namedSql.getSql(); sql = namedSql.getSql();
params = namedSql.getParamArray(); params = namedSql.getParamArray();
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.management; package org.dromara.hutool.extra.management;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Singleton; import org.dromara.hutool.core.lang.Singleton;
import org.dromara.hutool.core.util.ObjUtil; import org.dromara.hutool.core.util.ObjUtil;
@ -462,6 +462,6 @@ public class ManagementUtil {
* @param value * @param value
*/ */
protected static void append(final StringBuilder builder, final String caption, final Object value) { protected static void append(final StringBuilder builder, final String caption, final Object value) {
builder.append(caption).append(ObjUtil.defaultIfNull(Convert.toStr(value), "[n/a]")).append("\n"); builder.append(caption).append(ObjUtil.defaultIfNull(ConvertUtil.toStr(value), "[n/a]")).append("\n");
} }
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.jetbrick; package org.dromara.hutool.extra.template.engine.jetbrick;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.dromara.hutool.extra.template.Template; import org.dromara.hutool.extra.template.Template;
import jetbrick.template.JetTemplate; import jetbrick.template.JetTemplate;
@ -59,13 +59,13 @@ public class JetbrickTemplate implements Template, Serializable{
@Override @Override
public void render(final Map<?, ?> bindingMap, final Writer writer) { public void render(final Map<?, ?> bindingMap, final Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
rawTemplate.render(map, writer); rawTemplate.render(map, writer);
} }
@Override @Override
public void render(final Map<?, ?> bindingMap, final OutputStream out) { public void render(final Map<?, ?> bindingMap, final OutputStream out) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
rawTemplate.render(map, out); rawTemplate.render(map, out);
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.pebble; package org.dromara.hutool.extra.template.engine.pebble;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.dromara.hutool.extra.template.Template; import org.dromara.hutool.extra.template.Template;
import org.dromara.hutool.extra.template.TemplateException; import org.dromara.hutool.extra.template.TemplateException;
@ -64,7 +64,7 @@ public class PebbleTemplate implements Template {
@Override @Override
public void render(final Map<?, ?> bindingMap, final Writer writer) { public void render(final Map<?, ?> bindingMap, final Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() { final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {
}, bindingMap); }, bindingMap);
try { try {
this.template.evaluate(writer, map); this.template.evaluate(writer, map);
@ -82,7 +82,7 @@ public class PebbleTemplate implements Template {
@Override @Override
public void render(final Map<?, ?> bindingMap, final OutputStream out) { public void render(final Map<?, ?> bindingMap, final OutputStream out) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() { final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {
}, bindingMap); }, bindingMap);
try { try {
this.template.evaluate(new OutputStreamWriter(out), map); this.template.evaluate(new OutputStreamWriter(out), map);

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.rythm; package org.dromara.hutool.extra.template.engine.rythm;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.dromara.hutool.extra.template.Template; import org.dromara.hutool.extra.template.Template;
@ -57,7 +57,7 @@ public class RythmTemplate implements Template, Serializable {
@Override @Override
public void render(final Map<?, ?> bindingMap, final Writer writer) { public void render(final Map<?, ?> bindingMap, final Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
rawTemplate.__setRenderArgs(map); rawTemplate.__setRenderArgs(map);
rawTemplate.render(writer); rawTemplate.render(writer);
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.thymeleaf; package org.dromara.hutool.extra.template.engine.thymeleaf;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.dromara.hutool.core.util.CharsetUtil; import org.dromara.hutool.core.util.CharsetUtil;
@ -72,7 +72,7 @@ public class ThymeleafTemplate implements Template, Serializable {
@Override @Override
public void render(final Map<?, ?> bindingMap, final Writer writer) { public void render(final Map<?, ?> bindingMap, final Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
final Context context = new Context(Locale.getDefault(), map); final Context context = new Context(Locale.getDefault(), map);
this.engine.process(this.template, context, writer); this.engine.process(this.template, context, writer);
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.velocity; package org.dromara.hutool.extra.template.engine.velocity;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
@ -82,7 +82,7 @@ public class VelocityTemplate implements Template, Serializable {
* @return {@link VelocityContext} * @return {@link VelocityContext}
*/ */
private VelocityContext toContext(final Map<?, ?> bindingMap) { private VelocityContext toContext(final Map<?, ?> bindingMap) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
return new VelocityContext(map); return new VelocityContext(map);
} }

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.extra.template.engine.wit; package org.dromara.hutool.extra.template.engine.wit;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import org.febit.wit.Template; import org.febit.wit.Template;
@ -56,13 +56,13 @@ public class WitTemplate implements org.dromara.hutool.extra.template.Template,
@Override @Override
public void render(final Map<?, ?> bindingMap, final Writer writer) { public void render(final Map<?, ?> bindingMap, final Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
rawTemplate.merge(map, writer); rawTemplate.merge(map, writer);
} }
@Override @Override
public void render(final Map<?, ?> bindingMap, final OutputStream out) { public void render(final Map<?, ?> bindingMap, final OutputStream out) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap); final Map<String, Object> map = ConvertUtil.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
rawTemplate.merge(map, out); rawTemplate.merge(map, out);
} }

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.extra.spring.cglib; package org.dromara.hutool.extra.spring.cglib;
import lombok.Data; import lombok.Data;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.EnabledForJreRange;
@ -41,7 +41,7 @@ public class CglibUtilTest {
otherBean = new OtherSampleBean(); otherBean = new OtherSampleBean();
//自定义转换器 //自定义转换器
CglibUtil.copy(bean, otherBean, (value, target, context) -> Convert.convertQuietly(target, value)); CglibUtil.copy(bean, otherBean, (value, target, context) -> ConvertUtil.convertQuietly(target, value));
Assertions.assertEquals("Hello world", otherBean.getValue()); Assertions.assertEquals("Hello world", otherBean.getValue());
Assertions.assertEquals(123, otherBean.getValue2()); Assertions.assertEquals(123, otherBean.getValue2());
} }

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.http.client;
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.convert.ConvertUtil;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.http.HttpUtil; import org.dromara.hutool.http.HttpUtil;
@ -191,7 +191,7 @@ public interface HeaderOperation<T extends HeaderOperation<T>> {
* @since 5.7.9 * @since 5.7.9
*/ */
default long contentLength() { default long contentLength() {
long contentLength = Convert.toLong(header(HeaderName.CONTENT_LENGTH), -1L); long contentLength = ConvertUtil.toLong(header(HeaderName.CONTENT_LENGTH), -1L);
if (contentLength > 0 && (isChunked() || StrUtil.isNotBlank(contentEncoding()))) { if (contentLength > 0 && (isChunked() || StrUtil.isNotBlank(contentEncoding()))) {
//按照HTTP协议规范 Transfer-Encoding和Content-Encoding设置后 Content-Length 无效 //按照HTTP协议规范 Transfer-Encoding和Content-Encoding设置后 Content-Length 无效
contentLength = -1; contentLength = -1;

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.http.client; package org.dromara.hutool.http.client;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.http.HttpException; import org.dromara.hutool.http.HttpException;
@ -172,7 +172,7 @@ public interface Response extends Closeable {
* @since 5.7.9 * @since 5.7.9
*/ */
default long contentLength() { default long contentLength() {
long contentLength = Convert.toLong(header(HeaderName.CONTENT_LENGTH), -1L); long contentLength = ConvertUtil.toLong(header(HeaderName.CONTENT_LENGTH), -1L);
if (contentLength > 0 && (isChunked() || StrUtil.isNotBlank(contentEncoding()))) { if (contentLength > 0 && (isChunked() || StrUtil.isNotBlank(contentEncoding()))) {
//按照HTTP协议规范 Transfer-Encoding和Content-Encoding设置后 Content-Length 无效 //按照HTTP协议规范 Transfer-Encoding和Content-Encoding设置后 Content-Length 无效
contentLength = -1; contentLength = -1;

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.http.client.body; package org.dromara.hutool.http.client.body;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.resource.FileResource; import org.dromara.hutool.core.io.resource.FileResource;
import org.dromara.hutool.core.io.resource.MultiFileResource; import org.dromara.hutool.core.io.resource.MultiFileResource;
import org.dromara.hutool.core.map.MapUtil; import org.dromara.hutool.core.map.MapUtil;
@ -120,7 +120,7 @@ public abstract class FormBody<T extends FormBody<T>> implements HttpBody {
strValue = ArrayUtil.join(value, ","); strValue = ArrayUtil.join(value, ",");
} else { } else {
// 其他对象一律转换为字符串 // 其他对象一律转换为字符串
strValue = Convert.toStr(value, null); strValue = ConvertUtil.toStr(value, null);
} }
return putToForm(name, strValue); return putToForm(name, strValue);

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.http.client.body; package org.dromara.hutool.http.client.body;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.file.FileUtil;
@ -123,7 +123,7 @@ public class MultipartOutputStream extends OutputStream {
appendResource(formFieldName, new InputStreamResource((Reader) value, this.charset)); appendResource(formFieldName, new InputStreamResource((Reader) value, this.charset));
} else { } else {
appendResource(formFieldName, appendResource(formFieldName,
new StringResource(Convert.toStr(value), null, this.charset)); new StringResource(ConvertUtil.toStr(value), null, this.charset));
} }
write(StrUtil.CRLF); write(StrUtil.CRLF);

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.json;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.bean.copier.CopyOptions; import org.dromara.hutool.core.bean.copier.CopyOptions;
import org.dromara.hutool.core.codec.binary.HexUtil; import org.dromara.hutool.core.codec.binary.HexUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.lang.mutable.MutableEntry; import org.dromara.hutool.core.lang.mutable.MutableEntry;
import org.dromara.hutool.core.map.CaseInsensitiveLinkedMap; import org.dromara.hutool.core.map.CaseInsensitiveLinkedMap;
@ -148,7 +148,7 @@ public final class InternalJSONUtil {
* @param predicate 属性过滤器{@link Predicate#test(Object)}{@code true}保留 * @param predicate 属性过滤器{@link Predicate#test(Object)}{@code true}保留
*/ */
public static void propertyPut(final JSONObject jsonObject, final Object key, final Object value, final Predicate<MutableEntry<String, Object>> predicate) { public static void propertyPut(final JSONObject jsonObject, final Object key, final Object value, final Predicate<MutableEntry<String, Object>> predicate) {
final String[] path = SplitUtil.splitToArray(Convert.toStr(key), StrUtil.DOT); final String[] path = SplitUtil.splitToArray(ConvertUtil.toStr(key), StrUtil.DOT);
final int last = path.length - 1; final int last = path.length - 1;
JSONObject target = jsonObject; JSONObject target = jsonObject;
for (int i = 0; i < last; i += 1) { for (int i = 0; i < last; i += 1) {

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.json; package org.dromara.hutool.json;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.impl.ArrayConverter; import org.dromara.hutool.core.convert.impl.ArrayConverter;
import org.dromara.hutool.core.lang.Validator; import org.dromara.hutool.core.lang.Validator;
import org.dromara.hutool.core.lang.mutable.Mutable; import org.dromara.hutool.core.lang.mutable.Mutable;
@ -520,7 +520,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
* @since 3.0.8 * @since 3.0.8
*/ */
public <T> List<T> toList(final Class<T> elementType) { public <T> List<T> toList(final Class<T> elementType) {
return Convert.toList(elementType, this); return ConvertUtil.toList(elementType, this);
} }
/** /**

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.json; package org.dromara.hutool.json;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
@ -397,7 +397,7 @@ public class JSONUtil {
} }
//issue#I7CW27其他类型使用默认转换 //issue#I7CW27其他类型使用默认转换
return Convert.convert(type, json); return ConvertUtil.convert(type, json);
} }
// -------------------------------------------------------------------- toBean end // -------------------------------------------------------------------- toBean end

View File

@ -20,7 +20,7 @@ import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.bean.RecordUtil; import org.dromara.hutool.core.bean.RecordUtil;
import org.dromara.hutool.core.bean.copier.BeanCopier; import org.dromara.hutool.core.bean.copier.BeanCopier;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.convert.ConvertException; import org.dromara.hutool.core.convert.ConvertException;
import org.dromara.hutool.core.convert.Converter; import org.dromara.hutool.core.convert.Converter;
import org.dromara.hutool.core.convert.RegisterConverter; import org.dromara.hutool.core.convert.RegisterConverter;
@ -121,7 +121,7 @@ public class JSONConverter implements Converter, Serializable {
} }
} }
return Convert.convertWithCheck(targetType, value, null, config.isIgnoreError()); return ConvertUtil.convertWithCheck(targetType, value, null, config.isIgnoreError());
} }
/** /**

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.json.mapper;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.bean.RecordUtil; import org.dromara.hutool.core.bean.RecordUtil;
import org.dromara.hutool.core.bean.copier.CopyOptions; import org.dromara.hutool.core.bean.copier.CopyOptions;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.lang.mutable.MutableEntry; import org.dromara.hutool.core.lang.mutable.MutableEntry;
import org.dromara.hutool.core.reflect.method.MethodUtil; import org.dromara.hutool.core.reflect.method.MethodUtil;
@ -114,11 +114,11 @@ public class JSONObjectMapper {
} else if (source instanceof Map) { } else if (source instanceof Map) {
// Map // Map
for (final Map.Entry<?, ?> e : ((Map<?, ?>) source).entrySet()) { for (final Map.Entry<?, ?> e : ((Map<?, ?>) source).entrySet()) {
jsonObject.set(Convert.toStr(e.getKey()), e.getValue(), predicate, false); jsonObject.set(ConvertUtil.toStr(e.getKey()), e.getValue(), predicate, false);
} }
} else if (source instanceof Map.Entry) { } else if (source instanceof Map.Entry) {
final Map.Entry entry = (Map.Entry) source; final Map.Entry entry = (Map.Entry) source;
jsonObject.set(Convert.toStr(entry.getKey()), entry.getValue(), predicate, false); jsonObject.set(ConvertUtil.toStr(entry.getKey()), entry.getValue(), predicate, false);
} else if (source instanceof CharSequence) { } else if (source instanceof CharSequence) {
// 可能为JSON字符串 // 可能为JSON字符串
mapFromStr((CharSequence) source, jsonObject); mapFromStr((CharSequence) source, jsonObject);

View File

@ -16,7 +16,7 @@
package org.dromara.hutool.json.serialize; package org.dromara.hutool.json.serialize;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.date.DateUtil; import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.date.TemporalAccessorUtil; import org.dromara.hutool.core.date.TemporalAccessorUtil;
import org.dromara.hutool.core.date.format.GlobalCustomFormat; import org.dromara.hutool.core.date.format.GlobalCustomFormat;
@ -86,7 +86,7 @@ public class DateJSONString implements JSONStringer {
if (dateObj instanceof TemporalAccessor) { if (dateObj instanceof TemporalAccessor) {
dateStr = TemporalAccessorUtil.format((TemporalAccessor) dateObj, format); dateStr = TemporalAccessorUtil.format((TemporalAccessor) dateObj, format);
} else { } else {
dateStr = DateUtil.format(Convert.toDate(dateObj), format); dateStr = DateUtil.format(ConvertUtil.toDate(dateObj), format);
} }
if (GlobalCustomFormat.FORMAT_SECONDS.equals(format) if (GlobalCustomFormat.FORMAT_SECONDS.equals(format)

View File

@ -13,7 +13,7 @@
package org.dromara.hutool.json; package org.dromara.hutool.json;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.reflect.TypeReference; import org.dromara.hutool.core.reflect.TypeReference;
import lombok.Data; import lombok.Data;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -31,7 +31,7 @@ public class Issue1101Test {
public void treeMapConvertTest(){ public void treeMapConvertTest(){
final String json = "[{\"nodeName\":\"admin\",\"treeNodeId\":\"00010001_52c95b83-2083-4138-99fb-e6e21f0c1277\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"52c95b83-2083-4138-99fb-e6e21f0c1277\",\"status\":true},{\"nodeName\":\"test\",\"treeNodeId\":\"00010001_97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"status\":true}]"; final String json = "[{\"nodeName\":\"admin\",\"treeNodeId\":\"00010001_52c95b83-2083-4138-99fb-e6e21f0c1277\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"52c95b83-2083-4138-99fb-e6e21f0c1277\",\"status\":true},{\"nodeName\":\"test\",\"treeNodeId\":\"00010001_97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"sort\":0,\"type\":10,\"parentId\":\"00010001\",\"children\":[],\"id\":\"97054a82-f8ff-46a1-b76c-cbacf6d18045\",\"status\":true}]";
final JSONArray objects = JSONUtil.parseArray(json); final JSONArray objects = JSONUtil.parseArray(json);
final TreeSet<TreeNodeDto> convert = Convert.convert(new TypeReference<TreeSet<TreeNodeDto>>() { final TreeSet<TreeNodeDto> convert = ConvertUtil.convert(new TypeReference<TreeSet<TreeNodeDto>>() {
}, objects); }, objects);
Assertions.assertEquals(2, convert.size()); Assertions.assertEquals(2, convert.size());
} }

View File

@ -12,7 +12,7 @@
package org.dromara.hutool.json; package org.dromara.hutool.json;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -82,7 +82,7 @@ public class IssueI49VZBTest {
@Test @Test
public void enumConvertTest(){ public void enumConvertTest(){
final NBCloudKeyType type = Convert.toEnum(NBCloudKeyType.class, "snapKey"); final NBCloudKeyType type = ConvertUtil.toEnum(NBCloudKeyType.class, "snapKey");
Assertions.assertEquals(NBCloudKeyType.snapKey, type); Assertions.assertEquals(NBCloudKeyType.snapKey, type);
} }
} }

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.poi.csv;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.iter.ArrayIter; import org.dromara.hutool.core.collection.iter.ArrayIter;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.io.IORuntimeException; import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.file.FileUtil;
@ -228,7 +228,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
public CsvWriter write(final Iterable<?> lines) throws IORuntimeException { public CsvWriter write(final Iterable<?> lines) throws IORuntimeException {
if (CollUtil.isNotEmpty(lines)) { if (CollUtil.isNotEmpty(lines)) {
for (final Object values : lines) { for (final Object values : lines) {
appendLine(Convert.toStrArray(values)); appendLine(ConvertUtil.toStrArray(values));
} }
flush(); flush();
} }
@ -286,7 +286,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
writeHeaderLine(map.keySet().toArray(new String[0])); writeHeaderLine(map.keySet().toArray(new String[0]));
isFirst = false; isFirst = false;
} }
writeLine(Convert.toStrArray(map.values())); writeLine(ConvertUtil.toStrArray(map.values()));
} }
flush(); flush();
} }

View File

@ -17,7 +17,6 @@
package org.dromara.hutool.poi.excel.reader.sheet; package org.dromara.hutool.poi.excel.reader.sheet;
import org.dromara.hutool.core.collection.CollUtil; import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.convert.Convert;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.dromara.hutool.poi.excel.RowUtil; import org.dromara.hutool.poi.excel.RowUtil;
import org.dromara.hutool.poi.excel.cell.editors.CellEditor; import org.dromara.hutool.poi.excel.cell.editors.CellEditor;

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.poi.excel.sax.handler;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.collection.iter.IterUtil; import org.dromara.hutool.core.collection.iter.IterUtil;
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.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import java.util.List; import java.util.List;
@ -61,7 +61,7 @@ public abstract class BeanRowHandler<T> extends AbstractRowHandler<T> {
@Override @Override
public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) { public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) {
if (rowIndex == this.headerRowIndex) { if (rowIndex == this.headerRowIndex) {
this.headerList = ListUtil.view(Convert.toList(String.class, rowCells)); this.headerList = ListUtil.view(ConvertUtil.toList(String.class, rowCells));
return; return;
} }
super.handle(sheetIndex, rowIndex, rowCells); super.handle(sheetIndex, rowIndex, rowCells);

View File

@ -18,7 +18,7 @@ package org.dromara.hutool.poi.excel.sax.handler;
import org.dromara.hutool.core.collection.iter.IterUtil; import org.dromara.hutool.core.collection.iter.IterUtil;
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.convert.ConvertUtil;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -57,7 +57,7 @@ public abstract class MapRowHandler extends AbstractRowHandler<Map<String, Objec
@Override @Override
public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) { public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) {
if (rowIndex == this.headerRowIndex) { if (rowIndex == this.headerRowIndex) {
this.headerList = ListUtil.view(Convert.toList(String.class, rowCells)); this.headerList = ListUtil.view(ConvertUtil.toList(String.class, rowCells));
return; return;
} }
super.handle(sheetIndex, rowIndex, rowCells); super.handle(sheetIndex, rowIndex, rowCells);

View File

@ -19,7 +19,7 @@ package org.dromara.hutool.poi.word;
import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.collection.ListUtil; import org.dromara.hutool.core.collection.ListUtil;
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.convert.ConvertUtil;
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.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -147,7 +147,7 @@ public class TableUtil {
int index = 0; int index = 0;
for (final Object cellData : rowData) { for (final Object cellData : rowData) {
cell = getOrCreateCell(row, index); cell = getOrCreateCell(row, index);
cell.setText(Convert.toStr(cellData)); cell.setText(ConvertUtil.toStr(cellData));
index++; index++;
} }
} }

View File

@ -14,7 +14,7 @@ package org.dromara.hutool.poi.excel.reader;
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.convert.ConvertUtil;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.io.file.FileUtil; import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.lang.Console; import org.dromara.hutool.core.lang.Console;
@ -93,7 +93,7 @@ public class ExcelSaxReadTest {
@Disabled @Disabled
public void readBlankLineTest() { public void readBlankLineTest() {
ExcelUtil.readBySax("e:/ExcelBlankLine.xlsx", 0, (sheetIndex, rowIndex, rowList) -> { ExcelUtil.readBySax("e:/ExcelBlankLine.xlsx", 0, (sheetIndex, rowIndex, rowList) -> {
if (StrUtil.isAllEmpty(Convert.toStrArray(rowList))) { if (StrUtil.isAllEmpty(ConvertUtil.toStrArray(rowList))) {
return; return;
} }
Console.log(rowList); Console.log(rowList);

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.setting; package org.dromara.hutool.setting;
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.convert.ConvertUtil;
import org.dromara.hutool.core.func.LambdaUtil; import org.dromara.hutool.core.func.LambdaUtil;
import org.dromara.hutool.core.func.SerSupplier; import org.dromara.hutool.core.func.SerSupplier;
import org.dromara.hutool.core.io.IoUtil; import org.dromara.hutool.core.io.IoUtil;
@ -512,7 +512,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
* @return 被删除的值如果值不存在返回null * @return 被删除的值如果值不存在返回null
*/ */
public String remove(final String group, final Object key) { public String remove(final String group, final Object key) {
return this.groupedMap.remove(group, Convert.toStr(key)); return this.groupedMap.remove(group, ConvertUtil.toStr(key));
} }
/** /**
@ -641,7 +641,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
*/ */
@Override @Override
public boolean containsKey(final Object key) { public boolean containsKey(final Object key) {
return this.groupedMap.containsKey(DEFAULT_GROUP, Convert.toStr(key)); return this.groupedMap.containsKey(DEFAULT_GROUP, ConvertUtil.toStr(key));
} }
/** /**
@ -652,7 +652,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
*/ */
@Override @Override
public boolean containsValue(final Object value) { public boolean containsValue(final Object value) {
return this.groupedMap.containsValue(DEFAULT_GROUP, Convert.toStr(value)); return this.groupedMap.containsValue(DEFAULT_GROUP, ConvertUtil.toStr(value));
} }
/** /**

View File

@ -17,7 +17,7 @@
package org.dromara.hutool.swing.img.color; package org.dromara.hutool.swing.img.color;
import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.convert.Convert; import org.dromara.hutool.core.convert.ConvertUtil;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.ansi.Ansi4BitColor; import org.dromara.hutool.core.lang.ansi.Ansi4BitColor;
import org.dromara.hutool.core.lang.ansi.Ansi8BitColor; import org.dromara.hutool.core.lang.ansi.Ansi8BitColor;
@ -175,12 +175,12 @@ public class ColorUtil {
if (3 == size) { if (3 == size) {
// RGB // RGB
final Integer[] rgbIntegers = Convert.toIntArray(rgb); final Integer[] rgbIntegers = ConvertUtil.toIntArray(rgb);
return new Color(rgbIntegers[0], rgbIntegers[1], rgbIntegers[2]); return new Color(rgbIntegers[0], rgbIntegers[1], rgbIntegers[2]);
} }
if (4 == size) { if (4 == size) {
// RGBA // RGBA
final Float[] rgbFloats = Convert.toFloatArray(rgb); final Float[] rgbFloats = ConvertUtil.toFloatArray(rgb);
Float a = rgbFloats[3]; Float a = rgbFloats[3];
if (a < 1) { if (a < 1) {
// 识别CSS形式 // 识别CSS形式