mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-06 21:58:03 +08:00
fix bugs
This commit is contained in:
parent
93d91699c1
commit
80ed1c0141
@ -24,6 +24,8 @@
|
||||
* 【core 】 修复Dict中putAll大小写问题(issue#I1MU5B@Gitee)
|
||||
* 【core 】 修复POI中sax读取数字判断错误问题(issue#931@Github)
|
||||
* 【core 】 修复DateUtil.endOfQuarter错误问题(issue#I1NGZ7@Gitee)
|
||||
* 【core 】 修复URL中有空格转为+问题(issue#I1NGW4@Gitee)
|
||||
* 【core 】 修复CollUtil.intersectionDistinct空集合结果错误问题
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
## 5.3.8 (2020-06-16)
|
||||
|
@ -283,23 +283,26 @@ public class CollUtil {
|
||||
@SafeVarargs
|
||||
public static <T> Set<T> intersectionDistinct(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
|
||||
final Set<T> result;
|
||||
if (isEmpty(coll1)) {
|
||||
result = new LinkedHashSet<>();
|
||||
if (isEmpty(coll1) || isEmpty(coll2)) {
|
||||
// 有一个空集合就直接返回空
|
||||
return new LinkedHashSet<>();
|
||||
} else {
|
||||
result = new LinkedHashSet<>(coll1);
|
||||
}
|
||||
|
||||
if (isNotEmpty(coll2)) {
|
||||
result.retainAll(coll2);
|
||||
}
|
||||
|
||||
if (ArrayUtil.isNotEmpty(otherColls)) {
|
||||
for (Collection<T> otherColl : otherColls) {
|
||||
if(isNotEmpty(otherColl)){
|
||||
result.retainAll(otherColl);
|
||||
} else {
|
||||
// 有一个空集合就直接返回空
|
||||
return new LinkedHashSet<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.retainAll(coll2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,9 @@ import java.util.BitSet;
|
||||
* 3.将非文本内容转换成"%xy"的形式,xy是两位16进制的数值;
|
||||
* </pre>
|
||||
*
|
||||
* @author looly,
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class URLEncoder implements Serializable{
|
||||
public class URLEncoder implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// --------------------------------------------------------------------------------------------- Static method start
|
||||
@ -48,11 +47,21 @@ public class URLEncoder implements Serializable{
|
||||
* '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' Also '=' and '&' 不编码
|
||||
* 其它编码为 %nn 形式
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* 详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
|
||||
*/
|
||||
public static final URLEncoder QUERY = createQuery();
|
||||
|
||||
/**
|
||||
* 全编码的{@link URLEncoder}<br>
|
||||
* <pre>
|
||||
* 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is
|
||||
* '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' 不编码
|
||||
* 其它编码为 %nn 形式
|
||||
* </pre>
|
||||
*/
|
||||
public static final URLEncoder ALL = createAll();
|
||||
|
||||
/**
|
||||
* 创建默认{@link URLEncoder}<br>
|
||||
* 默认的编码器针对URI路径编码,定义如下:
|
||||
@ -102,7 +111,7 @@ public class URLEncoder implements Serializable{
|
||||
* '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' Also '=' and '&' 不编码
|
||||
* 其它编码为 %nn 形式
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* 详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
|
||||
*
|
||||
* @return {@link URLEncoder}
|
||||
@ -122,16 +131,44 @@ public class URLEncoder implements Serializable{
|
||||
|
||||
return encoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@link URLEncoder}<br>
|
||||
* 编码器针对URI路径编码,定义如下:
|
||||
*
|
||||
* <pre>
|
||||
* 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is
|
||||
* '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' 不编码
|
||||
* 其它编码为 %nn 形式
|
||||
* </pre>
|
||||
* <p>
|
||||
* 详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
|
||||
*
|
||||
* @return {@link URLEncoder}
|
||||
*/
|
||||
public static URLEncoder createAll() {
|
||||
final URLEncoder encoder = new URLEncoder();
|
||||
encoder.addSafeCharacter('*');
|
||||
encoder.addSafeCharacter('-');
|
||||
encoder.addSafeCharacter('.');
|
||||
encoder.addSafeCharacter('_');
|
||||
|
||||
return encoder;
|
||||
}
|
||||
// --------------------------------------------------------------------------------------------- Static method end
|
||||
|
||||
/** 存放安全编码 */
|
||||
/**
|
||||
* 存放安全编码
|
||||
*/
|
||||
private final BitSet safeCharacters;
|
||||
/** 是否编码空格为+ */
|
||||
/**
|
||||
* 是否编码空格为+
|
||||
*/
|
||||
private boolean encodeSpaceAsPlus = false;
|
||||
|
||||
/**
|
||||
* 构造<br>
|
||||
*
|
||||
* <p>
|
||||
* [a-zA-Z0-9]默认不被编码
|
||||
*/
|
||||
public URLEncoder() {
|
||||
@ -191,7 +228,6 @@ public class URLEncoder implements Serializable{
|
||||
*
|
||||
* @param path 需要编码的字符串
|
||||
* @param charset 编码
|
||||
*
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public String encode(String path, Charset charset) {
|
||||
|
@ -14,7 +14,6 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
@ -331,11 +330,8 @@ public class URLUtil {
|
||||
if (null == charset) {
|
||||
return url;
|
||||
}
|
||||
try {
|
||||
return java.net.URLEncoder.encode(url, charset.toString());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new UtilException(e);
|
||||
}
|
||||
|
||||
return URLEncoder.ALL.encode(url, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,11 @@ import java.util.SortedSet;
|
||||
* 集合工具类单元测试
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void isNotEmptyTest(){
|
||||
public void isNotEmptyTest() {
|
||||
Assert.assertFalse(CollUtil.isNotEmpty((Collection<?>) null));
|
||||
}
|
||||
|
||||
@ -144,7 +143,7 @@ public class CollUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subtractTest(){
|
||||
public void subtractTest() {
|
||||
List<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
List<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final Collection<String> subtract = CollUtil.subtract(list1, list2);
|
||||
@ -632,9 +631,9 @@ public class CollUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toMapTest(){
|
||||
public void toMapTest() {
|
||||
Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
|
||||
final Map<String, String> map = CollUtil.toMap(keys, new HashMap<>(), (value)->"key" + value);
|
||||
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"));
|
||||
Assert.assertEquals("c", map.get("keyc"));
|
||||
|
@ -198,4 +198,10 @@ public class UrlBuilderTest {
|
||||
final UrlBuilder builder = UrlBuilder.ofHttp(getWorkDayUrl, CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals(getWorkDayUrl, builder.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blankEncodeTest(){
|
||||
final UrlBuilder urlBuilder = UrlBuilder.ofHttp("http://a.com/aaa bbb.html", CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals("http://a.com/aaa%20bbb.html", urlBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user