mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix http bug
This commit is contained in:
@@ -1350,7 +1350,7 @@ public class CollUtil {
|
||||
* @return 抽取后的新列表
|
||||
* @since 5.3.5
|
||||
*/
|
||||
public static <T, R> List<R> map(Iterable<T> collection, Function<T, R> func, boolean ignoreNull) {
|
||||
public static <T, R> List<R> map(Iterable<T> collection, Function<? super T, ? extends R> func, boolean ignoreNull) {
|
||||
final List<R> fieldValueList = new ArrayList<>();
|
||||
if (null == collection) {
|
||||
return fieldValueList;
|
||||
|
@@ -11,7 +11,17 @@ import cn.hutool.core.lang.Matcher;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 数组工具类
|
||||
@@ -4274,4 +4284,23 @@ public class ArrayUtil {
|
||||
public static <T> boolean isAllNotNull(T... array) {
|
||||
return false == hasNull(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照指定规则,将一种类型的数组转换为另一种类型
|
||||
*
|
||||
* @param array 被转换的数组
|
||||
* @param targetComponentType 目标的元素类型
|
||||
* @param func 转换规则函数
|
||||
* @param <T> 原数组类型
|
||||
* @param <R> 目标数组类型
|
||||
* @return 转换后的数组
|
||||
* @since 5.4.2
|
||||
*/
|
||||
public static <T, R> R[] map(T[] array, Class<R> targetComponentType, Function<? super T, ? extends R> func){
|
||||
final R[] result = newArray(targetComponentType, array.length);
|
||||
for(int i=0; i< array.length; i++){
|
||||
result[i] = func.apply(array[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -295,7 +295,7 @@ public class TypeUtil {
|
||||
* @return 给定泛型参数对应的实际类型,如果无对应类型,返回null
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public static TableMap<TypeVariable<?>, Type> getActualTypeMap(Type actualType, Class<?> typeDefineClass) {
|
||||
public static TableMap<String, Type> getActualTypeMap(Type actualType, Class<?> typeDefineClass) {
|
||||
if (false == typeDefineClass.isAssignableFrom(getClass(actualType))) {
|
||||
throw new IllegalArgumentException("Parameter [superClass] must be assignable from [clazz]");
|
||||
}
|
||||
@@ -305,13 +305,14 @@ public class TypeUtil {
|
||||
if (ArrayUtil.isEmpty(typeVars)) {
|
||||
return new TableMap<>(0);
|
||||
}
|
||||
|
||||
// 实际类型列表
|
||||
final Type[] actualTypeArguments = TypeUtil.getTypeArguments(actualType);
|
||||
if (ArrayUtil.isEmpty(actualTypeArguments)) {
|
||||
return new TableMap<>(0);
|
||||
}
|
||||
|
||||
return new TableMap<>(typeVars, actualTypeArguments);
|
||||
return new TableMap<>(ArrayUtil.map(typeVars, String.class, TypeVariable::getName), actualTypeArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -331,13 +332,14 @@ public class TypeUtil {
|
||||
* @since 4.5.7
|
||||
*/
|
||||
public static Type[] getActualTypes(Type actualType, Class<?> typeDefineClass, Type... typeVariables) {
|
||||
final TableMap<TypeVariable<?>, Type> tableMap = getActualTypeMap(actualType, typeDefineClass);
|
||||
final TableMap<String, Type> tableMap = getActualTypeMap(actualType, typeDefineClass);
|
||||
|
||||
// 查找方法定义所在类或接口中此泛型参数的位置
|
||||
final Type[] result = new Type[typeVariables.length];
|
||||
for (int i = 0; i < typeVariables.length; i++) {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
result[i] = (typeVariables[i] instanceof TypeVariable) ? tableMap.get(typeVariables[i]) : typeVariables[i];
|
||||
result[i] = (typeVariables[i] instanceof TypeVariable)
|
||||
? tableMap.get(((TypeVariable<?>) typeVariables[i]).getName())
|
||||
: typeVariables[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -359,7 +361,7 @@ public class TypeUtil {
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static Type getActualType(Type actualType, Class<?> typeDefineClass, Type typeVariable) {
|
||||
Type[] types = getActualTypes(actualType, typeDefineClass, typeVariable);
|
||||
final Type[] types = getActualTypes(actualType, typeDefineClass, typeVariable);
|
||||
if (ArrayUtil.isNotEmpty(types)) {
|
||||
return types[0];
|
||||
}
|
||||
|
@@ -60,10 +60,12 @@ public class TypeUtilTest {
|
||||
|
||||
@Test
|
||||
public void getActualTypesTest(){
|
||||
final Type id = TypeUtil.getActualType(
|
||||
final Type idType = TypeUtil.getActualType(
|
||||
Station.class,
|
||||
Entity.class,
|
||||
Tree.class,
|
||||
TypeUtil.getFieldType(Station.class, "id"));
|
||||
|
||||
Assert.assertEquals(Long.class, idType);
|
||||
}
|
||||
|
||||
public static class Station extends Tree<Station, Long>{
|
||||
|
Reference in New Issue
Block a user