mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.annotation;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Documented;
|
||||
@@ -7,14 +9,12 @@ import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
/**
|
||||
* 组合注解 对JDK的原生注解机制做一个增强,支持类似Spring的组合注解。<br>
|
||||
* 核心实现使用了递归获取指定元素上的注解以及注解的注解,以实现复合注解的获取。
|
||||
@@ -65,13 +65,13 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
@Override
|
||||
public Annotation[] getAnnotations() {
|
||||
final Collection<Annotation> annotations = this.annotationMap.values();
|
||||
return annotations.toArray(new Annotation[annotations.size()]);
|
||||
return annotations.toArray(new Annotation[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Annotation[] getDeclaredAnnotations() {
|
||||
final Collection<Annotation> annotations = this.declaredAnnotationMap.values();
|
||||
return annotations.toArray(new Annotation[annotations.size()]);
|
||||
return annotations.toArray(new Annotation[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class CombinationAnnotationElement implements AnnotatedElement, Serializa
|
||||
parseDeclared(declaredAnnotations);
|
||||
|
||||
final Annotation[] annotations = element.getAnnotations();
|
||||
if(ObjectUtil.equal(declaredAnnotations, annotations)) {
|
||||
if(Arrays.equals(declaredAnnotations, annotations)) {
|
||||
this.annotationMap = this.declaredAnnotationMap;
|
||||
}else {
|
||||
this.annotationMap = new HashMap<>();
|
||||
|
@@ -2700,8 +2700,7 @@ public class ArrayUtil {
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static <T> T[] toArray(Collection<T> collection, Class<T> componentType) {
|
||||
final T[] array = newArray(componentType, collection.size());
|
||||
return collection.toArray(array);
|
||||
return collection.toArray(newArray(componentType, 0));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- remove
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Editor;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* {@link ArrayUtil} 数组工具单元测试
|
||||
@@ -20,8 +23,10 @@ public class ArrayUtilTest {
|
||||
Assert.assertTrue(ArrayUtil.isEmpty(a));
|
||||
Assert.assertTrue(ArrayUtil.isEmpty((Object) a));
|
||||
int[] b = null;
|
||||
//noinspection ConstantConditions
|
||||
Assert.assertTrue(ArrayUtil.isEmpty(b));
|
||||
Object c = null;
|
||||
//noinspection ConstantConditions
|
||||
Assert.assertTrue(ArrayUtil.isEmpty(c));
|
||||
|
||||
Object d = new Object[]{"1", "2", 3, 4D};
|
||||
@@ -31,7 +36,9 @@ public class ArrayUtilTest {
|
||||
isEmpty = ArrayUtil.isEmpty(d);
|
||||
Assert.assertTrue(isEmpty);
|
||||
d = null;
|
||||
//noinspection ConstantConditions
|
||||
isEmpty = ArrayUtil.isEmpty(d);
|
||||
//noinspection ConstantConditions
|
||||
Assert.assertTrue(isEmpty);
|
||||
}
|
||||
|
||||
@@ -117,7 +124,7 @@ public class ArrayUtilTest {
|
||||
String[] keys = {"a", "b", "c"};
|
||||
Integer[] values = {1, 2, 3};
|
||||
Map<String, Integer> map = ArrayUtil.zip(keys, values, true);
|
||||
Assert.assertEquals(map.toString(), "{a=1, b=2, c=3}");
|
||||
Assert.assertEquals(Objects.requireNonNull(map).toString(), "{a=1, b=2, c=3}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,4 +255,14 @@ public class ArrayUtilTest {
|
||||
String[] array = {"aa", "bb", "cc", "dd", "bb", "dd"};
|
||||
Assert.assertEquals("[aa, bb, cc, dd, bb, dd]", ArrayUtil.toString(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toArrayTest(){
|
||||
final ArrayList<String> list = CollUtil.newArrayList("A", "B", "C", "D");
|
||||
final String[] array = ArrayUtil.toArray(list, String.class);
|
||||
Assert.assertEquals("A", array[0]);
|
||||
Assert.assertEquals("B", array[1]);
|
||||
Assert.assertEquals("C", array[2]);
|
||||
Assert.assertEquals("D", array[3]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user