mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add CollUtil.padXXX
This commit is contained in:
parent
28f149b2bc
commit
23884e7121
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
## 5.3.10 (2020-07-22)
|
## 5.3.10 (2020-07-23)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【db 】 增加DbUtil.setReturnGeneratedKeyGlobal(issue#I1NM0K@Gitee)
|
* 【db 】 增加DbUtil.setReturnGeneratedKeyGlobal(issue#I1NM0K@Gitee)
|
||||||
@ -13,6 +13,7 @@
|
|||||||
* 【core 】 LocalDateTimeUtil增加format等方法(pr#140@Gitee)
|
* 【core 】 LocalDateTimeUtil增加format等方法(pr#140@Gitee)
|
||||||
* 【http 】 UserAgentUtil增加Android原生浏览器识别(pr#975@Github)
|
* 【http 】 UserAgentUtil增加Android原生浏览器识别(pr#975@Github)
|
||||||
* 【crypto 】 增加ECIES算法类(issue#979@Github)
|
* 【crypto 】 增加ECIES算法类(issue#979@Github)
|
||||||
|
* 【crypto 】 CollUtil增加padLeft和padRight方法(pr#141@Gitee)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复ZipUtil中finish位于循环内的问题(issue#961@Github)
|
* 【core 】 修复ZipUtil中finish位于循环内的问题(issue#961@Github)
|
||||||
|
@ -12,11 +12,39 @@ import cn.hutool.core.lang.Matcher;
|
|||||||
import cn.hutool.core.lang.func.Func1;
|
import cn.hutool.core.lang.func.Func1;
|
||||||
import cn.hutool.core.lang.hash.Hash32;
|
import cn.hutool.core.lang.hash.Hash32;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.*;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import cn.hutool.core.util.CharUtil;
|
||||||
|
import cn.hutool.core.util.ClassUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.core.util.TypeUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.AbstractCollection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Deque;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.NavigableSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.Stack;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@ -36,40 +64,6 @@ import java.util.function.Function;
|
|||||||
*/
|
*/
|
||||||
public class CollUtil {
|
public class CollUtil {
|
||||||
|
|
||||||
/**
|
|
||||||
* 填充List,以达到最小长度
|
|
||||||
*
|
|
||||||
* @param list 列表
|
|
||||||
* @param minLen 最小长度
|
|
||||||
* @param padObj 填充的对象
|
|
||||||
* @param <T> 集合元素类型
|
|
||||||
*/
|
|
||||||
public static <T> void padLeft(List<T> list, int minLen, T padObj) {
|
|
||||||
Objects.requireNonNull(list);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
padRight(list, minLen, padObj);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = list.size(); i < minLen; i++) {
|
|
||||||
list.add(0, padObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 填充List,以达到最小长度
|
|
||||||
*
|
|
||||||
* @param list 列表
|
|
||||||
* @param minLen 最小长度
|
|
||||||
* @param padObj 填充的对象
|
|
||||||
* @param <T> 集合元素类型
|
|
||||||
*/
|
|
||||||
public static <T> void padRight(Collection<T> list, int minLen, T padObj) {
|
|
||||||
Objects.requireNonNull(list);
|
|
||||||
for (int i = list.size(); i < minLen; i++) {
|
|
||||||
list.add(padObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果提供的集合为{@code null},返回一个不可变的默认空集合,否则返回原集合<br>
|
* 如果提供的集合为{@code null},返回一个不可变的默认空集合,否则返回原集合<br>
|
||||||
* 空集合使用{@link Collections#emptySet()}
|
* 空集合使用{@link Collections#emptySet()}
|
||||||
@ -298,7 +292,7 @@ public class CollUtil {
|
|||||||
|
|
||||||
if (ArrayUtil.isNotEmpty(otherColls)) {
|
if (ArrayUtil.isNotEmpty(otherColls)) {
|
||||||
for (Collection<T> otherColl : otherColls) {
|
for (Collection<T> otherColl : otherColls) {
|
||||||
if(isNotEmpty(otherColl)){
|
if (isNotEmpty(otherColl)) {
|
||||||
result.retainAll(otherColl);
|
result.retainAll(otherColl);
|
||||||
} else {
|
} else {
|
||||||
// 有一个空集合就直接返回空
|
// 有一个空集合就直接返回空
|
||||||
@ -2786,6 +2780,42 @@ public class CollUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充List,以达到最小长度
|
||||||
|
*
|
||||||
|
* @param <T> 集合元素类型
|
||||||
|
* @param list 列表
|
||||||
|
* @param minLen 最小长度
|
||||||
|
* @param padObj 填充的对象
|
||||||
|
* @since 5.3.10
|
||||||
|
*/
|
||||||
|
public static <T> void padLeft(List<T> list, int minLen, T padObj) {
|
||||||
|
Objects.requireNonNull(list);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
padRight(list, minLen, padObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = list.size(); i < minLen; i++) {
|
||||||
|
list.add(0, padObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充List,以达到最小长度
|
||||||
|
*
|
||||||
|
* @param <T> 集合元素类型
|
||||||
|
* @param list 列表
|
||||||
|
* @param minLen 最小长度
|
||||||
|
* @param padObj 填充的对象
|
||||||
|
* @since 5.3.10
|
||||||
|
*/
|
||||||
|
public static <T> void padRight(Collection<T> list, int minLen, T padObj) {
|
||||||
|
Objects.requireNonNull(list);
|
||||||
|
for (int i = list.size(); i < minLen; i++) {
|
||||||
|
list.add(padObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------- Interface start
|
// ---------------------------------------------------------------------------------------------- Interface start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.db.Db;
|
|
||||||
import cn.hutool.db.Entity;
|
|
||||||
import cn.hutool.db.ds.DSFactory;
|
import cn.hutool.db.ds.DSFactory;
|
||||||
import cn.hutool.db.ds.c3p0.C3p0DSFactory;
|
import cn.hutool.db.ds.c3p0.C3p0DSFactory;
|
||||||
import cn.hutool.db.ds.dbcp.DbcpDSFactory;
|
import cn.hutool.db.ds.dbcp.DbcpDSFactory;
|
||||||
@ -18,6 +8,12 @@ import cn.hutool.db.ds.druid.DruidDSFactory;
|
|||||||
import cn.hutool.db.ds.hikari.HikariDSFactory;
|
import cn.hutool.db.ds.hikari.HikariDSFactory;
|
||||||
import cn.hutool.db.ds.pooled.PooledDSFactory;
|
import cn.hutool.db.ds.pooled.PooledDSFactory;
|
||||||
import cn.hutool.db.ds.tomcat.TomcatDSFactory;
|
import cn.hutool.db.ds.tomcat.TomcatDSFactory;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据源单元测试
|
* 数据源单元测试
|
||||||
|
Loading…
x
Reference in New Issue
Block a user