mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
029a603d5f
commit
36d75d7030
@ -42,7 +42,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
/**
|
||||
* 元注解
|
||||
*/
|
||||
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = SetUtil.newHashSet(Target.class, //
|
||||
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = SetUtil.of(Target.class, //
|
||||
Retention.class, //
|
||||
Inherited.class, //
|
||||
Documented.class, //
|
||||
|
@ -575,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 = SetUtil.set(false, properties);
|
||||
final Set<String> propertiesSet = SetUtil.of(properties);
|
||||
keyEditor = property -> propertiesSet.contains(property) ? property : null;
|
||||
}
|
||||
|
||||
|
@ -121,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 = SetUtil.newHashSet(coll2);
|
||||
final Set<T> elts = SetUtil.of(coll2);
|
||||
elts.addAll(coll1);
|
||||
int m;
|
||||
for (final T t : elts) {
|
||||
@ -238,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 = SetUtil.newHashSet(coll2);
|
||||
final Set<T> elts = SetUtil.of(coll2);
|
||||
int m;
|
||||
for (final T t : elts) {
|
||||
m = Math.min(Convert.toInt(map1.get(t), 0), Convert.toInt(map2.get(t), 0));
|
||||
@ -347,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 = SetUtil.newHashSet(coll2);
|
||||
final Set<T> elts = SetUtil.of(coll2);
|
||||
elts.addAll(coll1);
|
||||
int m;
|
||||
for (final T t : elts) {
|
||||
@ -400,7 +400,7 @@ public class CollUtil {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
if (isEmpty(coll2)) {
|
||||
return ListUtil.list(true, coll1);
|
||||
return ListUtil.of(true, coll1);
|
||||
}
|
||||
|
||||
//将被交数用链表储存,防止因为频繁扩容影响性能
|
||||
@ -830,7 +830,7 @@ public class CollUtil {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
|
||||
final List<T> list = collection instanceof List ? (List<T>) collection : ListUtil.toList(collection);
|
||||
final List<T> list = collection instanceof List ? (List<T>) collection : ListUtil.of(collection);
|
||||
return sub(list, start, end, step);
|
||||
}
|
||||
|
||||
@ -927,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(SetUtil.newHashSet(elesRemoved));
|
||||
collection.removeAll(SetUtil.of(elesRemoved));
|
||||
return collection;
|
||||
}
|
||||
|
||||
@ -1632,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 : ListUtil.toList(iterable.iterator());
|
||||
return (iterable instanceof Collection) ? (Collection<E>) iterable : ListUtil.of(iterable.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1787,7 +1787,7 @@ public class CollUtil {
|
||||
iter = StrUtil.splitTrim(ArrayStr, CharUtil.COMMA).iterator();
|
||||
} else {
|
||||
// 其它类型按照单一元素处理
|
||||
iter = ListUtil.toList(value).iterator();
|
||||
iter = ListUtil.of(value).iterator();
|
||||
}
|
||||
|
||||
final ConverterRegistry convert = ConverterRegistry.getInstance();
|
||||
@ -2323,11 +2323,11 @@ public class CollUtil {
|
||||
while (result.size() - 1 < index) {
|
||||
result.add(null);
|
||||
}
|
||||
result.set(index, ListUtil.toList(t));
|
||||
result.set(index, ListUtil.of(t));
|
||||
} else {
|
||||
subList = result.get(index);
|
||||
if (null == subList) {
|
||||
result.set(index, ListUtil.toList(t));
|
||||
result.set(index, ListUtil.of(t));
|
||||
} else {
|
||||
subList.add(t);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.collection.iter.EnumerationIter;
|
||||
import cn.hutool.core.collection.partition.AvgPartition;
|
||||
import cn.hutool.core.collection.partition.Partition;
|
||||
import cn.hutool.core.collection.partition.RandomAccessAvgPartition;
|
||||
@ -29,51 +30,53 @@ import java.util.function.Consumer;
|
||||
* @author looly
|
||||
*/
|
||||
public class ListUtil {
|
||||
/**
|
||||
* 新建一个空List
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否新建LinkedList
|
||||
* @return List对象
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public static <T> List<T> list(final boolean isLinked) {
|
||||
return isLinked ? new LinkedList<>() : new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个List
|
||||
* 新建一个List<br>
|
||||
* 如果提供的初始化数组为空,新建默认初始长度的List
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否新建LinkedList
|
||||
* @param values 数组
|
||||
* @param values 数组,可以为{@code null}
|
||||
* @return List对象
|
||||
* @since 4.1.2
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> List<T> list(final boolean isLinked, final T... values) {
|
||||
public static <T> ArrayList<T> of(final T... values) {
|
||||
if (ArrayUtil.isEmpty(values)) {
|
||||
return list(isLinked);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
final List<T> arrayList = isLinked ? new LinkedList<>() : new ArrayList<>(values.length);
|
||||
final ArrayList<T> arrayList = new ArrayList<>(values.length);
|
||||
Collections.addAll(arrayList, values);
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个List
|
||||
* 新建一个{@link LinkedList}<br>
|
||||
* 如果提供的初始化数组为空,新建默认初始长度的List
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否新建LinkedList
|
||||
* @param collection 集合
|
||||
* @return List对象
|
||||
* @since 4.1.2
|
||||
* @param values 数组,可以为{@code null}
|
||||
* @return {@link LinkedList}对象
|
||||
*/
|
||||
public static <T> List<T> list(final boolean isLinked, final Collection<T> collection) {
|
||||
if (null == collection) {
|
||||
return list(isLinked);
|
||||
@SafeVarargs
|
||||
public static <T> LinkedList<T> ofLinked(final T... values) {
|
||||
final LinkedList<T> list = new LinkedList<>();
|
||||
if (ArrayUtil.isNotEmpty(values)) {
|
||||
Collections.addAll(list, values);
|
||||
}
|
||||
return isLinked ? new LinkedList<>(collection) : new ArrayList<>(collection);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个List<br>
|
||||
* 如果提供的初始化数组为空,新建默认初始长度的List
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否为链表
|
||||
* @return List对象
|
||||
*/
|
||||
public static <T> List<T> of(final boolean isLinked) {
|
||||
return isLinked ? ofLinked() : of();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,31 +89,15 @@ public class ListUtil {
|
||||
* @return List对象
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public static <T> List<T> list(final boolean isLinked, final Iterable<T> iterable) {
|
||||
public static <T> List<T> of(final boolean isLinked, final Iterable<T> iterable) {
|
||||
if (null == iterable) {
|
||||
return list(isLinked);
|
||||
return of(isLinked);
|
||||
}
|
||||
return list(isLinked, iterable.iterator());
|
||||
if (iterable instanceof Collection) {
|
||||
final Collection<T> collection = (Collection<T>) iterable;
|
||||
return isLinked ? new LinkedList<>(collection) : new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个List<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) {
|
||||
final List<T> list = list(isLinked);
|
||||
if (null != iter) {
|
||||
while (iter.hasNext()) {
|
||||
list.add(iter.next());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return of(isLinked, iterable.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,80 +110,30 @@ public class ListUtil {
|
||||
* @return ArrayList对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static <T> List<T> list(final boolean isLinked, final Enumeration<T> enumration) {
|
||||
final List<T> list = list(isLinked);
|
||||
if (null != enumration) {
|
||||
while (enumration.hasMoreElements()) {
|
||||
list.add(enumration.nextElement());
|
||||
public static <T> List<T> of(final boolean isLinked, final Enumeration<T> enumration) {
|
||||
return of(isLinked, (Iterator<T>) new EnumerationIter<>(enumration));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个List<br>
|
||||
* 提供的参数为null时返回空{@link ArrayList}
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否新建LinkedList
|
||||
* @param iter {@link Iterator}
|
||||
* @return ArrayList对象
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public static <T> List<T> of(final boolean isLinked, final Iterator<T> iter) {
|
||||
final List<T> list = of(isLinked);
|
||||
if (null != iter) {
|
||||
while (iter.hasNext()) {
|
||||
list.add(iter.next());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个ArrayList
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param values 数组
|
||||
* @return ArrayList对象
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> ArrayList<T> toList(final T... values) {
|
||||
return (ArrayList<T>) list(false, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建LinkedList
|
||||
*
|
||||
* @param values 数组
|
||||
* @param <T> 类型
|
||||
* @return LinkedList
|
||||
* @since 4.1.2
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> LinkedList<T> toLinkedList(final T... values) {
|
||||
return (LinkedList<T>) list(true, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组转为一个不可变List<br>
|
||||
* 类似于Java9中的List.of
|
||||
*
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List
|
||||
* @since 5.4.3
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> List<T> of(final T... ts) {
|
||||
if (ArrayUtil.isEmpty(ts)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.unmodifiableList(toList(ts));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个CopyOnWriteArrayList
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @return {@link CopyOnWriteArrayList}
|
||||
*/
|
||||
public static <T> CopyOnWriteArrayList<T> toCopyOnWriteArrayList(final Collection<T> collection) {
|
||||
return (null == collection) ? (new CopyOnWriteArrayList<>()) : (new CopyOnWriteArrayList<>(collection));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个ArrayList
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @return ArrayList对象
|
||||
*/
|
||||
public static <T> ArrayList<T> toList(final Collection<T> collection) {
|
||||
return (ArrayList<T>) list(false, collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个ArrayList<br>
|
||||
* 提供的参数为null时返回空{@link ArrayList}
|
||||
@ -206,8 +143,8 @@ public class ListUtil {
|
||||
* @return ArrayList对象
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public static <T> ArrayList<T> toList(final Iterable<T> iterable) {
|
||||
return (ArrayList<T>) list(false, iterable);
|
||||
public static <T> ArrayList<T> of(final Iterable<T> iterable) {
|
||||
return (ArrayList<T>) of(false, iterable);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,8 +156,8 @@ public class ListUtil {
|
||||
* @return ArrayList对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static <T> ArrayList<T> toList(final Iterator<T> iterator) {
|
||||
return (ArrayList<T>) list(false, iterator);
|
||||
public static <T> ArrayList<T> of(final Iterator<T> iterator) {
|
||||
return (ArrayList<T>) of(false, iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,8 +169,71 @@ public class ListUtil {
|
||||
* @return ArrayList对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static <T> ArrayList<T> toList(final Enumeration<T> enumeration) {
|
||||
return (ArrayList<T>) list(false, enumeration);
|
||||
public static <T> ArrayList<T> of(final Enumeration<T> enumeration) {
|
||||
return (ArrayList<T>) of(false, enumeration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组转为一个不可变List<br>
|
||||
* 类似于Java9中的List.of
|
||||
*
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> List<T> view(final T... ts) {
|
||||
return view(of(ts));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为一个不可变List<br>
|
||||
* 类似于Java9中的List.of
|
||||
*
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List,如果提供List为{@code null}或者空,返回{@link Collections#emptyList()}
|
||||
*/
|
||||
public static <T> List<T> view(final List<T> ts) {
|
||||
if (ArrayUtil.isEmpty(ts)) {
|
||||
return empty();
|
||||
}
|
||||
return Collections.unmodifiableList(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个空List,这个空List不可变
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @return 空的List
|
||||
* @see Collections#emptyList()
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static <T> List<T> empty() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个CopyOnWriteArrayList
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @return {@link CopyOnWriteArrayList}
|
||||
*/
|
||||
public static <T> CopyOnWriteArrayList<T> ofCopyOnWrite(final Collection<T> collection) {
|
||||
return (null == collection) ? (new CopyOnWriteArrayList<>()) : (new CopyOnWriteArrayList<>(collection));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个CopyOnWriteArrayList
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param ts 集合
|
||||
* @return {@link CopyOnWriteArrayList}
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> CopyOnWriteArrayList<T> ofCopyOnWrite(final T... ts) {
|
||||
return (null == ts) ? (new CopyOnWriteArrayList<>()) : (new CopyOnWriteArrayList<>(ts));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,7 +255,7 @@ public class ListUtil {
|
||||
// 每页条目数大于总数直接返回所有
|
||||
if (resultSize <= pageSize) {
|
||||
if (pageNo < (PageUtil.getFirstPageNo() + 1)) {
|
||||
return unmodifiable(list);
|
||||
return view(list);
|
||||
} else {
|
||||
// 越界直接返回空
|
||||
return new ArrayList<>(0);
|
||||
@ -500,33 +500,6 @@ public class ListUtil {
|
||||
return CollUtil.indexOfAll(list, matcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对应List转换为不可修改的List
|
||||
*
|
||||
* @param list List
|
||||
* @param <T> 元素类型
|
||||
* @return 不可修改List
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static <T> List<T> unmodifiable(final List<T> list) {
|
||||
if (null == list) {
|
||||
return null;
|
||||
}
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个空List,这个空List不可变
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @return 空的List
|
||||
* @see Collections#emptyList()
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static <T> List<T> empty() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过传入分区长度,将指定列表分区为不同的块,每块区域的长度相同(最后一块可能小于长度)<br>
|
||||
* 分区是在原List的基础上进行的,返回的分区是不可变的抽象列表,原列表元素变更,分区中元素也会变更。
|
||||
|
@ -1,11 +1,14 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 集合中的{@link java.util.Set}相关方法封装
|
||||
@ -14,6 +17,18 @@ import java.util.LinkedHashSet;
|
||||
*/
|
||||
public class SetUtil {
|
||||
|
||||
/**
|
||||
* 新建一个List<br>
|
||||
* 如果提供的初始化数组为空,新建默认初始长度的List
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否为链表
|
||||
* @return List对象
|
||||
*/
|
||||
public static <T> HashSet<T> of(final boolean isLinked) {
|
||||
return _of(isLinked, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个HashSet
|
||||
*
|
||||
@ -22,8 +37,8 @@ public class SetUtil {
|
||||
* @return HashSet对象
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> HashSet<T> newHashSet(final T... ts) {
|
||||
return set(false, ts);
|
||||
public static <T> HashSet<T> of(final T... ts) {
|
||||
return _of(false, ts);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,50 +50,39 @@ public class SetUtil {
|
||||
* @since 4.1.10
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> LinkedHashSet<T> newLinkedHashSet(final T... ts) {
|
||||
return (LinkedHashSet<T>) set(true, ts);
|
||||
public static <T> LinkedHashSet<T> ofLinked(final T... ts) {
|
||||
return (LinkedHashSet<T>) _of(true, ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个HashSet
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回 {@link HashSet}
|
||||
* @param ts 元素数组
|
||||
* @param iterable 集合
|
||||
* @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;
|
||||
public static <T> HashSet<T> of(final Iterable<T> iterable) {
|
||||
return of(false, iterable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个HashSet
|
||||
* 新建一个HashSet<br>
|
||||
* 提供的参数为null时返回空{@link HashSet}
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @param isLinked 是否新建LinkedList
|
||||
* @param iterable {@link Iterable}
|
||||
* @return HashSet对象
|
||||
*/
|
||||
public static <T> HashSet<T> newHashSet(final Collection<T> collection) {
|
||||
return newHashSet(false, collection);
|
||||
public static <T> HashSet<T> of(final boolean isLinked, final Iterable<T> iterable) {
|
||||
if (null == iterable) {
|
||||
return of(isLinked);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个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);
|
||||
if (iterable instanceof Collection) {
|
||||
final Collection<T> collection = (Collection<T>) iterable;
|
||||
return isLinked ? new LinkedHashSet<>(collection) : new HashSet<>(collection);
|
||||
}
|
||||
return of(isLinked, iterable.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,9 +94,9 @@ public class SetUtil {
|
||||
* @return HashSet对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static <T> HashSet<T> newHashSet(final boolean isSorted, final Iterator<T> iter) {
|
||||
public static <T> HashSet<T> of(final boolean isSorted, final Iterator<T> iter) {
|
||||
if (null == iter) {
|
||||
return set(isSorted, (T[]) null);
|
||||
return _of(isSorted, null);
|
||||
}
|
||||
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
|
||||
while (iter.hasNext()) {
|
||||
@ -105,19 +109,75 @@ public class SetUtil {
|
||||
* 新建一个HashSet
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isSorted 是否有序,有序返回 {@link LinkedHashSet},否则返回{@link HashSet}
|
||||
* @param isLinked 是否有序,有序返回 {@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) {
|
||||
public static <T> HashSet<T> of(final boolean isLinked, final Enumeration<T> enumeration) {
|
||||
if (null == enumeration) {
|
||||
return set(isSorted, (T[]) null);
|
||||
return _of(isLinked, null);
|
||||
}
|
||||
final HashSet<T> set = isSorted ? new LinkedHashSet<>() : new HashSet<>();
|
||||
final HashSet<T> set = isLinked ? new LinkedHashSet<>() : new HashSet<>();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
set.add(enumeration.nextElement());
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组转为一个不可变List<br>
|
||||
* 类似于Java9中的List.of
|
||||
*
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> Set<T> view(final T... ts) {
|
||||
return view(of(ts));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为一个不可变Set
|
||||
*
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List,如果提供List为{@code null}或者空,返回{@link Collections#emptySet()}
|
||||
*/
|
||||
public static <T> Set<T> view(final Set<T> ts) {
|
||||
if (ArrayUtil.isEmpty(ts)) {
|
||||
return empty();
|
||||
}
|
||||
return Collections.unmodifiableSet(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个空Set,这个空Set不可变
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @return 空的List
|
||||
* @see Collections#emptySet()
|
||||
*/
|
||||
public static <T> Set<T> empty() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建一个HashSet
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param isLinked 是否有序,有序返回 {@link LinkedHashSet},否则返回 {@link HashSet}
|
||||
* @param ts 元素数组
|
||||
* @return HashSet对象
|
||||
*/
|
||||
private static <T> HashSet<T> _of(final boolean isLinked, final T[] ts) {
|
||||
if (ArrayUtil.isEmpty(ts)) {
|
||||
return isLinked ? new LinkedHashSet<>() : new HashSet<>();
|
||||
}
|
||||
final int initialCapacity = Math.max((int) (ts.length / .75f) + 1, 16);
|
||||
final HashSet<T> set = isLinked ? new LinkedHashSet<>(initialCapacity) : new HashSet<>(initialCapacity);
|
||||
Collections.addAll(set, ts);
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class CopiedIter<E> implements IterableIter<E>, Serializable {
|
||||
* @param iterator 被复制的Iterator
|
||||
*/
|
||||
public CopiedIter(final Iterator<E> iterator) {
|
||||
final List<E> eleList = ListUtil.toList(iterator);
|
||||
final List<E> eleList = ListUtil.of(iterator);
|
||||
this.listIterator = eleList.iterator();
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ public class IterUtil {
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public static <E> List<E> toList(final Iterator<E> iter) {
|
||||
return ListUtil.toList(iter);
|
||||
return ListUtil.of(iter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1849,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 = ListUtil.toList((Iterable<DateTime>) start);
|
||||
final List<DateTime> endDateTimes = ListUtil.toList((Iterable<DateTime>) end);
|
||||
final List<DateTime> startDateTimes = ListUtil.of((Iterable<DateTime>) start);
|
||||
final List<DateTime> endDateTimes = ListUtil.of((Iterable<DateTime>) end);
|
||||
return startDateTimes.stream().filter(endDateTimes::contains).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -1864,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 = ListUtil.toList((Iterable<DateTime>) start);
|
||||
final List<DateTime> endDateTimes = ListUtil.toList((Iterable<DateTime>) end);
|
||||
final List<DateTime> startDateTimes = ListUtil.of((Iterable<DateTime>) start);
|
||||
final List<DateTime> endDateTimes = ListUtil.of((Iterable<DateTime>) end);
|
||||
return endDateTimes.stream().filter(item -> !startDateTimes.contains(item)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -1916,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 ListUtil.toList((Iterable<DateTime>) range(start, end, unit));
|
||||
return ListUtil.of((Iterable<DateTime>) range(start, end, unit));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1930,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 ListUtil.toList((Iterable<DateTime>) new DateRange(start, end, unit, step));
|
||||
return ListUtil.of((Iterable<DateTime>) new DateRange(start, end, unit, step));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
|
||||
* @param resources 资源数组
|
||||
*/
|
||||
public MultiResource(final Resource... resources) {
|
||||
this(ListUtil.toList(resources));
|
||||
this(ListUtil.of(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 = ListUtil.toList(resources);
|
||||
this.resources = ListUtil.of(resources);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class WatcherChain implements Watcher, Chain<Watcher, WatcherChain>{
|
||||
* @param watchers 观察者列表
|
||||
*/
|
||||
public WatcherChain(final Watcher... watchers) {
|
||||
chain = ListUtil.toList(watchers);
|
||||
chain = ListUtil.of(watchers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,7 +64,7 @@ public class Tuple extends CloneSupport<Tuple> implements Iterable<Object>, Seri
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public final List<Object> toList() {
|
||||
return ListUtil.toList(this.members);
|
||||
return ListUtil.of(this.members);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 = SetUtil.newHashSet(withoutNames);
|
||||
final HashSet<String> withoutSet = SetUtil.of(withoutNames);
|
||||
for (final Map.Entry<String, Object> entry : dict.entrySet()) {
|
||||
if (withoutSet.contains(entry.getKey())) {
|
||||
continue;
|
||||
|
@ -409,7 +409,7 @@ public class MapUtil {
|
||||
key = entry.getKey();
|
||||
valueList = resultMap.get(key);
|
||||
if (null == valueList) {
|
||||
valueList = ListUtil.toList(entry.getValue());
|
||||
valueList = ListUtil.of(entry.getValue());
|
||||
resultMap.put(key, valueList);
|
||||
} else {
|
||||
valueList.add(entry.getValue());
|
||||
@ -464,7 +464,7 @@ public class MapUtil {
|
||||
List<V> vList;
|
||||
int vListSize;
|
||||
for (final Entry<K, ? extends Iterable<V>> entry : listMap.entrySet()) {
|
||||
vList = ListUtil.toList(entry.getValue());
|
||||
vList = ListUtil.of(entry.getValue());
|
||||
vListSize = vList.size();
|
||||
if (index < vListSize) {
|
||||
map.put(entry.getKey(), vList.get(index));
|
||||
|
@ -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 = ListUtil.toList(keys);
|
||||
this.values = ListUtil.toList(values);
|
||||
this.keys = ListUtil.of(keys);
|
||||
this.values = ListUtil.of(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +67,7 @@ public class Ipv4Util {
|
||||
final String[] param = StrUtil.splitToArray(ipRange, IP_MASK_SPLIT_MARK);
|
||||
return list(param[0], Integer.parseInt(param[1]), isAll);
|
||||
} else {
|
||||
return ListUtil.toList(ipRange);
|
||||
return ListUtil.of(ipRange);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class MethodUtil {
|
||||
* @return 过滤后的方法列表
|
||||
*/
|
||||
public static Method[] getPublicMethods(final Class<?> clazz, final Method... excludeMethods) {
|
||||
final HashSet<Method> excludeMethodSet = SetUtil.newHashSet(excludeMethods);
|
||||
final HashSet<Method> excludeMethodSet = SetUtil.of(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 = SetUtil.newHashSet(excludeMethodNames);
|
||||
final HashSet<String> excludeMethodNameSet = SetUtil.of(excludeMethodNames);
|
||||
return getPublicMethods(clazz, method -> false == excludeMethodNameSet.contains(method.getName()));
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class ReUtil {
|
||||
/**
|
||||
* 正则中需要被转义的关键字
|
||||
*/
|
||||
public final static Set<Character> RE_KEYS = SetUtil.newHashSet('$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|');
|
||||
public final static Set<Character> RE_KEYS = SetUtil.of('$', '(', ')', '*', '+', '.', '[', ']', '?', '\\', '^', '{', '}', '|');
|
||||
|
||||
/**
|
||||
* 获得匹配的字符串,获得正则中分组0的内容
|
||||
|
@ -11,7 +11,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class StopChar {
|
||||
/** 不需要处理的词,如标点符号、空格等 */
|
||||
public static final Set<Character> STOP_WORD = SetUtil.newHashSet(' ', '\'', '、', '。', //
|
||||
public static final Set<Character> STOP_WORD = SetUtil.of(' ', '\'', '、', '。', //
|
||||
'·', 'ˉ', 'ˇ', '々', '—', '~', '‖', '…', '‘', '’', '“', '”', '〔', '〕', '〈', '〉', '《', '》', '「', '」', '『', //
|
||||
'』', '〖', '〗', '【', '】', '±', '+', '-', '×', '÷', '∧', '∨', '∑', '∏', '∪', '∩', '∈', '√', '⊥', '⊙', '∫', //
|
||||
'∮', '≡', '≌', '≈', '∽', '∝', '≠', '≮', '≯', '≤', '≥', '∞', '∶', '∵', '∴', '∷', '♂', '♀', '°', '′', '〃', //
|
||||
|
@ -86,7 +86,7 @@ public class WordTree extends HashMap<Character, WordTree> {
|
||||
* @return this
|
||||
*/
|
||||
public WordTree addWords(final String... words) {
|
||||
for (final String word : SetUtil.newHashSet(words)) {
|
||||
for (final String word : SetUtil.of(words)) {
|
||||
addWord(word);
|
||||
}
|
||||
return this;
|
||||
|
@ -1288,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(ListUtil.toList(iterator), componentType);
|
||||
return toArray(ListUtil.of(iterator), componentType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import java.util.Set;
|
||||
public class BooleanUtil {
|
||||
|
||||
/** 表示为真的字符串 */
|
||||
private static final Set<String> TRUE_SET = SetUtil.newHashSet("true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√");
|
||||
private static final Set<String> TRUE_SET = SetUtil.of("true", "yes", "y", "t", "ok", "1", "on", "是", "对", "真", "對", "√");
|
||||
|
||||
/**
|
||||
* 取相反值
|
||||
|
@ -445,7 +445,7 @@ public class RandomUtil {
|
||||
*/
|
||||
public static <T> List<T> randomEleList(final List<T> source, final int count) {
|
||||
if (count >= source.size()) {
|
||||
return ListUtil.toList(source);
|
||||
return ListUtil.of(source);
|
||||
}
|
||||
final int[] randomList = ArrayUtil.sub(randomInts(source.size()), 0, count);
|
||||
final List<T> result = new ArrayList<>();
|
||||
|
@ -102,6 +102,6 @@ public class ServiceLoaderUtil {
|
||||
* @since 5.4.2
|
||||
*/
|
||||
public static <T> List<T> loadList(final Class<T> clazz, final ClassLoader loader) {
|
||||
return ListUtil.list(false, load(clazz, loader));
|
||||
return ListUtil.of(false, load(clazz, loader));
|
||||
}
|
||||
}
|
||||
|
@ -1109,7 +1109,7 @@ public class XmlUtil {
|
||||
if (value instanceof List) {
|
||||
((List<Object>) value).add(newValue);
|
||||
} else {
|
||||
result.put(childEle.getNodeName(), ListUtil.toList(value, newValue));
|
||||
result.put(childEle.getNodeName(), ListUtil.of(value, newValue));
|
||||
}
|
||||
} else {
|
||||
result.put(childEle.getNodeName(), newValue);
|
||||
|
@ -285,7 +285,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPropertyDescriptorsTest() {
|
||||
final HashSet<Object> set = SetUtil.newHashSet();
|
||||
final HashSet<Object> set = SetUtil.of();
|
||||
final PropertyDescriptor[] propertyDescriptors = BeanUtil.getPropertyDescriptors(SubPerson.class);
|
||||
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
set.add(propertyDescriptor.getName());
|
||||
@ -326,7 +326,7 @@ public class BeanUtilTest {
|
||||
student.setAge(125);
|
||||
student.setNo(8848L);
|
||||
|
||||
final List<Student> studentList = ListUtil.of(student, student2);
|
||||
final List<Student> studentList = ListUtil.view(student, student2);
|
||||
|
||||
for (int i=0;i<5000;i++){
|
||||
new Thread(()->{
|
||||
@ -633,7 +633,7 @@ public class BeanUtilTest {
|
||||
student.setAge(125);
|
||||
student.setNo(8848L);
|
||||
|
||||
final List<Student> studentList = ListUtil.of(student, student2);
|
||||
final List<Student> studentList = ListUtil.view(student, student2);
|
||||
final List<Person> people = BeanUtil.copyToList(studentList, Person.class);
|
||||
|
||||
Assert.assertEquals(studentList.size(), people.size());
|
||||
@ -759,7 +759,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void issueI41WKPTest(){
|
||||
final Test1 t1 = new Test1().setStrList(ListUtil.toList("list"));
|
||||
final Test1 t1 = new Test1().setStrList(ListUtil.of("list"));
|
||||
final Test2 t2_hu = new Test2();
|
||||
BeanUtil.copyProperties(t1, t2_hu, CopyOptions.create().setIgnoreError(true));
|
||||
Assert.assertNull(t2_hu.getStrList());
|
||||
|
@ -35,22 +35,22 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void testPredicateContains() {
|
||||
final ArrayList<String> list = ListUtil.toList("bbbbb", "aaaaa", "ccccc");
|
||||
final ArrayList<String> list = ListUtil.of("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 = ListUtil.toList(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = ListUtil.toList(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = ListUtil.toList(1);
|
||||
ArrayList<Integer> list = ListUtil.of(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = ListUtil.of(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = ListUtil.of(1);
|
||||
|
||||
List<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
Assert.assertEquals(resultList, exceptResultList);
|
||||
|
||||
list = ListUtil.toList(1, 2, 3);
|
||||
list = ListUtil.of(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 = ListUtil.toList();
|
||||
List<String> answerList = ListUtil.toList("a", "b");
|
||||
List<String> srcList = ListUtil.of();
|
||||
List<String> answerList = ListUtil.of("a", "b");
|
||||
CollUtil.padLeft(srcList, 1, "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = ListUtil.toList("a", "b");
|
||||
answerList = ListUtil.toList("a", "b");
|
||||
srcList = ListUtil.of("a", "b");
|
||||
answerList = ListUtil.of("a", "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = ListUtil.toList("c");
|
||||
answerList = ListUtil.toList("a", "a", "c");
|
||||
srcList = ListUtil.of("c");
|
||||
answerList = ListUtil.of("a", "a", "c");
|
||||
CollUtil.padLeft(srcList, 3, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPadRight() {
|
||||
final List<String> srcList = ListUtil.toList("a");
|
||||
final List<String> answerList = ListUtil.toList("a", "b", "b", "b", "b");
|
||||
final List<String> srcList = ListUtil.of("a");
|
||||
final List<String> answerList = ListUtil.of("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 = SetUtil.newHashSet((String[]) null);
|
||||
final Set<String> set = SetUtil.of((String[]) null);
|
||||
Assert.assertNotNull(set);
|
||||
}
|
||||
|
||||
@ -114,8 +114,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void unionTest() {
|
||||
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> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = 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 ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list3 = ListUtil.of();
|
||||
|
||||
final Collection<String> intersectionDistinct = CollUtil.intersectionDistinct(list1, list2);
|
||||
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
|
||||
Assert.assertEquals(SetUtil.ofLinked("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 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = ListUtil.toList();
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.of();
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = ListUtil.toList("1", "2", "3");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "c");
|
||||
final ArrayList<String> list1 = ListUtil.of("1", "2", "3");
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final List<String> list1 = ListUtil.of("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = ListUtil.of("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 = ListUtil.toList(map1, map2);
|
||||
final ArrayList<HashMap<String, String>> list = ListUtil.of(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 = ListUtil.toList(v1, v2);
|
||||
final ArrayList<Dict> list = ListUtil.of(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 = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final ArrayList<Integer> list = ListUtil.of(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 = ListUtil.toList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c");
|
||||
|
||||
final Collection<String> filtered = CollUtil.edit(list, t -> t + 1);
|
||||
|
||||
Assert.assertEquals(ListUtil.toList("a1", "b1", "c1"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a1", "b1", "c1"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest2() {
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> false == "a".equals(t));
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(ListUtil.toList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterSetTest() {
|
||||
final Set<String> set = SetUtil.newLinkedHashSet("a", "b", "", " ", "c");
|
||||
final Set<String> set = SetUtil.ofLinked("a", "b", "", " ", "c");
|
||||
final Set<String> filtered = CollUtil.filter(set, StrUtil::isNotBlank);
|
||||
|
||||
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(SetUtil.ofLinked("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterRemoveTest() {
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.of("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(ListUtil.toList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeNullTest() {
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeNull(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c", "", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c", "", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeEmptyTest() {
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeEmpty(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeBlankTest() {
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.of("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeBlank(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.of("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupTest() {
|
||||
final List<String> list = ListUtil.toList("1", "2", "3", "4", "5", "6");
|
||||
final List<String> list = ListUtil.of("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(ListUtil.toList("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(ListUtil.toList("1", "3", "5"), group2.get(1));
|
||||
Assert.assertEquals(ListUtil.of("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(ListUtil.of("1", "3", "5"), group2.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupByFieldTest() {
|
||||
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<TestBean> list = ListUtil.of(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 = ListUtil.toList(
|
||||
final List<TestBean> list = ListUtil.of(
|
||||
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 = ListUtil.toList(
|
||||
final List<TestBean> list = ListUtil.of(
|
||||
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 = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.of(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 = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.of(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 = ListUtil.list(false);
|
||||
final List<Object> list2 = ListUtil.list(true);
|
||||
final List<Object> list1 = ListUtil.of(false);
|
||||
final List<Object> list2 = ListUtil.of(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 = ListUtil.list(false, "a", "b", "c");
|
||||
final List<String> list2 = ListUtil.list(true, "a", "b", "c");
|
||||
final List<String> list1 = ListUtil.of( "a", "b", "c");
|
||||
final List<String> list2 = ListUtil.ofLinked( "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 = ListUtil.list(false, set);
|
||||
final List<String> list2 = ListUtil.list(true, set);
|
||||
final List<String> list1 = ListUtil.of(false, set);
|
||||
final List<String> list2 = ListUtil.of(true, set);
|
||||
Assert.assertEquals("[a, b, c]", list1.toString());
|
||||
Assert.assertEquals("[a, b, c]", list2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.ofLinked("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 = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> sortPageAll = CollUtil.sortPageAll(1, 5, Comparator.reverseOrder(), list);
|
||||
|
||||
Assert.assertEquals(ListUtil.toList(4, 3, 2, 1), sortPageAll);
|
||||
Assert.assertEquals(ListUtil.of(4, 3, 2, 1), sortPageAll);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAnyTest() {
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1, 9, 11);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.of(5, 3, 1, 9, 11);
|
||||
|
||||
Assert.assertTrue(CollUtil.containsAny(list1, list2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAllTest() {
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.of(5, 3, 1);
|
||||
Assert.assertTrue(CollUtil.containsAll(list1, list2));
|
||||
|
||||
final ArrayList<Integer> list3 = ListUtil.toList(1);
|
||||
final ArrayList<Integer> list4 = ListUtil.toList();
|
||||
final ArrayList<Integer> list3 = ListUtil.of(1);
|
||||
final ArrayList<Integer> list4 = ListUtil.of();
|
||||
Assert.assertTrue(CollUtil.containsAll(list3, list4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastTest() {
|
||||
// 测试:空数组返回null而不是报错
|
||||
final List<String> test = ListUtil.toList();
|
||||
final List<String> test = ListUtil.of();
|
||||
final String last = CollUtil.getLast(test);
|
||||
Assert.assertNull(last);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zipTest() {
|
||||
final Collection<String> keys = ListUtil.toList("a", "b", "c", "d");
|
||||
final Collection<Integer> values = ListUtil.toList(1, 2, 3, 4);
|
||||
final Collection<String> keys = ListUtil.of("a", "b", "c", "d");
|
||||
final Collection<Integer> values = ListUtil.of(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 = ListUtil.toList("a", "b", "c", "d");
|
||||
final Collection<String> keys = ListUtil.of("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 = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("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 = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("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 = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.of("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 = SetUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
|
||||
final Set<String> list = SetUtil.ofLinked("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 = ListUtil.toList();
|
||||
final List<Dict> objects = ListUtil.of();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
objects.add(Dict.create().set("name", "姓名:" + i));
|
||||
}
|
||||
@ -832,7 +832,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortComparableTest() {
|
||||
final List<String> of = ListUtil.toList("a", "c", "b");
|
||||
final List<String> of = ListUtil.of("a", "c", "b");
|
||||
final List<String> sort = CollUtil.sort(of, new ComparableComparator<>());
|
||||
Assert.assertEquals("a,b,c", CollUtil.join(sort, ","));
|
||||
}
|
||||
@ -880,8 +880,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void distinctTest(){
|
||||
final ArrayList<Integer> distinct = CollUtil.distinct(ListUtil.of(5, 3, 10, 9, 0, 5, 10, 9));
|
||||
Assert.assertEquals(ListUtil.of(5, 3, 10, 9, 0), distinct);
|
||||
final ArrayList<Integer> distinct = CollUtil.distinct(ListUtil.view(5, 3, 10, 9, 0, 5, 10, 9));
|
||||
Assert.assertEquals(ListUtil.view(5, 3, 10, 9, 0), distinct);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -17,20 +17,20 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link IterUtil} 单元测试
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getFirstNonNullTest(){
|
||||
final ArrayList<String> strings = ListUtil.toList(null, null, "123", "456", null);
|
||||
public void getFirstNonNullTest() {
|
||||
final ArrayList<String> strings = ListUtil.of(null, null, "123", "456", null);
|
||||
Assert.assertEquals("123", IterUtil.getFirstNoneNull(strings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldValueMapTest() {
|
||||
final ArrayList<Car> carList = ListUtil.toList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
|
||||
final ArrayList<Car> carList = ListUtil.of(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 = ListUtil.toList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("1", "2", "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4);
|
||||
final ArrayList<Integer> list1 = ListUtil.of(1, 2, 3, 4);
|
||||
final String join1 = IterUtil.join(list1.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join1);
|
||||
|
||||
// 包装每个节点
|
||||
final ArrayList<String> list2 = ListUtil.toList("1", "2", "3", "4");
|
||||
final ArrayList<String> list2 = ListUtil.of("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 = ListUtil.toList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("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 = ListUtil.toList("1", null, "3", "4");
|
||||
final ArrayList<String> list = ListUtil.of("1", null, "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:null:3:4", join);
|
||||
}
|
||||
@ -94,10 +94,10 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getElementTypeTest(){
|
||||
public void getElementTypeTest() {
|
||||
final List<Integer> integers = Arrays.asList(null, 1);
|
||||
final Class<?> elementType = IterUtil.getElementType(integers);
|
||||
Assert.assertEquals(Integer.class,elementType);
|
||||
Assert.assertEquals(Integer.class, elementType);
|
||||
}
|
||||
|
||||
@Data
|
||||
@ -108,9 +108,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filterTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
IterUtil.filter(obj.iterator(), obj2::contains);
|
||||
|
||||
@ -119,9 +119,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filteredTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filteredTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
final FilterIter<String> filtered = IterUtil.filtered(obj.iterator(), obj2::contains);
|
||||
|
||||
@ -130,9 +130,9 @@ public class IterUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterToListTest(){
|
||||
final List<String> obj2 = ListUtil.toList("3");
|
||||
final List<String> obj = ListUtil.toList("1", "3");
|
||||
public void filterToListTest() {
|
||||
final List<String> obj2 = ListUtil.of("3");
|
||||
final List<String> obj = ListUtil.of("1", "3");
|
||||
|
||||
final List<String> filtered = IterUtil.filterToList(obj.iterator(), obj2::contains);
|
||||
|
||||
@ -142,7 +142,7 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.ofLinked("A", "B", "C", "D");
|
||||
final String str = IterUtil.get(set.iterator(), 2);
|
||||
Assert.assertEquals("C", str);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void editTest() {
|
||||
final List<String> a = ListUtil.toLinkedList("1", "2", "3");
|
||||
final List<String> a = ListUtil.ofLinked("1", "2", "3");
|
||||
final List<String> filter = (List<String>) CollUtil.edit(a, str -> "edit" + str);
|
||||
Assert.assertEquals("edit1", filter.get(0));
|
||||
Assert.assertEquals("edit2", filter.get(1));
|
||||
@ -96,16 +96,16 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void indexOfAll() {
|
||||
final List<String> a = ListUtil.toLinkedList("1", "2", "3", "4", "3", "2", "1");
|
||||
final int[] indexArray = ListUtil.indexOfAll(a, "2"::equals);
|
||||
final List<String> a = ListUtil.ofLinked("1", "2", "3", "4", "3", "2", "1");
|
||||
final int[] indexArray = CollUtil.indexOfAll(a, "2"::equals);
|
||||
Assert.assertArrayEquals(new int[]{1,5}, indexArray);
|
||||
final int[] indexArray2 = ListUtil.indexOfAll(a, "1"::equals);
|
||||
final int[] indexArray2 = CollUtil.indexOfAll(a, "1"::equals);
|
||||
Assert.assertArrayEquals(new int[]{0,6}, indexArray2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pageTest() {
|
||||
final List<Integer> a = ListUtil.toLinkedList(1, 2, 3,4,5);
|
||||
final List<Integer> a = ListUtil.ofLinked(1, 2, 3,4,5);
|
||||
|
||||
PageUtil.setFirstPageNo(1);
|
||||
final int[] a_1 = ListUtil.page(1,2,a).stream().mapToInt(Integer::valueOf).toArray();
|
||||
@ -174,7 +174,7 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void subTest() {
|
||||
final List<Integer> of = ListUtil.of(1, 2, 3, 4);
|
||||
final List<Integer> of = ListUtil.view(1, 2, 3, 4);
|
||||
final List<Integer> sub = ListUtil.sub(of, 2, 4);
|
||||
sub.remove(0);
|
||||
|
||||
@ -192,7 +192,7 @@ public class ListUtilTest {
|
||||
private String name;
|
||||
}
|
||||
|
||||
final List<TestBean> beanList = ListUtil.toList(
|
||||
final List<TestBean> beanList = ListUtil.of(
|
||||
new TestBean(2, "test2"),
|
||||
new TestBean(1, "test1"),
|
||||
new TestBean(5, "test5"),
|
||||
|
@ -22,7 +22,7 @@ public class PartitionIterTest {
|
||||
|
||||
@Test
|
||||
public void iterMaxTest() {
|
||||
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 0, 12, 45, 12);
|
||||
final List<Integer> list = ListUtil.view(1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 0, 12, 45, 12);
|
||||
final PartitionIter<Integer> iter = new PartitionIter<>(list.iterator(), 3);
|
||||
int max = 0;
|
||||
for (final List<Integer> lines : iter) {
|
||||
|
@ -19,10 +19,10 @@ public class CompareUtilTest {
|
||||
|
||||
@Test
|
||||
public void comparingPinyin() {
|
||||
final List<String> list = ListUtil.toList("成都", "北京", "上海", "深圳");
|
||||
final List<String> list = ListUtil.of("成都", "北京", "上海", "深圳");
|
||||
|
||||
final List<String> ascendingOrderResult = ListUtil.of("北京", "成都", "上海", "深圳");
|
||||
final List<String> descendingOrderResult = ListUtil.of("深圳", "上海", "成都", "北京");
|
||||
final List<String> ascendingOrderResult = ListUtil.view("北京", "成都", "上海", "深圳");
|
||||
final List<String> descendingOrderResult = ListUtil.view("深圳", "上海", "成都", "北京");
|
||||
|
||||
// 正序
|
||||
list.sort(CompareUtil.comparingPinyin(e -> e));
|
||||
|
@ -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(SetUtil.set(false, 1,2,3), result);
|
||||
Assert.assertEquals(SetUtil.of(1,2,3), result);
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
@ -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 = ListUtil.toList(set);
|
||||
final ArrayList<?> list = ListUtil.of(set);
|
||||
Assert.assertEquals("a", list.get(0));
|
||||
Assert.assertEquals("你", list.get(1));
|
||||
Assert.assertEquals("好", list.get(2));
|
||||
|
@ -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 = ListUtil.list(false, yearAndQuarters);
|
||||
final List<String> list = ListUtil.of(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 = ListUtil.list(false, yearAndQuarters2);
|
||||
final List<String> list2 = ListUtil.of(false, yearAndQuarters2);
|
||||
Assert.assertEquals(1, list2.size());
|
||||
Assert.assertEquals("20184", list2.get(0));
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ public class FileUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void appendLinesTest(){
|
||||
final List<String> list = ListUtil.toList("a", "b", "c");
|
||||
final List<String> list = ListUtil.of("a", "b", "c");
|
||||
FileUtil.appendLines(list, FileUtil.file("d:/test/appendLines.txt"), CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,6 @@ public class WeightRandomTest {
|
||||
random.add("C", 100);
|
||||
|
||||
final String result = random.next();
|
||||
Assert.assertTrue(ListUtil.toList("A", "B", "C").contains(result));
|
||||
Assert.assertTrue(ListUtil.of("A", "B", "C").contains(result));
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ public class StrJoinerTest {
|
||||
@Test
|
||||
public void joinMultiArrayTest(){
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
append.append(new Object[]{ListUtil.of("1", "2"),
|
||||
SetUtil.newLinkedHashSet("3", "4")
|
||||
append.append(new Object[]{ListUtil.view("1", "2"),
|
||||
SetUtil.ofLinked("3", "4")
|
||||
});
|
||||
Assert.assertEquals("1,2,3,4", append.toString());
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
|
||||
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, false);
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ public class DfaTest {
|
||||
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, false);
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅", "出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配
|
||||
// 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, true);
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "土^豆", "刚出锅"));
|
||||
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, true);
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.of("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class DfaTest {
|
||||
tree.addWord("tio");
|
||||
|
||||
final List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
|
||||
Assert.assertEquals(all, ListUtil.toList("t-io"));
|
||||
Assert.assertEquals(all, ListUtil.of("t-io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -34,7 +34,7 @@ public class SensitiveUtilTest {
|
||||
|
||||
@Test
|
||||
public void issue2126(){
|
||||
SensitiveUtil.init(ListUtil.of("赵", "赵阿", "赵阿三"));
|
||||
SensitiveUtil.init(ListUtil.view("赵", "赵阿", "赵阿三"));
|
||||
|
||||
final String result = SensitiveUtil.sensitiveFilter("赵阿三在做什么。", true, null);
|
||||
Assert.assertEquals("***在做什么。", result);
|
||||
|
@ -1,8 +1,6 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.TreeUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -13,7 +11,7 @@ public class Issue2279Test {
|
||||
|
||||
@Test
|
||||
public void buildSingleTest() {
|
||||
final List<TestTree> list = ListUtil.of(
|
||||
final List<TestTree> list = ListUtil.view(
|
||||
// 模拟数据
|
||||
new TestTree(1, 0, 1, 1),
|
||||
new TestTree(2, 1, 2, 2),
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TreeTest {
|
||||
// 模拟数据
|
||||
static List<TreeNode<String>> nodeList = ListUtil.toList();
|
||||
static List<TreeNode<String>> nodeList = ListUtil.of();
|
||||
|
||||
static {
|
||||
// 模拟数据
|
||||
|
@ -323,7 +323,7 @@ public class ArrayUtilTest {
|
||||
|
||||
@Test
|
||||
public void toArrayTest() {
|
||||
final ArrayList<String> list = ListUtil.toList("A", "B", "C", "D");
|
||||
final ArrayList<String> list = ListUtil.of("A", "B", "C", "D");
|
||||
final String[] array = ArrayUtil.toArray(list, String.class);
|
||||
Assert.assertEquals("A", array[0]);
|
||||
Assert.assertEquals("B", array[1]);
|
||||
|
@ -18,13 +18,13 @@ public class EnumUtilTest {
|
||||
@Test
|
||||
public void getNamesTest() {
|
||||
final List<String> names = EnumUtil.getNames(TestEnum.class);
|
||||
Assert.assertEquals(ListUtil.toList("TEST1", "TEST2", "TEST3"), names);
|
||||
Assert.assertEquals(ListUtil.of("TEST1", "TEST2", "TEST3"), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFieldValuesTest() {
|
||||
final List<Object> types = EnumUtil.getFieldValues(TestEnum.class, "type");
|
||||
Assert.assertEquals(ListUtil.toList("type1", "type2", "type3"), types);
|
||||
Assert.assertEquals(ListUtil.of("type1", "type2", "type3"), types);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -58,7 +58,7 @@ public class ObjectUtilTest {
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final ArrayList<String> strings = ListUtil.toList("1", "2");
|
||||
final ArrayList<String> strings = ListUtil.of("1", "2");
|
||||
final String result = ObjUtil.toString(strings);
|
||||
Assert.assertEquals("[1, 2]", result);
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ public class RandomUtilTest {
|
||||
|
||||
@Test
|
||||
public void randomEleSetTest(){
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(ListUtil.of(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(set.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomElesTest(){
|
||||
final List<Integer> result = RandomUtil.randomEles(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
|
||||
final List<Integer> result = RandomUtil.randomEles(ListUtil.of(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(result.size(), 2);
|
||||
}
|
||||
|
||||
|
@ -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 = ListUtil.toList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
final ArrayList<String> expected = ListUtil.of("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
Assert.assertEquals(expected, resultFindAll);
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class XmlUtilTest {
|
||||
final Map<String, Object> map = XmlUtil.xmlToMap(xml);
|
||||
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertEquals(ListUtil.toList("张三", "李四"), map.get("name"));
|
||||
Assert.assertEquals(ListUtil.of("张三", "李四"), map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -138,7 +138,7 @@ public class XmlUtilTest {
|
||||
public void mapToXmlTest2() {
|
||||
// 测试List
|
||||
final Map<String, Object> map = MapBuilder.create(new LinkedHashMap<String, Object>())
|
||||
.put("Town", ListUtil.toList("town1", "town2"))
|
||||
.put("Town", ListUtil.of("town1", "town2"))
|
||||
.build();
|
||||
|
||||
final Document doc = XmlUtil.mapToXml(map, "City");
|
||||
@ -158,7 +158,7 @@ public class XmlUtilTest {
|
||||
|
||||
@Test
|
||||
public void readBySaxTest(){
|
||||
final Set<String> eles = SetUtil.newHashSet(
|
||||
final Set<String> eles = SetUtil.of(
|
||||
"returnsms", "returnstatus", "message", "remainpoint", "taskID", "successCounts");
|
||||
XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){
|
||||
@Override
|
||||
|
@ -554,7 +554,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
||||
* @throws DbRuntimeException SQL执行异常
|
||||
*/
|
||||
public <T> T find(final Entity where, final RsHandler<T> rsh, final String... fields) throws DbRuntimeException {
|
||||
return find(ListUtil.toList(fields), where, rsh);
|
||||
return find(ListUtil.of(fields), where, rsh);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,7 +156,7 @@ public class Entity extends Dict {
|
||||
*/
|
||||
public Entity setFieldNames(final Collection<String> fieldNames) {
|
||||
if (CollUtil.isNotEmpty(fieldNames)) {
|
||||
this.fieldNames = SetUtil.newHashSet(true, fieldNames);
|
||||
this.fieldNames = SetUtil.of(true, fieldNames);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -169,7 +169,7 @@ public class Entity extends Dict {
|
||||
*/
|
||||
public Entity setFieldNames(final String... fieldNames) {
|
||||
if (ArrayUtil.isNotEmpty(fieldNames)) {
|
||||
this.fieldNames = SetUtil.newLinkedHashSet(fieldNames);
|
||||
this.fieldNames = SetUtil.ofLinked(fieldNames);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public interface Dialect extends Serializable {
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
default PreparedStatement psForCount(final Connection conn, final Query query) throws SQLException {
|
||||
return psForFind(conn, query.clone().setFields(ListUtil.toList("count(1)")));
|
||||
return psForFind(conn, query.clone().setFields(ListUtil.of("count(1)")));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,7 +272,7 @@ public class MetaUtil {
|
||||
indexInfo.getColumnIndexInfoList().add(ColumnIndexInfo.create(rs));
|
||||
}
|
||||
}
|
||||
table.setIndexInfoList(ListUtil.toList(indexInfoMap.values()));
|
||||
table.setIndexInfoList(ListUtil.of(indexInfoMap.values()));
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
throw new DbRuntimeException("Get columns error!", e);
|
||||
|
@ -55,7 +55,7 @@ public class ConditionBuilder implements Builder<String> {
|
||||
* @return 参数列表
|
||||
*/
|
||||
public List<Object> getParamValues() {
|
||||
return ListUtil.unmodifiable(this.paramValues);
|
||||
return ListUtil.view(this.paramValues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ public class Query implements Cloneable {
|
||||
* @return this
|
||||
*/
|
||||
public Query setFields(final String... fields) {
|
||||
this.fields = ListUtil.toList(fields);
|
||||
this.fields = ListUtil.of(fields);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class CRUDTest {
|
||||
|
||||
@Test
|
||||
public void findTest() {
|
||||
final List<Entity> find = db.find(ListUtil.toList("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
final List<Entity> find = db.find(ListUtil.of("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
Assert.assertFalse(find.isEmpty());
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ public class CRUDTest {
|
||||
Console.log(data1);
|
||||
Console.log(data2);
|
||||
|
||||
final int[] result = db.insert(ListUtil.toList(data1, data2));
|
||||
final int[] result = db.insert(ListUtil.of(data1, data2));
|
||||
Console.log(result);
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ public class CRUDTest {
|
||||
|
||||
Console.log(data1);
|
||||
|
||||
final int[] result = db.insert(ListUtil.toList(data1));
|
||||
final int[] result = db.insert(ListUtil.of(data1));
|
||||
Console.log(result);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class ConcurentTest {
|
||||
for(int i = 0; i < 10000; i++) {
|
||||
ThreadUtil.execute(() -> {
|
||||
final List<Entity> find;
|
||||
find = db.find(ListUtil.toList("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
find = db.find(ListUtil.of("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
Console.log(find);
|
||||
});
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class PicTransferTest {
|
||||
@Ignore
|
||||
public void findTest() {
|
||||
Db.of().find(
|
||||
ListUtil.of("NAME", "TYPE", "GROUP", "PIC"),
|
||||
ListUtil.view("NAME", "TYPE", "GROUP", "PIC"),
|
||||
Entity.create("PIC_INFO").set("TYPE", 1),
|
||||
rs -> {
|
||||
while(rs.next()){
|
||||
|
@ -27,7 +27,7 @@ public class MetaUtilTest {
|
||||
@Test
|
||||
public void getTableMetaTest() {
|
||||
final Table table = MetaUtil.getTableMeta(ds, "user");
|
||||
Assert.assertEquals(SetUtil.newHashSet("id"), table.getPkNames());
|
||||
Assert.assertEquals(SetUtil.of("id"), table.getPkNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -23,6 +23,6 @@ public class ConditionGroupTest {
|
||||
final ConditionBuilder conditionBuilder = ConditionBuilder.of(cg2, condition4);
|
||||
|
||||
Assert.assertEquals("((a = ? OR b = ?) AND c = ?) AND d = ?", conditionBuilder.build());
|
||||
Assert.assertEquals(ListUtil.of("A", "B", "C", "D"), conditionBuilder.getParamValues());
|
||||
Assert.assertEquals(ListUtil.view("A", "B", "C", "D"), conditionBuilder.getParamValues());
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ public class MailUtil {
|
||||
} else if (StrUtil.contains(addresses, ';')) {
|
||||
result = StrUtil.splitTrim(addresses, ';');
|
||||
} else {
|
||||
result = ListUtil.toList(addresses);
|
||||
result = ListUtil.of(addresses);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class RootAction implements Action {
|
||||
*/
|
||||
public RootAction(final File rootDir, final String... indexFileNames) {
|
||||
this.rootDir = rootDir;
|
||||
this.indexFileNames = ListUtil.toList(indexFileNames);
|
||||
this.indexFileNames = ListUtil.of(indexFileNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,7 @@ public class Browser extends UserAgentInfo {
|
||||
/**
|
||||
* 支持的浏览器类型
|
||||
*/
|
||||
public static final List<Browser> browers = ListUtil.toList(
|
||||
public static final List<Browser> browers = ListUtil.of(
|
||||
// 部分特殊浏览器是基于安卓、Iphone等的,需要优先判断
|
||||
// 企业微信 企业微信使用微信浏览器内核,会包含 MicroMessenger 所以要放在前面
|
||||
new Browser("wxwork", "wxwork", "wxwork\\/([\\d\\w\\.\\-]+)"),
|
||||
|
@ -21,7 +21,7 @@ public class Engine extends UserAgentInfo {
|
||||
/**
|
||||
* 支持的引擎类型
|
||||
*/
|
||||
public static final List<Engine> engines = ListUtil.of(
|
||||
public static final List<Engine> engines = ListUtil.view(
|
||||
new Engine("Trident", "trident"),
|
||||
new Engine("Webkit", "webkit"),
|
||||
new Engine("Chrome", "chrome"),
|
||||
|
@ -23,7 +23,7 @@ public class OS extends UserAgentInfo {
|
||||
/**
|
||||
* 支持的引擎类型
|
||||
*/
|
||||
public static final List<OS> oses = ListUtil.of(//
|
||||
public static final List<OS> oses = ListUtil.view(//
|
||||
new OS("Windows 10 or Windows Server 2016", "windows nt 10\\.0", "windows nt (10\\.0)"),//
|
||||
new OS("Windows 8.1 or Windows Server 2012R2", "windows nt 6\\.3", "windows nt (6\\.3)"),//
|
||||
new OS("Windows 8 or Windows Server 2012", "windows nt 6\\.2", "windows nt (6\\.2)"),//
|
||||
|
@ -49,7 +49,7 @@ public class Platform extends UserAgentInfo {
|
||||
/**
|
||||
* 支持的移动平台类型
|
||||
*/
|
||||
public static final List<Platform> mobilePlatforms = ListUtil.of(//
|
||||
public static final List<Platform> mobilePlatforms = ListUtil.view(//
|
||||
WINDOWS_PHONE, //
|
||||
IPAD, //
|
||||
IPOD, //
|
||||
@ -65,7 +65,7 @@ public class Platform extends UserAgentInfo {
|
||||
/**
|
||||
* 支持的桌面平台类型
|
||||
*/
|
||||
public static final List<Platform> desktopPlatforms = ListUtil.of(//
|
||||
public static final List<Platform> desktopPlatforms = ListUtil.view(//
|
||||
new Platform("Windows", "windows"), //
|
||||
new Platform("Mac", "(macintosh|darwin)"), //
|
||||
new Platform("Linux", "linux"), //
|
||||
|
@ -49,7 +49,7 @@ public class Issue2131Test {
|
||||
@Data
|
||||
static class GoodsResponse extends BaseResponse {
|
||||
// 由于定义成了final形式,setXXX无效,导致无法注入。
|
||||
private final List<GoodsItem> collections = ListUtil.list(false);
|
||||
private final List<GoodsItem> collections = ListUtil.of(false);
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -19,7 +19,7 @@ public class IssueI1AU86Test {
|
||||
|
||||
@Test
|
||||
public void toListTest() {
|
||||
final List<String> redisList = ListUtil.toList(
|
||||
final List<String> redisList = ListUtil.of(
|
||||
"{\"updateDate\":1583376342000,\"code\":\"move\",\"id\":1,\"sort\":1,\"name\":\"电影大全\"}",
|
||||
"{\"updateDate\":1583378882000,\"code\":\"zy\",\"id\":3,\"sort\":5,\"name\":\"综艺会\"}"
|
||||
);
|
||||
|
@ -42,7 +42,7 @@ public class JSONArrayTest {
|
||||
|
||||
@Test
|
||||
public void addNullTest(){
|
||||
final List<String> aaa = ListUtil.of("aaa", null);
|
||||
final List<String> aaa = ListUtil.view("aaa", null);
|
||||
final String jsonStr = JSONUtil.toJsonStr(JSONUtil.parse(aaa,
|
||||
JSONConfig.create().setIgnoreNullValue(false)));
|
||||
Assert.assertEquals("[\"aaa\",null]", jsonStr);
|
||||
@ -97,7 +97,7 @@ public class JSONArrayTest {
|
||||
b2.setAkey("aValue2");
|
||||
b2.setBkey("bValue2");
|
||||
|
||||
final ArrayList<KeyBean> list = ListUtil.toList(b1, b2);
|
||||
final ArrayList<KeyBean> list = ListUtil.of(b1, b2);
|
||||
|
||||
final JSONArray jsonArray = JSONUtil.parseArray(list);
|
||||
Assert.assertEquals("aValue1", jsonArray.getJSONObject(0).getStr("akey"));
|
||||
|
@ -238,7 +238,7 @@ public class JSONObjectTest {
|
||||
userA.setA("A user");
|
||||
userA.setName("{\n\t\"body\":{\n\t\t\"loginId\":\"id\",\n\t\t\"password\":\"pwd\"\n\t}\n}");
|
||||
userA.setDate(new Date());
|
||||
userA.setSqs(ListUtil.toList(new Seq("seq1"), new Seq("seq2")));
|
||||
userA.setSqs(ListUtil.of(new Seq("seq1"), new Seq("seq2")));
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(userA);
|
||||
final UserA userA2 = json.toBean(UserA.class);
|
||||
@ -320,7 +320,7 @@ public class JSONObjectTest {
|
||||
final UserA userA = new UserA();
|
||||
userA.setName("nameTest");
|
||||
userA.setDate(new Date());
|
||||
userA.setSqs(ListUtil.toList(new Seq(null), new Seq("seq2")));
|
||||
userA.setSqs(ListUtil.of(new Seq(null), new Seq("seq2")));
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(userA, false);
|
||||
|
||||
@ -333,7 +333,7 @@ public class JSONObjectTest {
|
||||
final TestBean bean = new TestBean();
|
||||
bean.setDoubleValue(111.1);
|
||||
bean.setIntValue(123);
|
||||
bean.setList(ListUtil.toList("a", "b", "c"));
|
||||
bean.setList(ListUtil.of("a", "b", "c"));
|
||||
bean.setStrValue("strTest");
|
||||
bean.setTestEnum(TestEnum.TYPE_B);
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class JSONUtilTest {
|
||||
a2.setDate(DateUtil.date());
|
||||
a2.setName("AAAA222Name");
|
||||
|
||||
final ArrayList<UserA> list = ListUtil.toList(a1, a2);
|
||||
final ArrayList<UserA> list = ListUtil.of(a1, a2);
|
||||
final HashMap<String, Object> map = MapUtil.newHashMap();
|
||||
map.put("total", 13);
|
||||
map.put("rows", list);
|
||||
@ -229,7 +229,7 @@ public class JSONUtilTest {
|
||||
public void toXmlTest(){
|
||||
final JSONObject obj = JSONUtil.createObj();
|
||||
obj.set("key1", "v1")
|
||||
.set("key2", ListUtil.of("a", "b", "c"));
|
||||
.set("key2", ListUtil.view("a", "b", "c"));
|
||||
final String xmlStr = JSONUtil.toXmlStr(obj);
|
||||
Assert.assertEquals("<key1>v1</key1><key2>a</key2><key2>b</key2><key2>c</key2>", xmlStr);
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ public class ParseBeanTest {
|
||||
c2.setTest("test2");
|
||||
|
||||
final B b1 = new B();
|
||||
b1.setCs(ListUtil.toList(c1, c2));
|
||||
b1.setCs(ListUtil.of(c1, c2));
|
||||
final B b2 = new B();
|
||||
b2.setCs(ListUtil.toList(c1, c2));
|
||||
b2.setCs(ListUtil.of(c1, c2));
|
||||
|
||||
final A a = new A();
|
||||
a.setBs(ListUtil.toList(b1, b2));
|
||||
a.setBs(ListUtil.of(b1, b2));
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(a);
|
||||
final A a1 = JSONUtil.toBean(json, A.class);
|
||||
|
@ -1017,7 +1017,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
}
|
||||
} else if (rowBean instanceof Hyperlink) {
|
||||
// Hyperlink当成一个值
|
||||
return writeRow(ListUtil.toList(rowBean), isWriteKeyAsHead);
|
||||
return writeRow(ListUtil.of(rowBean), isWriteKeyAsHead);
|
||||
} else if (BeanUtil.isBean(rowBean.getClass())) {
|
||||
if (MapUtil.isEmpty(this.headerAlias)) {
|
||||
rowMap = BeanUtil.beanToMap(rowBean, new LinkedHashMap<>(), false, false);
|
||||
@ -1027,7 +1027,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
}
|
||||
} else {
|
||||
// 其它转为字符串默认输出
|
||||
return writeRow(ListUtil.toList(rowBean), isWriteKeyAsHead);
|
||||
return writeRow(ListUtil.of(rowBean), isWriteKeyAsHead);
|
||||
}
|
||||
return writeRow(rowMap, isWriteKeyAsHead);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class SheetRidReader extends DefaultHandler {
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public List<String> getSheetNames() {
|
||||
return ListUtil.toList(this.NAME_RID_MAP.keySet());
|
||||
return ListUtil.of(this.NAME_RID_MAP.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +44,7 @@ public abstract class BeanRowHandler<T> extends AbstractRowHandler<T> {
|
||||
@Override
|
||||
public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) {
|
||||
if (rowIndex == this.headerRowIndex) {
|
||||
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
|
||||
this.headerList = ListUtil.view(Convert.toList(String.class, rowCells));
|
||||
return;
|
||||
}
|
||||
super.handle(sheetIndex, rowIndex, rowCells);
|
||||
|
@ -41,7 +41,7 @@ public abstract class MapRowHandler extends AbstractRowHandler<Map<String, Objec
|
||||
@Override
|
||||
public void handle(final int sheetIndex, final long rowIndex, final List<Object> rowCells) {
|
||||
if (rowIndex == this.headerRowIndex) {
|
||||
this.headerList = ListUtil.unmodifiable(Convert.toList(String.class, rowCells));
|
||||
this.headerList = ListUtil.view(Convert.toList(String.class, rowCells));
|
||||
return;
|
||||
}
|
||||
super.handle(sheetIndex, rowIndex, rowCells);
|
||||
|
@ -94,7 +94,7 @@ public class TableUtil {
|
||||
rowMap = BeanUtil.beanToMap(rowBean, new LinkedHashMap<>(), false, false);
|
||||
} else {
|
||||
// 其它转为字符串默认输出
|
||||
writeRow(row, ListUtil.toList(rowBean), isWriteKeyAsHead);
|
||||
writeRow(row, ListUtil.of(rowBean), isWriteKeyAsHead);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ public class CsvUtilTest {
|
||||
String mobile;
|
||||
}
|
||||
|
||||
final List<String> header = ListUtil.of("用户id", "用户名", "手机号");
|
||||
final List<String> header = ListUtil.view("用户id", "用户名", "手机号");
|
||||
final List<CsvRow> row = new ArrayList<>();
|
||||
|
||||
final List<User> datas = new ArrayList<>();
|
||||
|
@ -30,7 +30,7 @@ public class BigExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeTest2() {
|
||||
final List<String> row = ListUtil.toList("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final BigExcelWriter overtimeWriter = ExcelUtil.getBigWriter("e:/excel/single_line.xlsx");
|
||||
overtimeWriter.write(row);
|
||||
overtimeWriter.close();
|
||||
@ -39,13 +39,13 @@ public class BigExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeTest() {
|
||||
final List<?> row1 = ListUtil.toList("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
for(int i=0; i < 400000; i++) {
|
||||
//超大列表写出测试
|
||||
rows.add(ObjUtil.clone(row1));
|
||||
@ -70,13 +70,13 @@ public class BigExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void mergeTest() {
|
||||
final List<?> row1 = ListUtil.toList("aa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<?> row1 = ListUtil.of("aa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final BigExcelWriter writer = ExcelUtil.getBigWriter("e:/mergeTest.xlsx");
|
||||
@ -114,7 +114,7 @@ public class BigExcelWriteTest {
|
||||
row2.put("是否合格", false);
|
||||
row2.put("考试日期", DateUtil.date());
|
||||
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.of(row1, row2);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final String path = "e:/bigWriteMapTest.xlsx";
|
||||
@ -174,7 +174,7 @@ public class BigExcelWriteTest {
|
||||
bean2.setScore(38.50);
|
||||
bean2.setExamDate(DateUtil.date());
|
||||
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.toList(bean1, bean2);
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.of(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "e:/bigWriteBeanTest.xlsx";
|
||||
FileUtil.del(file);
|
||||
|
@ -46,12 +46,12 @@ public class ExcelWriteTest {
|
||||
|
||||
@Test
|
||||
public void writeNoFlushTest(){
|
||||
final List<?> row1 = ListUtil.toList("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter();
|
||||
writer.write(rows);
|
||||
@ -61,13 +61,13 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRowOrColumnCellStyle() {
|
||||
final List<?> row1 = ListUtil.toList("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
final BigExcelWriter overtimeWriter = ExcelUtil.getBigWriter("d:/test/style_line.xlsx");
|
||||
|
||||
overtimeWriter.write(rows, true);
|
||||
@ -105,7 +105,7 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeTest2() {
|
||||
final List<String> row = ListUtil.toList("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final ExcelWriter overtimeWriter = ExcelUtil.getWriter("e:/excel/single_line.xlsx");
|
||||
overtimeWriter.writeRow(row);
|
||||
overtimeWriter.close();
|
||||
@ -117,12 +117,12 @@ public class ExcelWriteTest {
|
||||
final ExcelWriter writer = ExcelUtil.getWriterWithSheet("表格1");
|
||||
|
||||
// 写出第一张表
|
||||
final List<String> row = ListUtil.toList("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
writer.writeRow(row);
|
||||
|
||||
// 写出第二张表
|
||||
writer.setSheet("表格2");
|
||||
final List<String> row2 = ListUtil.toList("姓名2", "加班日期2", "下班时间2", "加班时长2", "餐补2", "车补次数2", "车补2", "总计2");
|
||||
final List<String> row2 = ListUtil.of("姓名2", "加班日期2", "下班时间2", "加班时长2", "餐补2", "车补次数2", "车补2", "总计2");
|
||||
writer.writeRow(row2);
|
||||
|
||||
// 生成文件或导出Excel
|
||||
@ -134,13 +134,13 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeTest() {
|
||||
final List<?> row1 = ListUtil.toList("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<?> row1 = ListUtil.of("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
for (int i = 0; i < 400; i++) {
|
||||
// 超大列表写出测试
|
||||
rows.add(ObjUtil.clone(row1));
|
||||
@ -169,13 +169,13 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void mergeTest() {
|
||||
final List<?> row1 = ListUtil.toList("aa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.toList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.toList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.toList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.toList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
final List<?> row1 = ListUtil.of("aa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
|
||||
final List<?> row2 = ListUtil.of("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
|
||||
final List<?> row3 = ListUtil.of("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
|
||||
final List<?> row4 = ListUtil.of("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
|
||||
final List<?> row5 = ListUtil.of("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/mergeTest.xlsx");
|
||||
@ -213,7 +213,7 @@ public class ExcelWriteTest {
|
||||
row2.put("是否合格", false);
|
||||
row2.put("考试日期", DateUtil.date());
|
||||
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.of(row1, row2);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeMapTest.xlsx");
|
||||
@ -243,7 +243,7 @@ public class ExcelWriteTest {
|
||||
row2.put("是否合格", false);
|
||||
row2.put("考试日期", DateUtil.date());
|
||||
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final ArrayList<Map<String, Object>> rows = ListUtil.of(row1, row2);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("e:/excel/writeMapTest.xlsx");
|
||||
@ -325,7 +325,7 @@ public class ExcelWriteTest {
|
||||
row2.put("score", 32.30);
|
||||
row2.put("examDate", DateUtil.date());
|
||||
|
||||
final List<Map<Object, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "d:/test/writeMapAlias.xlsx";
|
||||
FileUtil.del(file);
|
||||
@ -360,7 +360,7 @@ public class ExcelWriteTest {
|
||||
row2.put("score", 32.30);
|
||||
row2.put("examDate", DateUtil.date());
|
||||
|
||||
final List<Map<Object, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "f:/test/test_alias.xlsx";
|
||||
FileUtil.del(file);
|
||||
@ -393,7 +393,7 @@ public class ExcelWriteTest {
|
||||
row2.put("score", 32.30);
|
||||
row2.put("examDate", DateUtil.date());
|
||||
|
||||
final List<Map<Object, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "d:/test/test_alias.xls";
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file, "test1");
|
||||
@ -424,7 +424,7 @@ public class ExcelWriteTest {
|
||||
row2.put("score", 32.30);
|
||||
row2.put("examDate", DateUtil.date());
|
||||
|
||||
final List<Map<Object, Object>> rows = ListUtil.toList(row1, row2);
|
||||
final List<Map<Object, Object>> rows = ListUtil.of(row1, row2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "d:/test/test_alias.xls";
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(file, "test1");
|
||||
@ -458,7 +458,7 @@ public class ExcelWriteTest {
|
||||
bean2.setScore(38.50);
|
||||
bean2.setExamDate(DateUtil.date());
|
||||
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.toList(bean1, bean2);
|
||||
final List<cn.hutool.poi.excel.TestBean> rows = ListUtil.of(bean1, bean2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "e:/writeBeanTest.xlsx";
|
||||
FileUtil.del(file);
|
||||
@ -490,7 +490,7 @@ public class ExcelWriteTest {
|
||||
order1.setNum("456");
|
||||
order1.setBody("body2");
|
||||
|
||||
final List<cn.hutool.poi.excel.OrderExcel> rows = ListUtil.toList(order1, order2);
|
||||
final List<cn.hutool.poi.excel.OrderExcel> rows = ListUtil.of(order1, order2);
|
||||
// 通过工具类创建writer
|
||||
final String file = "f:/test/writeBeanTest2.xlsx";
|
||||
FileUtil.del(file);
|
||||
@ -517,7 +517,7 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void addSelectTest() {
|
||||
final List<String> row = ListUtil.toList("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final List<String> row = ListUtil.of("姓名", "加班日期", "下班时间", "加班时长", "餐补", "车补次数", "车补", "总计");
|
||||
final ExcelWriter overtimeWriter = ExcelUtil.getWriter("d:/test/single_line.xlsx");
|
||||
overtimeWriter.writeCellValue(3, 4, "AAAA");
|
||||
overtimeWriter.addSelect(3, 4, row.toArray(new String[0]));
|
||||
@ -674,7 +674,7 @@ public class ExcelWriteTest {
|
||||
public void writeNumberFormatTest() {
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/formatTest.xlsx");
|
||||
writer.disableDefaultStyle();
|
||||
writer.writeRow(ListUtil.toList(51.33333333, 90.111111111));
|
||||
writer.writeRow(ListUtil.of(51.33333333, 90.111111111));
|
||||
final CellStyle columnStyle = writer.createCellStyle(0, 0);
|
||||
columnStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("0.00"));
|
||||
writer.close();
|
||||
@ -683,13 +683,13 @@ public class ExcelWriteTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeSecHeadRowTest() {
|
||||
final List<?> row1 = ListUtil.toList(1, "aa", "bb", "cc", "dd", "ee");
|
||||
final List<?> row2 = ListUtil.toList(2, "aa1", "bb1", "cc1", "dd1", "ee1");
|
||||
final List<?> row3 = ListUtil.toList(3, "aa2", "bb2", "cc2", "dd2", "ee2");
|
||||
final List<?> row4 = ListUtil.toList(4, "aa3", "bb3", "cc3", "dd3", "ee3");
|
||||
final List<?> row5 = ListUtil.toList(5, "aa4", "bb4", "cc4", "dd4", "ee4");
|
||||
final List<?> row1 = ListUtil.of(1, "aa", "bb", "cc", "dd", "ee");
|
||||
final List<?> row2 = ListUtil.of(2, "aa1", "bb1", "cc1", "dd1", "ee1");
|
||||
final List<?> row3 = ListUtil.of(3, "aa2", "bb2", "cc2", "dd2", "ee2");
|
||||
final List<?> row4 = ListUtil.of(4, "aa3", "bb3", "cc3", "dd3", "ee3");
|
||||
final List<?> row5 = ListUtil.of(5, "aa4", "bb4", "cc4", "dd4", "ee4");
|
||||
|
||||
final List<List<?>> rows = ListUtil.toList(row1, row2, row3, row4, row5);
|
||||
final List<List<?>> rows = ListUtil.of(row1, row2, row3, row4, row5);
|
||||
|
||||
// 通过工具类创建writer
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeSecHeadRowTest.xlsx");
|
||||
@ -718,7 +718,7 @@ public class ExcelWriteTest {
|
||||
writer.merge(2, 2, 4, 5, "DDEE", true);
|
||||
writer.setCurrentRow(3);
|
||||
|
||||
final List<String> sechead = ListUtil.toList("AA", "BB", "DD", "EE");
|
||||
final List<String> sechead = ListUtil.of("AA", "BB", "DD", "EE");
|
||||
writer.writeSecHeadRow(sechead);
|
||||
// 一次性写出内容,使用默认样式
|
||||
writer.write(rows);
|
||||
@ -800,7 +800,7 @@ public class ExcelWriteTest {
|
||||
@Ignore
|
||||
public void changeHeaderStyleTest(){
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/headerStyle.xlsx");
|
||||
writer.writeHeadRow(ListUtil.of("姓名", "性别", "年龄"));
|
||||
writer.writeHeadRow(ListUtil.view("姓名", "性别", "年龄"));
|
||||
final CellStyle headCellStyle = writer.getStyleSet().getHeadCellStyle();
|
||||
headCellStyle.setFillForegroundColor(IndexedColors.YELLOW1.index);
|
||||
headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
@ -816,7 +816,7 @@ public class ExcelWriteTest {
|
||||
FileUtil.del(path);
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter(path);
|
||||
writer.writeRow(ListUtil.of(22.9f));
|
||||
writer.writeRow(ListUtil.view(22.9f));
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@ -826,7 +826,7 @@ public class ExcelWriteTest {
|
||||
// https://gitee.com/dromara/hutool/issues/I466ZZ
|
||||
// 需要输出S_20000314_x5116_0004
|
||||
// 此处加入一个转义前缀:_x005F
|
||||
final List<Object> row = ListUtil.of(new EscapeStrCellSetter("S_20000314_x5116_0004"));
|
||||
final List<Object> row = ListUtil.view(new EscapeStrCellSetter("S_20000314_x5116_0004"));
|
||||
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/_x.xlsx");
|
||||
writer.writeRow(row);
|
||||
@ -838,7 +838,7 @@ public class ExcelWriteTest {
|
||||
public void writeLongTest(){
|
||||
//https://gitee.com/dromara/hutool/issues/I49R6U
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/long.xlsx");
|
||||
writer.write(ListUtil.of(1427545395336093698L));
|
||||
writer.write(ListUtil.view(1427545395336093698L));
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@ -849,7 +849,7 @@ public class ExcelWriteTest {
|
||||
|
||||
final Hyperlink hyperlink = writer.createHyperlink(HyperlinkType.URL, "https://hutool.cn");
|
||||
|
||||
writer.write(ListUtil.of(hyperlink));
|
||||
writer.write(ListUtil.view(hyperlink));
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class Issue2221Test {
|
||||
writer.setOnlyAlias(true);
|
||||
|
||||
// 写入数据
|
||||
final List<Map<Object, Object>> data = ListUtil.of(
|
||||
final List<Map<Object, Object>> data = ListUtil.view(
|
||||
MapUtil.ofEntries(MapUtil.entry("androidLc", "1次"), MapUtil.entry("androidAc", "3人")),
|
||||
MapUtil.ofEntries(MapUtil.entry("androidLc", "1次"), MapUtil.entry("androidAc", "3人"))
|
||||
);
|
||||
@ -75,7 +75,7 @@ public class Issue2221Test {
|
||||
writer.merge(0, 0, 3, 4, "新增人数", true);
|
||||
|
||||
// 写入数据
|
||||
final List<Map<Object, Object>> data = ListUtil.of(
|
||||
final List<Map<Object, Object>> data = ListUtil.view(
|
||||
MapUtil.ofEntries(
|
||||
MapUtil.entry("date", "2022-01-01"),
|
||||
MapUtil.entry("androidLc", "1次"),
|
||||
|
@ -48,7 +48,7 @@ public class WordWriterTest {
|
||||
map.put("成绩", 88.32);
|
||||
map.put("是否合格", true);
|
||||
|
||||
writer.addTable(ListUtil.toList(map));
|
||||
writer.addTable(ListUtil.of(map));
|
||||
writer.flush(FileUtil.file("d:/test/test.docx"));
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ public class WordWriterTest {
|
||||
data2.put("是否合格", false);
|
||||
data2.put("考试日期", DateUtil.date());
|
||||
|
||||
final ArrayList<Map<String, Object>> mapArrayList = ListUtil.toList(data, data2);
|
||||
final ArrayList<Map<String, Object>> mapArrayList = ListUtil.of(data, data2);
|
||||
|
||||
// 添加段落(标题)
|
||||
writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分");
|
||||
@ -87,8 +87,8 @@ public class WordWriterTest {
|
||||
@Test
|
||||
public void overflowTest(){
|
||||
final Word07Writer word07Writer = new Word07Writer();
|
||||
final List<Object> list = ListUtil.list(false);
|
||||
final List<Object> list2 = ListUtil.list(false);
|
||||
final List<Object> list = ListUtil.of(false);
|
||||
final List<Object> list2 = ListUtil.of(false);
|
||||
list.add("溢出测试");
|
||||
list2.add(list);
|
||||
word07Writer.addTable(list);
|
||||
|
@ -279,7 +279,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
|
||||
public boolean contains(final String group, final String value, final String... otherValues) {
|
||||
if (ArrayUtil.isNotEmpty(otherValues)) {
|
||||
// 需要测试多个值的情况
|
||||
final List<String> valueList = ListUtil.toList(otherValues);
|
||||
final List<String> valueList = ListUtil.of(otherValues);
|
||||
valueList.add(value);
|
||||
return contains(group, valueList);
|
||||
} else {
|
||||
|
@ -437,7 +437,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
||||
* @return 获得所有分组名
|
||||
*/
|
||||
public List<String> getGroups() {
|
||||
return ListUtil.toList(this.groupedMap.keySet());
|
||||
return ListUtil.of(this.groupedMap.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user