add SetUtil

This commit is contained in:
Looly
2022-05-07 12:18:29 +08:00
parent ab0448e0fd
commit 029a603d5f
56 changed files with 434 additions and 625 deletions

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.annotation;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.map.TableMap;
import java.io.Serializable;
@@ -42,7 +42,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
/**
* 元注解
*/
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = CollUtil.newHashSet(Target.class, //
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = SetUtil.newHashSet(Target.class, //
Retention.class, //
Inherited.class, //
Documented.class, //

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.copier.BeanCopier;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.bean.copier.ValueProvider;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.func.Editor;
import cn.hutool.core.map.CaseInsensitiveMap;
@@ -574,7 +575,7 @@ public class BeanUtil {
public static Map<String, Object> beanToMap(final Object bean, final String... properties) {
Editor<String> keyEditor = null;
if(ArrayUtil.isNotEmpty(properties)){
final Set<String> propertiesSet = CollUtil.set(false, properties);
final Set<String> propertiesSet = SetUtil.set(false, properties);
keyEditor = property -> propertiesSet.contains(property) ? property : null;
}

View File

@@ -55,7 +55,6 @@ import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.function.BiConsumer;
import java.util.function.Function;
@@ -122,7 +121,7 @@ public class CollUtil {
final ArrayList<T> list = new ArrayList<>(Math.max(coll1.size(), coll2.size()));
final Map<T, Integer> map1 = countMap(coll1);
final Map<T, Integer> map2 = countMap(coll2);
final Set<T> elts = newHashSet(coll2);
final Set<T> elts = SetUtil.newHashSet(coll2);
elts.addAll(coll1);
int m;
for (final T t : elts) {
@@ -239,7 +238,7 @@ public class CollUtil {
final ArrayList<T> list = new ArrayList<>(Math.min(coll1.size(), coll2.size()));
final Map<T, Integer> map1 = countMap(coll1);
final Map<T, Integer> map2 = countMap(coll2);
final Set<T> elts = newHashSet(coll2);
final Set<T> elts = SetUtil.newHashSet(coll2);
int m;
for (final T t : elts) {
m = Math.min(Convert.toInt(map1.get(t), 0), Convert.toInt(map2.get(t), 0));
@@ -348,7 +347,7 @@ public class CollUtil {
final List<T> result = new ArrayList<>();
final Map<T, Integer> map1 = countMap(coll1);
final Map<T, Integer> map2 = countMap(coll2);
final Set<T> elts = newHashSet(coll2);
final Set<T> elts = SetUtil.newHashSet(coll2);
elts.addAll(coll1);
int m;
for (final T t : elts) {
@@ -654,300 +653,6 @@ public class CollUtil {
return currentAlaDatas;
}
// ----------------------------------------------------------------------------------------------- new HashSet
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param ts 元素数组
* @return HashSet对象
*/
@SafeVarargs
public static <T> HashSet<T> newHashSet(final T... ts) {
return set(false, ts);
}
/**
* 新建一个LinkedHashSet
*
* @param <T> 集合元素类型
* @param ts 元素数组
* @return HashSet对象
* @since 4.1.10
*/
@SafeVarargs
public static <T> LinkedHashSet<T> newLinkedHashSet(final T... ts) {
return (LinkedHashSet<T>) set(true, ts);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回 {@link HashSet}
* @param ts 元素数组
* @return HashSet对象
*/
@SafeVarargs
public static <T> HashSet<T> set(final boolean isSorted, final T... ts) {
if (null == ts) {
return isSorted ? new LinkedHashSet<>() : new HashSet<>();
}
final int initialCapacity = Math.max((int) (ts.length / .75f) + 1, 16);
final HashSet<T> set = isSorted ? new LinkedHashSet<>(initialCapacity) : new HashSet<>(initialCapacity);
Collections.addAll(set, ts);
return set;
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param collection 集合
* @return HashSet对象
*/
public static <T> HashSet<T> newHashSet(final Collection<T> collection) {
return newHashSet(false, collection);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param collection 集合用于初始化Set
* @return HashSet对象
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Collection<T> collection) {
return isSorted ? new LinkedHashSet<>(collection) : new HashSet<>(collection);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param iter {@link Iterator}
* @return HashSet对象
* @since 3.0.8
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Iterator<T> iter) {
if (null == iter) {
return set(isSorted, (T[]) null);
}
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
while (iter.hasNext()) {
set.add(iter.next());
}
return set;
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param enumeration {@link Enumeration}
* @return HashSet对象
* @since 3.0.8
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Enumeration<T> enumeration) {
if (null == enumeration) {
return set(isSorted, (T[]) null);
}
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
while (enumeration.hasMoreElements()) {
set.add(enumeration.nextElement());
}
return set;
}
// ----------------------------------------------------------------------------------------------- List
/**
* 新建一个空List
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @return List对象
* @since 4.1.2
*/
public static <T> List<T> list(final boolean isLinked) {
return ListUtil.list(isLinked);
}
/**
* 新建一个List
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @param values 数组
* @return List对象
* @since 4.1.2
*/
@SafeVarargs
public static <T> List<T> list(final boolean isLinked, final T... values) {
return ListUtil.list(isLinked, values);
}
/**
* 新建一个List
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @param collection 集合
* @return List对象
* @since 4.1.2
*/
public static <T> List<T> list(final boolean isLinked, final Collection<T> collection) {
return ListUtil.list(isLinked, collection);
}
/**
* 新建一个List<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @param iterable {@link Iterable}
* @return List对象
* @since 4.1.2
*/
public static <T> List<T> list(final boolean isLinked, final Iterable<T> iterable) {
return ListUtil.list(isLinked, iterable);
}
/**
* 新建一个ArrayList<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @param iter {@link Iterator}
* @return ArrayList对象
* @since 4.1.2
*/
public static <T> List<T> list(final boolean isLinked, final Iterator<T> iter) {
return ListUtil.list(isLinked, iter);
}
/**
* 新建一个List<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param isLinked 是否新建LinkedList
* @param enumeration {@link Enumeration}
* @return ArrayList对象
* @since 3.0.8
*/
public static <T> List<T> list(final boolean isLinked, final Enumeration<T> enumeration) {
return ListUtil.list(isLinked, enumeration);
}
/**
* 新建一个ArrayList
*
* @param <T> 集合元素类型
* @param values 数组
* @return ArrayList对象
* @see #toList(Object[])
*/
@SafeVarargs
public static <T> ArrayList<T> newArrayList(final T... values) {
return ListUtil.toList(values);
}
/**
* 数组转为ArrayList
*
* @param <T> 集合元素类型
* @param values 数组
* @return ArrayList对象
* @since 4.0.11
*/
@SafeVarargs
public static <T> ArrayList<T> toList(final T... values) {
return ListUtil.toList(values);
}
/**
* 新建一个ArrayList
*
* @param <T> 集合元素类型
* @param collection 集合
* @return ArrayList对象
*/
public static <T> ArrayList<T> newArrayList(final Collection<T> collection) {
return ListUtil.toList(collection);
}
/**
* 新建一个ArrayList<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param iterable {@link Iterable}
* @return ArrayList对象
* @since 3.1.0
*/
public static <T> ArrayList<T> newArrayList(final Iterable<T> iterable) {
return ListUtil.toList(iterable);
}
/**
* 新建一个ArrayList<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param iterator {@link Iterator}
* @return ArrayList对象
* @since 3.0.8
*/
public static <T> ArrayList<T> newArrayList(final Iterator<T> iterator) {
return ListUtil.toList(iterator);
}
/**
* 新建一个ArrayList<br>
* 提供的参数为null时返回空{@link ArrayList}
*
* @param <T> 集合元素类型
* @param enumeration {@link Enumeration}
* @return ArrayList对象
* @since 3.0.8
*/
public static <T> ArrayList<T> newArrayList(final Enumeration<T> enumeration) {
return ListUtil.toList(enumeration);
}
// ----------------------------------------------------------------------new LinkedList
/**
* 新建LinkedList
*
* @param values 数组
* @param <T> 类型
* @return LinkedList
* @since 4.1.2
*/
@SafeVarargs
public static <T> LinkedList<T> newLinkedList(final T... values) {
return ListUtil.toLinkedList(values);
}
/**
* 新建一个CopyOnWriteArrayList
*
* @param <T> 集合元素类型
* @param collection 集合
* @return {@link CopyOnWriteArrayList}
*/
public static <T> CopyOnWriteArrayList<T> newCopyOnWriteArrayList(final Collection<T> collection) {
return ListUtil.toCopyOnWriteArrayList(collection);
}
/**
* 新建{@link BlockingQueue}<br>
* 在队列为空时,获取元素的线程会等待队列变为非空。当队列满时,存储元素的线程会等待队列可用。
@@ -1222,7 +927,7 @@ public class CollUtil {
*/
@SuppressWarnings("unchecked")
public static <T extends Collection<E>, E> T removeAny(final T collection, final E... elesRemoved) {
collection.removeAll(newHashSet(elesRemoved));
collection.removeAll(SetUtil.newHashSet(elesRemoved));
return collection;
}
@@ -1927,7 +1632,7 @@ public class CollUtil {
* @since 3.0.9
*/
public static <E> Collection<E> toCollection(final Iterable<E> iterable) {
return (iterable instanceof Collection) ? (Collection<E>) iterable : newArrayList(iterable.iterator());
return (iterable instanceof Collection) ? (Collection<E>) iterable : ListUtil.toList(iterable.iterator());
}
/**
@@ -2082,7 +1787,7 @@ public class CollUtil {
iter = StrUtil.splitTrim(ArrayStr, CharUtil.COMMA).iterator();
} else {
// 其它类型按照单一元素处理
iter = CollUtil.newArrayList(value).iterator();
iter = ListUtil.toList(value).iterator();
}
final ConverterRegistry convert = ConverterRegistry.getInstance();
@@ -2522,14 +2227,14 @@ public class CollUtil {
// ------------------------------------------------------------------------------------------------- forEach
/**
* 循环遍历 {@link Iterable},使用{@link Consumer} 接受遍历的每条数据,并针对每条数据做处理
* 循环遍历 {@link Iterable},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
*
* @param <T> 集合元素类型
* @param iterable {@link Iterable}
* @param consumer {@link Consumer} 遍历的每条数据处理器
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
* @since 5.4.7
*/
public static <T> void forEach(final Iterable<T> iterable, final Consumer<T> consumer) {
public static <T> void forEach(final Iterable<T> iterable, final IndexedConsumer<T> consumer) {
if (iterable == null) {
return;
}
@@ -2537,13 +2242,13 @@ public class CollUtil {
}
/**
* 循环遍历 {@link Iterator},使用{@link Consumer} 接受遍历的每条数据,并针对每条数据做处理
* 循环遍历 {@link Iterator},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
*
* @param <T> 集合元素类型
* @param iterator {@link Iterator}
* @param consumer {@link Consumer} 遍历的每条数据处理器
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
*/
public static <T> void forEach(final Iterator<T> iterator, final Consumer<T> consumer) {
public static <T> void forEach(final Iterator<T> iterator, final IndexedConsumer<T> consumer) {
if (iterator == null) {
return;
}
@@ -2555,13 +2260,13 @@ public class CollUtil {
}
/**
* 循环遍历 {@link Enumeration},使用{@link Consumer} 接受遍历的每条数据,并针对每条数据做处理
* 循环遍历 {@link Enumeration},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
*
* @param <T> 集合元素类型
* @param enumeration {@link Enumeration}
* @param consumer {@link Consumer} 遍历的每条数据处理器
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
*/
public static <T> void forEach(final Enumeration<T> enumeration, final Consumer<T> consumer) {
public static <T> void forEach(final Enumeration<T> enumeration, final IndexedConsumer<T> consumer) {
if (enumeration == null) {
return;
}
@@ -2573,15 +2278,15 @@ public class CollUtil {
}
/**
* 循环遍历Map使用{@link KVConsumer} 接受遍历的每条数据,并针对每条数据做处理<br>
* 循环遍历Map使用{@link IndexedKVConsumer} 接受遍历的每条数据,并针对每条数据做处理<br>
* 和JDK8中的map.forEach不同的是此方法支持index
*
* @param <K> Key类型
* @param <V> Value类型
* @param map {@link Map}
* @param kvConsumer {@link KVConsumer} 遍历的每条数据处理器
* @param kvConsumer {@link IndexedKVConsumer} 遍历的每条数据处理器
*/
public static <K, V> void forEach(final Map<K, V> map, final KVConsumer<K, V> kvConsumer) {
public static <K, V> void forEach(final Map<K, V> map, final IndexedKVConsumer<K, V> kvConsumer) {
if (map == null) {
return;
}
@@ -2618,11 +2323,11 @@ public class CollUtil {
while (result.size() - 1 < index) {
result.add(null);
}
result.set(index, newArrayList(t));
result.set(index, ListUtil.toList(t));
} else {
subList = result.get(index);
if (null == subList) {
result.set(index, newArrayList(t));
result.set(index, ListUtil.toList(t));
} else {
subList.add(t);
}
@@ -2661,30 +2366,6 @@ public class CollUtil {
});
}
/**
* 反序给定List会在原List基础上直接修改
*
* @param <T> 元素类型
* @param list 被反转的List
* @return 反转后的List
* @since 4.0.6
*/
public static <T> List<T> reverse(final List<T> list) {
return ListUtil.reverse(list);
}
/**
* 反序给定List会创建一个新的List原List数据不变
*
* @param <T> 元素类型
* @param list 被反转的List
* @return 反转后的List
* @since 4.0.6
*/
public static <T> List<T> reverseNew(final List<T> list) {
return ListUtil.reverseNew(list);
}
/**
* 设置或增加元素。当index小于List的长度时替换指定位置的值否则在尾部追加
*
@@ -2903,7 +2584,7 @@ public class CollUtil {
* @author Looly
*/
@FunctionalInterface
public interface Consumer<T> extends Serializable {
public interface IndexedConsumer<T> extends Serializable {
/**
* 接受并处理一个参数
*
@@ -2921,7 +2602,7 @@ public class CollUtil {
* @author Looly
*/
@FunctionalInterface
public interface KVConsumer<K, V> extends Serializable {
public interface IndexedKVConsumer<K, V> extends Serializable {
/**
* 接受并处理一对参数
*

View File

@@ -0,0 +1,123 @@
package cn.hutool.core.collection;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
/**
* 集合中的{@link java.util.Set}相关方法封装
*
* @author looly
*/
public class SetUtil {
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param ts 元素数组
* @return HashSet对象
*/
@SafeVarargs
public static <T> HashSet<T> newHashSet(final T... ts) {
return set(false, ts);
}
/**
* 新建一个LinkedHashSet
*
* @param <T> 集合元素类型
* @param ts 元素数组
* @return HashSet对象
* @since 4.1.10
*/
@SafeVarargs
public static <T> LinkedHashSet<T> newLinkedHashSet(final T... ts) {
return (LinkedHashSet<T>) set(true, ts);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回 {@link HashSet}
* @param ts 元素数组
* @return HashSet对象
*/
@SafeVarargs
public static <T> HashSet<T> set(final boolean isSorted, final T... ts) {
if (null == ts) {
return isSorted ? new LinkedHashSet<>() : new HashSet<>();
}
final int initialCapacity = Math.max((int) (ts.length / .75f) + 1, 16);
final HashSet<T> set = isSorted ? new LinkedHashSet<>(initialCapacity) : new HashSet<>(initialCapacity);
Collections.addAll(set, ts);
return set;
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param collection 集合
* @return HashSet对象
*/
public static <T> HashSet<T> newHashSet(final Collection<T> collection) {
return newHashSet(false, collection);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param collection 集合用于初始化Set
* @return HashSet对象
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Collection<T> collection) {
return isSorted ? new LinkedHashSet<>(collection) : new HashSet<>(collection);
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param iter {@link Iterator}
* @return HashSet对象
* @since 3.0.8
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Iterator<T> iter) {
if (null == iter) {
return set(isSorted, (T[]) null);
}
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
while (iter.hasNext()) {
set.add(iter.next());
}
return set;
}
/**
* 新建一个HashSet
*
* @param <T> 集合元素类型
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
* @param enumeration {@link Enumeration}
* @return HashSet对象
* @since 3.0.8
*/
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Enumeration<T> enumeration) {
if (null == enumeration) {
return set(isSorted, (T[]) null);
}
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
while (enumeration.hasMoreElements()) {
set.add(enumeration.nextElement());
}
return set;
}
}

View File

@@ -1,17 +1,17 @@
package cn.hutool.core.date;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.date.format.DateParser;
import cn.hutool.core.date.format.DatePrinter;
import cn.hutool.core.date.format.FastDateFormat;
import cn.hutool.core.date.format.GlobalCustomFormat;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.regex.PatternPool;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.math.NumberUtil;
import cn.hutool.core.regex.PatternPool;
import cn.hutool.core.regex.ReUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.util.CharUtil;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -20,7 +20,14 @@ import java.time.LocalDateTime;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -1842,8 +1849,8 @@ public class DateUtil extends CalendarUtil {
* @since 5.7.21
*/
public static List<DateTime> rangeContains(final DateRange start, final DateRange end) {
final List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
final List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end);
final List<DateTime> startDateTimes = ListUtil.toList((Iterable<DateTime>) start);
final List<DateTime> endDateTimes = ListUtil.toList((Iterable<DateTime>) end);
return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList());
}
@@ -1857,8 +1864,8 @@ public class DateUtil extends CalendarUtil {
* @since 5.7.21
*/
public static List<DateTime> rangeNotContains(final DateRange start, final DateRange end) {
final List<DateTime> startDateTimes = CollUtil.newArrayList((Iterable<DateTime>) start);
final List<DateTime> endDateTimes = CollUtil.newArrayList((Iterable<DateTime>) end);
final List<DateTime> startDateTimes = ListUtil.toList((Iterable<DateTime>) start);
final List<DateTime> endDateTimes = ListUtil.toList((Iterable<DateTime>) end);
return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList());
}
@@ -1909,7 +1916,7 @@ public class DateUtil extends CalendarUtil {
* @return {@link DateRange}
*/
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit) {
return CollUtil.newArrayList((Iterable<DateTime>) range(start, end, unit));
return ListUtil.toList((Iterable<DateTime>) range(start, end, unit));
}
/**
@@ -1923,7 +1930,7 @@ public class DateUtil extends CalendarUtil {
* @since 5.7.16
*/
public static List<DateTime> rangeToList(final Date start, final Date end, final DateField unit, final int step) {
return CollUtil.newArrayList((Iterable<DateTime>) new DateRange(start, end, unit, step));
return ListUtil.toList((Iterable<DateTime>) new DateRange(start, end, unit, step));
}
/**

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.io.resource;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.IORuntimeException;
import java.io.BufferedReader;
@@ -32,7 +32,7 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
* @param resources 资源数组
*/
public MultiResource(final Resource... resources) {
this(CollUtil.newArrayList(resources));
this(ListUtil.toList(resources));
}
/**
@@ -44,7 +44,7 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
if(resources instanceof List) {
this.resources = (List<Resource>)resources;
}else {
this.resources = CollUtil.newArrayList(resources);
this.resources = ListUtil.toList(resources);
}
}

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.io.watch.watchers;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.watch.Watcher;
import cn.hutool.core.lang.Chain;
@@ -35,7 +35,7 @@ public class WatcherChain implements Watcher, Chain<Watcher, WatcherChain>{
* @param watchers 观察者列表
*/
public WatcherChain(final Watcher... watchers) {
chain = CollUtil.newArrayList(watchers);
chain = ListUtil.toList(watchers);
}
@Override

View File

@@ -2,7 +2,7 @@ package cn.hutool.core.map;
import cn.hutool.core.bean.BeanPath;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Pair;
@@ -290,7 +290,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
* @param withoutNames 不需要去除的字段名
*/
public <T extends Dict> void removeEqual(final T dict, final String... withoutNames) {
final HashSet<String> withoutSet = CollUtil.newHashSet(withoutNames);
final HashSet<String> withoutSet = SetUtil.newHashSet(withoutNames);
for (final Map.Entry<String, Object> entry : dict.entrySet()) {
if (withoutSet.contains(entry.getKey())) {
continue;

View File

@@ -1,6 +1,7 @@
package cn.hutool.core.map;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.func.Editor;
import cn.hutool.core.lang.func.Filter;
@@ -408,7 +409,7 @@ public class MapUtil {
key = entry.getKey();
valueList = resultMap.get(key);
if (null == valueList) {
valueList = CollUtil.newArrayList(entry.getValue());
valueList = ListUtil.toList(entry.getValue());
resultMap.put(key, valueList);
} else {
valueList.add(entry.getValue());
@@ -463,7 +464,7 @@ public class MapUtil {
List<V> vList;
int vListSize;
for (final Entry<K, ? extends Iterable<V>> entry : listMap.entrySet()) {
vList = CollUtil.newArrayList(entry.getValue());
vList = ListUtil.toList(entry.getValue());
vListSize = vList.size();
if (index < vListSize) {
map.put(entry.getKey(), vList.get(index));

View File

@@ -56,8 +56,8 @@ public class TableMap<K, V> implements Map<K, V>, Iterable<Map.Entry<K, V>>, Ser
* @param values 值列表
*/
public TableMap(final K[] keys, final V[] values) {
this.keys = CollUtil.toList(keys);
this.values = CollUtil.toList(values);
this.keys = ListUtil.toList(keys);
this.values = ListUtil.toList(values);
}
@Override

View File

@@ -2,7 +2,7 @@ package cn.hutool.core.reflect;
import cn.hutool.core.bean.NullWrapperBean;
import cn.hutool.core.classloader.ClassLoaderUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.collection.UniqueKeySet;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.exceptions.UtilException;
@@ -90,7 +90,7 @@ public class MethodUtil {
* @return 过滤后的方法列表
*/
public static Method[] getPublicMethods(final Class<?> clazz, final Method... excludeMethods) {
final HashSet<Method> excludeMethodSet = CollUtil.newHashSet(excludeMethods);
final HashSet<Method> excludeMethodSet = SetUtil.newHashSet(excludeMethods);
return getPublicMethods(clazz, method -> false == excludeMethodSet.contains(method));
}
@@ -102,7 +102,7 @@ public class MethodUtil {
* @return 过滤后的方法数组
*/
public static Method[] getPublicMethods(final Class<?> clazz, final String... excludeMethodNames) {
final HashSet<String> excludeMethodNameSet = CollUtil.newHashSet(excludeMethodNames);
final HashSet<String> excludeMethodNameSet = SetUtil.newHashSet(excludeMethodNames);
return getPublicMethods(clazz, method -> false == excludeMethodNameSet.contains(method.getName()));
}

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.regex;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.lang.Assert;
@@ -45,7 +45,7 @@ public class ReUtil {
/**
* 正则中需要被转义的关键字
*/
public final static Set<Character> RE_KEYS = CollUtil.newHashSet('$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|');
public final static Set<Character> RE_KEYS = SetUtil.newHashSet('$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|');
/**
* 获得匹配的字符串获得正则中分组0的内容

View File

@@ -1,8 +1,8 @@
package cn.hutool.core.text.dfa;
import java.util.Set;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.collection.CollUtil;
import java.util.Set;
/**
* 过滤词及一些简单处理
@@ -11,7 +11,7 @@ import cn.hutool.core.collection.CollUtil;
*/
public class StopChar {
/** 不需要处理的词,如标点符号、空格等 */
public static final Set<Character> STOP_WORD = CollUtil.newHashSet(' ', '\'', '、', '。', //
public static final Set<Character> STOP_WORD = SetUtil.newHashSet(' ', '\'', '、', '。', //
'·', 'ˉ', 'ˇ', '々', '—', '', '‖', '…', '', '', '“', '”', '', '', '〈', '〉', '《', '》', '「', '」', '『', //
'』', '〖', '〗', '【', '】', '±', '', '', '×', '÷', '∧', '', '∑', '∏', '', '∩', '∈', '√', '⊥', '⊙', '∫', //
'∮', '≡', '≌', '≈', '∽', '∝', '≠', '≮', '≯', '≤', '≥', '∞', '', '∵', '∴', '∷', '♂', '♀', '°', '', '〃', //

View File

@@ -1,6 +1,7 @@
package cn.hutool.core.text.dfa;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.text.StrUtil;
import java.util.ArrayList;
@@ -85,7 +86,7 @@ public class WordTree extends HashMap<Character, WordTree> {
* @return this
*/
public WordTree addWords(final String... words) {
for (final String word : CollUtil.newHashSet(words)) {
for (final String word : SetUtil.newHashSet(words)) {
addWord(word);
}
return this;

View File

@@ -1,6 +1,7 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.collection.UniqueKeySet;
import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.exceptions.UtilException;
@@ -1287,7 +1288,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* @since 3.0.9
*/
public static <T> T[] toArray(final Iterator<T> iterator, final Class<T> componentType) {
return toArray(CollUtil.newArrayList(iterator), componentType);
return toArray(ListUtil.toList(iterator), componentType);
}
/**

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.text.StrUtil;
@@ -15,7 +15,7 @@ import java.util.Set;
public class BooleanUtil {
/** 表示为真的字符串 */
private static final Set<String> TRUE_SET = CollUtil.newHashSet("true", "yes", "y", "t", "ok", "1", "on", "", "", "", "", "");
private static final Set<String> TRUE_SET = SetUtil.newHashSet("true", "yes", "y", "t", "ok", "1", "on", "", "", "", "", "");
/**
* 取相反值

View File

@@ -1,7 +1,7 @@
package cn.hutool.core.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
@@ -1109,7 +1109,7 @@ public class XmlUtil {
if (value instanceof List) {
((List<Object>) value).add(newValue);
} else {
result.put(childEle.getNodeName(), CollUtil.newArrayList(value, newValue));
result.put(childEle.getNodeName(), ListUtil.toList(value, newValue));
}
} else {
result.put(childEle.getNodeName(), newValue);

View File

@@ -3,14 +3,14 @@ package cn.hutool.core.bean;
import cn.hutool.core.annotation.Alias;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.bean.copier.ValueProvider;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.text.StrUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@@ -285,7 +285,7 @@ public class BeanUtilTest {
@Test
public void getPropertyDescriptorsTest() {
final HashSet<Object> set = CollUtil.newHashSet();
final HashSet<Object> set = SetUtil.newHashSet();
final PropertyDescriptor[] propertyDescriptors = BeanUtil.getPropertyDescriptors(SubPerson.class);
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
set.add(propertyDescriptor.getName());

View File

@@ -35,22 +35,22 @@ public class CollUtilTest {
@Test
public void testPredicateContains() {
final ArrayList<String> list = CollUtil.newArrayList("bbbbb", "aaaaa", "ccccc");
final ArrayList<String> list = ListUtil.toList("bbbbb", "aaaaa", "ccccc");
Assert.assertTrue(CollUtil.contains(list, s -> s.startsWith("a")));
Assert.assertFalse(CollUtil.contains(list, s -> s.startsWith("d")));
}
@Test
public void testRemoveWithAddIf() {
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3);
final ArrayList<Integer> exceptRemovedList = CollUtil.newArrayList(2, 3);
final ArrayList<Integer> exceptResultList = CollUtil.newArrayList(1);
ArrayList<Integer> list = ListUtil.toList(1, 2, 3);
final ArrayList<Integer> exceptRemovedList = ListUtil.toList(2, 3);
final ArrayList<Integer> exceptResultList = ListUtil.toList(1);
List<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
Assert.assertEquals(list, exceptRemovedList);
Assert.assertEquals(resultList, exceptResultList);
list = CollUtil.newArrayList(1, 2, 3);
list = ListUtil.toList(1, 2, 3);
resultList = new ArrayList<>();
CollUtil.removeWithAddIf(list, resultList, ele -> 1 == ele);
Assert.assertEquals(list, exceptRemovedList);
@@ -59,27 +59,27 @@ public class CollUtilTest {
@Test
public void testPadLeft() {
List<String> srcList = CollUtil.newArrayList();
List<String> answerList = CollUtil.newArrayList("a", "b");
List<String> srcList = ListUtil.toList();
List<String> answerList = ListUtil.toList("a", "b");
CollUtil.padLeft(srcList, 1, "b");
CollUtil.padLeft(srcList, 2, "a");
Assert.assertEquals(srcList, answerList);
srcList = CollUtil.newArrayList("a", "b");
answerList = CollUtil.newArrayList("a", "b");
srcList = ListUtil.toList("a", "b");
answerList = ListUtil.toList("a", "b");
CollUtil.padLeft(srcList, 2, "a");
Assert.assertEquals(srcList, answerList);
srcList = CollUtil.newArrayList("c");
answerList = CollUtil.newArrayList("a", "a", "c");
srcList = ListUtil.toList("c");
answerList = ListUtil.toList("a", "a", "c");
CollUtil.padLeft(srcList, 3, "a");
Assert.assertEquals(srcList, answerList);
}
@Test
public void testPadRight() {
final List<String> srcList = CollUtil.newArrayList("a");
final List<String> answerList = CollUtil.newArrayList("a", "b", "b", "b", "b");
final List<String> srcList = ListUtil.toList("a");
final List<String> answerList = ListUtil.toList("a", "b", "b", "b", "b");
CollUtil.padRight(srcList, 5, "b");
Assert.assertEquals(srcList, answerList);
}
@@ -91,7 +91,7 @@ public class CollUtilTest {
@Test
public void newHashSetTest() {
final Set<String> set = CollUtil.newHashSet((String[]) null);
final Set<String> set = SetUtil.newHashSet((String[]) null);
Assert.assertNotNull(set);
}
@@ -114,8 +114,8 @@ public class CollUtilTest {
@Test
public void unionTest() {
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
final Collection<String> union = CollUtil.union(list1, list2);
@@ -124,8 +124,8 @@ public class CollUtilTest {
@Test
public void intersectionTest() {
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
final Collection<String> intersection = CollUtil.intersection(list1, list2);
Assert.assertEquals(2, CollUtil.count(intersection, "b"::equals));
@@ -133,12 +133,12 @@ public class CollUtilTest {
@Test
public void intersectionDistinctTest() {
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
final ArrayList<String> list3 = CollUtil.newArrayList();
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
final ArrayList<String> list3 = ListUtil.toList();
final Collection<String> intersectionDistinct = CollUtil.intersectionDistinct(list1, list2);
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
final Collection<String> intersectionDistinct2 = CollUtil.intersectionDistinct(list1, list2, list3);
Assert.assertTrue(intersectionDistinct2.isEmpty());
@@ -146,8 +146,8 @@ public class CollUtilTest {
@Test
public void disjunctionTest() {
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
Assert.assertTrue(disjunction.contains("b"));
@@ -163,8 +163,8 @@ public class CollUtilTest {
@Test
public void disjunctionTest2() {
// 任意一个集合为空,差集为另一个集合
final ArrayList<String> list1 = CollUtil.newArrayList();
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
final ArrayList<String> list1 = ListUtil.toList();
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
Assert.assertEquals(list2, disjunction);
@@ -175,8 +175,8 @@ public class CollUtilTest {
@Test
public void disjunctionTest3() {
// 无交集下返回共同的元素
final ArrayList<String> list1 = CollUtil.newArrayList("1", "2", "3");
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "c");
final ArrayList<String> list1 = ListUtil.toList("1", "2", "3");
final ArrayList<String> list2 = ListUtil.toList("a", "b", "c");
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
Assert.assertTrue(disjunction.contains("1"));
@@ -196,8 +196,8 @@ public class CollUtilTest {
@Test
public void subtractTest() {
final List<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
final List<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
final List<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
final List<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
final Collection<String> subtract = CollUtil.subtract(list1, list2);
Assert.assertEquals(1, subtract.size());
Assert.assertEquals("x", subtract.iterator().next());
@@ -236,7 +236,7 @@ public class CollUtilTest {
map2.put("c", "值3");
// ----------------------------------------------------------------------------------------
final ArrayList<HashMap<String, String>> list = CollUtil.newArrayList(map1, map2);
final ArrayList<HashMap<String, String>> list = ListUtil.toList(map1, map2);
final Map<String, List<String>> map = CollUtil.toListMap(list);
Assert.assertEquals("值1", map.get("a").get(0));
Assert.assertEquals("值2", map.get("a").get(1));
@@ -251,7 +251,7 @@ public class CollUtilTest {
public void getFieldValuesTest() {
final Dict v1 = Dict.create().set("id", 12).set("name", "张三").set("age", 23);
final Dict v2 = Dict.create().set("age", 13).set("id", 15).set("name", "李四");
final ArrayList<Dict> list = CollUtil.newArrayList(v1, v2);
final ArrayList<Dict> list = ListUtil.toList(v1, v2);
final List<Object> fieldValues = CollUtil.getFieldValues(list, "name");
Assert.assertEquals("张三", fieldValues.get(0));
@@ -260,7 +260,7 @@ public class CollUtilTest {
@Test
public void splitTest() {
final ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
final ArrayList<Integer> list = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
final List<List<Integer>> split = CollUtil.split(list, 3);
Assert.assertEquals(3, split.size());
Assert.assertEquals(3, split.get(0).size());
@@ -285,35 +285,35 @@ public class CollUtilTest {
@Test
public void filterTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
final Collection<String> filtered = CollUtil.edit(list, t -> t + 1);
Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered);
Assert.assertEquals(ListUtil.toList("a1", "b1", "c1"), filtered);
}
@Test
public void filterTest2() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
final ArrayList<String> filtered = CollUtil.filter(list, t -> false == "a".equals(t));
// 原地过滤
Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
Assert.assertEquals(ListUtil.toList("b", "c"), filtered);
}
@Test
public void filterSetTest() {
final Set<String> set = CollUtil.newLinkedHashSet("a", "b", "", " ", "c");
final Set<String> set = SetUtil.newLinkedHashSet("a", "b", "", " ", "c");
final Set<String> filtered = CollUtil.filter(set, StrUtil::isNotBlank);
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c"), filtered);
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c"), filtered);
}
@Test
public void filterRemoveTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
final List<String> removed = new ArrayList<>();
final ArrayList<String> filtered = CollUtil.filter(list, t -> {
@@ -329,45 +329,45 @@ public class CollUtilTest {
// 原地过滤
Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
Assert.assertEquals(ListUtil.toList("b", "c"), filtered);
}
@Test
public void removeNullTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
final ArrayList<String> filtered = CollUtil.removeNull(list);
// 原地过滤
Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered);
Assert.assertEquals(ListUtil.toList("a", "b", "c", "", " "), filtered);
}
@Test
public void removeEmptyTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
final ArrayList<String> filtered = CollUtil.removeEmpty(list);
// 原地过滤
Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered);
Assert.assertEquals(ListUtil.toList("a", "b", "c", " "), filtered);
}
@Test
public void removeBlankTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
final ArrayList<String> filtered = CollUtil.removeBlank(list);
// 原地过滤
Assert.assertSame(list, filtered);
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered);
Assert.assertEquals(ListUtil.toList("a", "b", "c"), filtered);
}
@Test
public void groupTest() {
final List<String> list = CollUtil.newArrayList("1", "2", "3", "4", "5", "6");
final List<String> list = ListUtil.toList("1", "2", "3", "4", "5", "6");
final List<List<String>> group = CollUtil.group(list, null);
Assert.assertTrue(group.size() > 0);
@@ -375,13 +375,13 @@ public class CollUtilTest {
// 按照奇数偶数分类
return Integer.parseInt(t) % 2;
});
Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0));
Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1));
Assert.assertEquals(ListUtil.toList("2", "4", "6"), group2.get(0));
Assert.assertEquals(ListUtil.toList("1", "3", "5"), group2.get(1));
}
@Test
public void groupByFieldTest() {
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
final List<List<TestBean>> groupByField = CollUtil.groupByField(list, "age");
Assert.assertEquals("张三", groupByField.get(0).get(0).getName());
Assert.assertEquals("王五", groupByField.get(0).get(1).getName());
@@ -391,7 +391,7 @@ public class CollUtilTest {
@Test
public void sortByPropertyTest() {
final List<TestBean> list = CollUtil.newArrayList(
final List<TestBean> list = ListUtil.toList(
new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
@@ -405,7 +405,7 @@ public class CollUtilTest {
@Test
public void sortByPropertyTest2() {
final List<TestBean> list = CollUtil.newArrayList(
final List<TestBean> list = ListUtil.toList(
new TestBean("张三", 0, DateUtil.parse("2018-05-01")), //
new TestBean("李四", -12, DateUtil.parse("2018-03-01")), //
new TestBean("王五", 23, DateUtil.parse("2018-04-01"))//
@@ -419,7 +419,7 @@ public class CollUtilTest {
@Test
public void fieldValueMapTest() {
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
);
@@ -432,7 +432,7 @@ public class CollUtilTest {
@Test
public void fieldValueAsMapTest() {
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
new TestBean("王五", 14, DateUtil.parse("2018-04-01"))//
);
@@ -470,8 +470,8 @@ public class CollUtilTest {
@Test
public void listTest() {
final List<Object> list1 = CollUtil.list(false);
final List<Object> list2 = CollUtil.list(true);
final List<Object> list1 = ListUtil.list(false);
final List<Object> list2 = ListUtil.list(true);
Assert.assertTrue(list1 instanceof ArrayList);
Assert.assertTrue(list2 instanceof LinkedList);
@@ -479,8 +479,8 @@ public class CollUtilTest {
@Test
public void listTest2() {
final List<String> list1 = CollUtil.list(false, "a", "b", "c");
final List<String> list2 = CollUtil.list(true, "a", "b", "c");
final List<String> list1 = ListUtil.list(false, "a", "b", "c");
final List<String> list2 = ListUtil.list(true, "a", "b", "c");
Assert.assertEquals("[a, b, c]", list1.toString());
Assert.assertEquals("[a, b, c]", list2.toString());
}
@@ -492,15 +492,15 @@ public class CollUtilTest {
set.add("b");
set.add("c");
final List<String> list1 = CollUtil.list(false, set);
final List<String> list2 = CollUtil.list(true, set);
final List<String> list1 = ListUtil.list(false, set);
final List<String> list2 = ListUtil.list(true, set);
Assert.assertEquals("[a, b, c]", list1.toString());
Assert.assertEquals("[a, b, c]", list2.toString());
}
@Test
public void getTest() {
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
String str = CollUtil.get(set, 2);
Assert.assertEquals("C", str);
@@ -701,43 +701,43 @@ public class CollUtilTest {
@Test
public void sortPageAllTest() {
final List<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
final List<Integer> list = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
final List<Integer> sortPageAll = CollUtil.sortPageAll(1, 5, Comparator.reverseOrder(), list);
Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll);
Assert.assertEquals(ListUtil.toList(4, 3, 2, 1), sortPageAll);
}
@Test
public void containsAnyTest() {
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1, 9, 11);
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1, 9, 11);
Assert.assertTrue(CollUtil.containsAny(list1, list2));
}
@Test
public void containsAllTest() {
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1);
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1);
Assert.assertTrue(CollUtil.containsAll(list1, list2));
final ArrayList<Integer> list3 = CollUtil.newArrayList(1);
final ArrayList<Integer> list4 = CollUtil.newArrayList();
final ArrayList<Integer> list3 = ListUtil.toList(1);
final ArrayList<Integer> list4 = ListUtil.toList();
Assert.assertTrue(CollUtil.containsAll(list3, list4));
}
@Test
public void getLastTest() {
// 测试空数组返回null而不是报错
final List<String> test = CollUtil.newArrayList();
final List<String> test = ListUtil.toList();
final String last = CollUtil.getLast(test);
Assert.assertNull(last);
}
@Test
public void zipTest() {
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
final Collection<Integer> values = CollUtil.newArrayList(1, 2, 3, 4);
final Collection<String> keys = ListUtil.toList("a", "b", "c", "d");
final Collection<Integer> values = ListUtil.toList(1, 2, 3, 4);
final Map<String, Integer> map = CollUtil.zip(keys, values);
@@ -751,7 +751,7 @@ public class CollUtilTest {
@Test
public void toMapTest() {
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
final Collection<String> keys = ListUtil.toList("a", "b", "c", "d");
final Map<String, String> map = CollUtil.toMap(keys, new HashMap<>(), (value) -> "key" + value);
Assert.assertEquals("a", map.get("keya"));
Assert.assertEquals("b", map.get("keyb"));
@@ -778,7 +778,7 @@ public class CollUtilTest {
@Test
public void countMapTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
final Map<String, Integer> countMap = CollUtil.countMap(list);
Assert.assertEquals(Integer.valueOf(2), countMap.get("a"));
@@ -789,7 +789,7 @@ public class CollUtilTest {
@Test
public void indexOfTest() {
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
final int i = CollUtil.indexOf(list, (str) -> str.charAt(0) == 'c');
Assert.assertEquals(2, i);
}
@@ -797,14 +797,14 @@ public class CollUtilTest {
@Test
public void lastIndexOfTest() {
// List有优化
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
Assert.assertEquals(3, i);
}
@Test
public void lastIndexOfSetTest() {
final Set<String> list = CollUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
final Set<String> list = SetUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
// 去重后c排第三
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
Assert.assertEquals(2, i);
@@ -812,7 +812,7 @@ public class CollUtilTest {
@Test
public void pageTest() {
final List<Dict> objects = CollUtil.newArrayList();
final List<Dict> objects = ListUtil.toList();
for (int i = 0; i < 10; i++) {
objects.add(Dict.create().set("name", "姓名:" + i));
}

View File

@@ -24,13 +24,13 @@ public class IterUtilTest {
@Test
public void getFirstNonNullTest(){
final ArrayList<String> strings = CollUtil.newArrayList(null, null, "123", "456", null);
final ArrayList<String> strings = ListUtil.toList(null, null, "123", "456", null);
Assert.assertEquals("123", IterUtil.getFirstNoneNull(strings));
}
@Test
public void fieldValueMapTest() {
final ArrayList<Car> carList = CollUtil.newArrayList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
final ArrayList<Car> carList = ListUtil.toList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
final Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
@@ -40,30 +40,30 @@ public class IterUtilTest {
@Test
public void joinTest() {
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
final ArrayList<String> list = ListUtil.toList("1", "2", "3", "4");
final String join = IterUtil.join(list.iterator(), ":");
Assert.assertEquals("1:2:3:4", join);
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4);
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4);
final String join1 = IterUtil.join(list1.iterator(), ":");
Assert.assertEquals("1:2:3:4", join1);
// 包装每个节点
final ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
final ArrayList<String> list2 = ListUtil.toList("1", "2", "3", "4");
final String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
}
@Test
public void joinWithFuncTest() {
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
final ArrayList<String> list = ListUtil.toList("1", "2", "3", "4");
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
Assert.assertEquals("1:2:3:4", join);
}
@Test
public void joinWithNullTest() {
final ArrayList<String> list = CollUtil.newArrayList("1", null, "3", "4");
final ArrayList<String> list = ListUtil.toList("1", null, "3", "4");
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
Assert.assertEquals("1:null:3:4", join);
}
@@ -142,7 +142,7 @@ public class IterUtilTest {
@Test
public void getTest() {
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
final String str = IterUtil.get(set.iterator(), 2);
Assert.assertEquals("C", str);
}

View File

@@ -1,12 +1,12 @@
package cn.hutool.core.convert;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.codec.HexUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.date.DateException;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.reflect.TypeReference;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.reflect.TypeReference;
import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.codec.HexUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
@@ -293,7 +293,7 @@ public class ConvertTest {
public void toSetTest(){
final Set<Integer> result = Convert.convert(new TypeReference<Set<Integer>>() {
}, "1,2,3");
Assert.assertEquals(CollUtil.set(false, 1,2,3), result);
Assert.assertEquals(SetUtil.set(false, 1,2,3), result);
}
@Getter

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.convert;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.reflect.TypeReference;
import org.junit.Assert;
import org.junit.Test;
@@ -128,7 +128,7 @@ public class ConvertToCollectionTest {
public void toSetTest() {
final Object[] a = { "a", "", "", "", 1 };
final LinkedHashSet<?> set = Convert.convert(LinkedHashSet.class, a);
final ArrayList<?> list = CollUtil.newArrayList(set);
final ArrayList<?> list = ListUtil.toList(set);
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("", list.get(1));
Assert.assertEquals("", list.get(2));

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.date;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.BetweenFormatter.Level;
import cn.hutool.core.date.format.FastDateFormat;
import cn.hutool.core.lang.Console;
@@ -800,13 +800,13 @@ public class DateUtilTest {
Assert.assertEquals("20184", yearAndQuarter);
final LinkedHashSet<String> yearAndQuarters = DateUtil.yearAndQuarter(DateUtil.parse("2018-09-10"), DateUtil.parse("2018-12-20"));
final List<String> list = CollUtil.list(false, yearAndQuarters);
final List<String> list = ListUtil.list(false, yearAndQuarters);
Assert.assertEquals(2, list.size());
Assert.assertEquals("20183", list.get(0));
Assert.assertEquals("20184", list.get(1));
final LinkedHashSet<String> yearAndQuarters2 = DateUtil.yearAndQuarter(DateUtil.parse("2018-10-10"), DateUtil.parse("2018-12-10"));
final List<String> list2 = CollUtil.list(false, yearAndQuarters2);
final List<String> list2 = ListUtil.list(false, yearAndQuarters2);
Assert.assertEquals(1, list2.size());
Assert.assertEquals("20184", list2.get(0));
}

View File

@@ -1,10 +1,9 @@
package cn.hutool.core.lang;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.collection.CollUtil;
public class WeightRandomTest {
@Test
@@ -15,6 +14,6 @@ public class WeightRandomTest {
random.add("C", 100);
final String result = random.next();
Assert.assertTrue(CollUtil.newArrayList("A", "B", "C").contains(result));
Assert.assertTrue(ListUtil.toList("A", "B", "C").contains(result));
}
}

View File

@@ -1,7 +1,7 @@
package cn.hutool.core.text;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.collection.SetUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -34,7 +34,7 @@ public class StrJoinerTest {
public void joinMultiArrayTest(){
final StrJoiner append = StrJoiner.of(",");
append.append(new Object[]{ListUtil.of("1", "2"),
CollUtil.newLinkedHashSet("3", "4")
SetUtil.newLinkedHashSet("3", "4")
});
Assert.assertEquals("1,2,3,4", append.toString());
}

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.text.dfa;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -27,7 +27,7 @@ public class DfaTest {
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
final List<String> matchAll = tree.matchAll(text, -1, false, false);
Assert.assertEquals(matchAll, CollUtil.newArrayList("", "土^豆", "刚出锅"));
Assert.assertEquals(matchAll, ListUtil.toList("", "土^豆", "刚出锅"));
}
/**
@@ -43,7 +43,7 @@ public class DfaTest {
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
final List<String> matchAll = tree.matchAll(text, -1, true, false);
Assert.assertEquals(matchAll, CollUtil.newArrayList("", "土^豆", "刚出锅", "出锅"));
Assert.assertEquals(matchAll, ListUtil.toList("", "土^豆", "刚出锅", "出锅"));
}
/**
@@ -59,7 +59,7 @@ public class DfaTest {
// 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配
// 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过
final List<String> matchAll = tree.matchAll(text, -1, false, true);
Assert.assertEquals(matchAll, CollUtil.newArrayList("", "土^豆", "刚出锅"));
Assert.assertEquals(matchAll, ListUtil.toList("", "土^豆", "刚出锅"));
}
@@ -76,7 +76,7 @@ public class DfaTest {
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
final List<String> matchAll = tree.matchAll(text, -1, true, true);
Assert.assertEquals(matchAll, CollUtil.newArrayList("", "大土^豆", "土^豆", "刚出锅", "出锅"));
Assert.assertEquals(matchAll, ListUtil.toList("", "大土^豆", "土^豆", "刚出锅", "出锅"));
}
@@ -112,7 +112,7 @@ public class DfaTest {
tree.addWord("tio");
final List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
Assert.assertEquals(all, CollUtil.newArrayList("t-io"));
Assert.assertEquals(all, ListUtil.toList("t-io"));
}
@Test

View File

@@ -1,10 +1,6 @@
package cn.hutool.core.tree;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.tree.Tree;
import cn.hutool.core.tree.TreeNode;
import cn.hutool.core.tree.TreeNodeConfig;
import cn.hutool.core.tree.TreeUtil;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -18,7 +14,7 @@ import java.util.List;
*/
public class TreeTest {
// 模拟数据
static List<TreeNode<String>> nodeList = CollUtil.newArrayList();
static List<TreeNode<String>> nodeList = ListUtil.toList();
static {
// 模拟数据

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -323,7 +323,7 @@ public class ArrayUtilTest {
@Test
public void toArrayTest() {
final ArrayList<String> list = CollUtil.newArrayList("A", "B", "C", "D");
final ArrayList<String> list = ListUtil.toList("A", "B", "C", "D");
final String[] array = ArrayUtil.toArray(list, String.class);
Assert.assertEquals("A", array[0]);
Assert.assertEquals("B", array[1]);

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -18,13 +18,13 @@ public class EnumUtilTest {
@Test
public void getNamesTest() {
final List<String> names = EnumUtil.getNames(TestEnum.class);
Assert.assertEquals(CollUtil.newArrayList("TEST1", "TEST2", "TEST3"), names);
Assert.assertEquals(ListUtil.toList("TEST1", "TEST2", "TEST3"), names);
}
@Test
public void getFieldValuesTest() {
final List<Object> types = EnumUtil.getFieldValues(TestEnum.class, "type");
Assert.assertEquals(CollUtil.newArrayList("type1", "type2", "type3"), types);
Assert.assertEquals(ListUtil.toList("type1", "type2", "type3"), types);
}
@Test

View File

@@ -1,7 +1,7 @@
package cn.hutool.core.util;
import cn.hutool.core.clone.CloneSupport;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
@@ -58,7 +58,7 @@ public class ObjectUtilTest {
@Test
public void toStringTest() {
final ArrayList<String> strings = CollUtil.newArrayList("1", "2");
final ArrayList<String> strings = ListUtil.toList("1", "2");
final String result = ObjUtil.toString(strings);
Assert.assertEquals("[1, 2]", result);
}

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Ignore;
@@ -15,13 +15,13 @@ public class RandomUtilTest {
@Test
public void randomEleSetTest(){
final Set<Integer> set = RandomUtil.randomEleSet(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
final Set<Integer> set = RandomUtil.randomEleSet(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
Assert.assertEquals(set.size(), 2);
}
@Test
public void randomElesTest(){
final List<Integer> result = RandomUtil.randomEles(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
final List<Integer> result = RandomUtil.randomEles(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
Assert.assertEquals(result.size(), 2);
}

View File

@@ -1,6 +1,6 @@
package cn.hutool.core.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.regex.PatternPool;
import cn.hutool.core.regex.ReUtil;
@@ -82,7 +82,7 @@ public class ReUtilTest {
public void findAllTest() {
// 查找所有匹配文本
final List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
final ArrayList<String> expected = CollUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
final ArrayList<String> expected = ListUtil.toList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
Assert.assertEquals(expected, resultFindAll);
}

View File

@@ -1,7 +1,8 @@
package cn.hutool.core.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.collection.SetUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapBuilder;
@@ -109,7 +110,7 @@ public class XmlUtilTest {
final Map<String, Object> map = XmlUtil.xmlToMap(xml);
Assert.assertEquals(1, map.size());
Assert.assertEquals(CollUtil.newArrayList("张三", "李四"), map.get("name"));
Assert.assertEquals(ListUtil.toList("张三", "李四"), map.get("name"));
}
@Test
@@ -137,7 +138,7 @@ public class XmlUtilTest {
public void mapToXmlTest2() {
// 测试List
final Map<String, Object> map = MapBuilder.create(new LinkedHashMap<String, Object>())
.put("Town", CollUtil.newArrayList("town1", "town2"))
.put("Town", ListUtil.toList("town1", "town2"))
.build();
final Document doc = XmlUtil.mapToXml(map, "City");
@@ -157,7 +158,7 @@ public class XmlUtilTest {
@Test
public void readBySaxTest(){
final Set<String> eles = CollUtil.newHashSet(
final Set<String> eles = SetUtil.newHashSet(
"returnsms", "returnstatus", "message", "remainpoint", "taskID", "successCounts");
XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){
@Override