Looly 6 年之前
父节点
当前提交
be91b672d2

+ 28 - 29
hutool-core/src/main/java/cn/hutool/core/annotation/AnnotationUtil.java

@@ -21,28 +21,28 @@ import cn.hutool.core.util.ReflectUtil;
 /**
 /**
  * 注解工具类<br>
  * 注解工具类<br>
  * 快速获取注解对象、注解值等工具封装
  * 快速获取注解对象、注解值等工具封装
- * 
+ *
  * @author looly
  * @author looly
  * @since 4.0.9
  * @since 4.0.9
  */
  */
 public class AnnotationUtil {
 public class AnnotationUtil {
-	
+
 	/**
 	/**
 	 * 将指定的被注解的元素转换为组合注解元素
 	 * 将指定的被注解的元素转换为组合注解元素
-	 * 
+	 *
 	 * @param annotationEle 注解元素
 	 * @param annotationEle 注解元素
 	 * @return 组合注解元素
 	 * @return 组合注解元素
 	 */
 	 */
 	public static CombinationAnnotationElement toCombination(AnnotatedElement annotationEle) {
 	public static CombinationAnnotationElement toCombination(AnnotatedElement annotationEle) {
-		if(annotationEle instanceof CombinationAnnotationElement) {
-			return (CombinationAnnotationElement)annotationEle;
+		if (annotationEle instanceof CombinationAnnotationElement) {
+			return (CombinationAnnotationElement) annotationEle;
 		}
 		}
 		return new CombinationAnnotationElement(annotationEle);
 		return new CombinationAnnotationElement(annotationEle);
 	}
 	}
 
 
 	/**
 	/**
 	 * 获取指定注解
 	 * 获取指定注解
-	 * 
+	 *
 	 * @param annotationEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @param annotationEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @return 注解对象
 	 * @return 注解对象
 	 */
 	 */
@@ -52,9 +52,9 @@ public class AnnotationUtil {
 
 
 	/**
 	/**
 	 * 获取指定注解
 	 * 获取指定注解
-	 * 
-	 * @param <A> 注解类型
-	 * @param annotationEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
+	 *
+	 * @param <A>            注解类型
+	 * @param annotationEle  {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @param annotationType 注解类型
 	 * @param annotationType 注解类型
 	 * @return 注解对象
 	 * @return 注解对象
 	 */
 	 */
@@ -65,9 +65,9 @@ public class AnnotationUtil {
 	/**
 	/**
 	 * 获取指定注解默认值<br>
 	 * 获取指定注解默认值<br>
 	 * 如果无指定的属性方法返回null
 	 * 如果无指定的属性方法返回null
-	 * 
-	 * @param <T> 注解值类型
-	 * @param annotationEle {@link AccessibleObject},可以是Class、Method、Field、Constructor、ReflectPermission
+	 *
+	 * @param <T>            注解值类型
+	 * @param annotationEle  {@link AccessibleObject},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @param annotationType 注解类型
 	 * @param annotationType 注解类型
 	 * @return 注解对象
 	 * @return 注解对象
 	 * @throws UtilException 调用注解中的方法时执行异常
 	 * @throws UtilException 调用注解中的方法时执行异常
@@ -79,11 +79,11 @@ public class AnnotationUtil {
 	/**
 	/**
 	 * 获取指定注解属性的值<br>
 	 * 获取指定注解属性的值<br>
 	 * 如果无指定的属性方法返回null
 	 * 如果无指定的属性方法返回null
-	 * 
-	 * @param <T> 注解值类型
-	 * @param annotationEle {@link AccessibleObject},可以是Class、Method、Field、Constructor、ReflectPermission
+	 *
+	 * @param <T>            注解值类型
+	 * @param annotationEle  {@link AccessibleObject},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @param annotationType 注解类型
 	 * @param annotationType 注解类型
-	 * @param propertyName 属性名,例如注解中定义了name()方法,则 此处传入name
+	 * @param propertyName   属性名,例如注解中定义了name()方法,则 此处传入name
 	 * @return 注解对象
 	 * @return 注解对象
 	 * @throws UtilException 调用注解中的方法时执行异常
 	 * @throws UtilException 调用注解中的方法时执行异常
 	 */
 	 */
@@ -103,8 +103,8 @@ public class AnnotationUtil {
 	/**
 	/**
 	 * 获取指定注解中所有属性值<br>
 	 * 获取指定注解中所有属性值<br>
 	 * 如果无指定的属性方法返回null
 	 * 如果无指定的属性方法返回null
-	 * 
-	 * @param annotationEle {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
+	 *
+	 * @param annotationEle  {@link AnnotatedElement},可以是Class、Method、Field、Constructor、ReflectPermission
 	 * @param annotationType 注解类型
 	 * @param annotationType 注解类型
 	 * @return 注解对象
 	 * @return 注解对象
 	 * @throws UtilException 调用注解中的方法时执行异常
 	 * @throws UtilException 调用注解中的方法时执行异常
@@ -121,11 +121,10 @@ public class AnnotationUtil {
 				if (ArrayUtil.isEmpty(t.getParameterTypes())) {
 				if (ArrayUtil.isEmpty(t.getParameterTypes())) {
 					// 只读取无参方法
 					// 只读取无参方法
 					final String name = t.getName();
 					final String name = t.getName();
-					if ("hashCode".equals(name) || "toString".equals(name) || "annotationType".equals(name)) {
-						// 跳过自有的几个方法
-						return false;
-					}
-					return true;
+					// 跳过自有的几个方法
+					return (false == "hashCode".equals(name)) //
+							&& (false == "toString".equals(name)) //
+							&& (false == "annotationType".equals(name));
 				}
 				}
 				return false;
 				return false;
 			}
 			}
@@ -140,7 +139,7 @@ public class AnnotationUtil {
 
 
 	/**
 	/**
 	 * 获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
 	 * 获取注解类的保留时间,可选值 SOURCE(源码时),CLASS(编译时),RUNTIME(运行时),默认为 CLASS
-	 * 
+	 *
 	 * @param annotationType 注解类
 	 * @param annotationType 注解类
 	 * @return 保留时间枚举
 	 * @return 保留时间枚举
 	 */
 	 */
@@ -154,14 +153,14 @@ public class AnnotationUtil {
 
 
 	/**
 	/**
 	 * 获取注解类可以用来修饰哪些程序元素,如 TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER 等
 	 * 获取注解类可以用来修饰哪些程序元素,如 TYPE, METHOD, CONSTRUCTOR, FIELD, PARAMETER 等
-	 * 
+	 *
 	 * @param annotationType 注解类
 	 * @param annotationType 注解类
 	 * @return 注解修饰的程序元素数组
 	 * @return 注解修饰的程序元素数组
 	 */
 	 */
 	public static ElementType[] getTargetType(Class<? extends Annotation> annotationType) {
 	public static ElementType[] getTargetType(Class<? extends Annotation> annotationType) {
 		final Target target = annotationType.getAnnotation(Target.class);
 		final Target target = annotationType.getAnnotation(Target.class);
 		if (null == target) {
 		if (null == target) {
-			return new ElementType[] { ElementType.TYPE, //
+			return new ElementType[]{ElementType.TYPE, //
 					ElementType.FIELD, //
 					ElementType.FIELD, //
 					ElementType.METHOD, //
 					ElementType.METHOD, //
 					ElementType.PARAMETER, //
 					ElementType.PARAMETER, //
@@ -176,17 +175,17 @@ public class AnnotationUtil {
 
 
 	/**
 	/**
 	 * 是否会保存到 Javadoc 文档中
 	 * 是否会保存到 Javadoc 文档中
-	 * 
+	 *
 	 * @param annotationType 注解类
 	 * @param annotationType 注解类
 	 * @return 是否会保存到 Javadoc 文档中
 	 * @return 是否会保存到 Javadoc 文档中
 	 */
 	 */
 	public static boolean isDocumented(Class<? extends Annotation> annotationType) {
 	public static boolean isDocumented(Class<? extends Annotation> annotationType) {
 		return annotationType.isAnnotationPresent(Documented.class);
 		return annotationType.isAnnotationPresent(Documented.class);
 	}
 	}
-	
+
 	/**
 	/**
 	 * 是否可以被继承,默认为 false
 	 * 是否可以被继承,默认为 false
-	 * 
+	 *
 	 * @param annotationType 注解类
 	 * @param annotationType 注解类
 	 * @return 是否会保存到 Javadoc 文档中
 	 * @return 是否会保存到 Javadoc 文档中
 	 */
 	 */

+ 3 - 3
hutool-core/src/main/java/cn/hutool/core/collection/ArrayIter.java

@@ -18,11 +18,11 @@ public class ArrayIter<E> implements Iterator<E>, Iterable<E>, Serializable{
 	/** 数组 */
 	/** 数组 */
 	private Object array;
 	private Object array;
 	/** 起始位置 */
 	/** 起始位置 */
-	private int startIndex = 0;
+	private int startIndex;
 	/** 结束位置 */
 	/** 结束位置 */
-	private int endIndex = 0;
+	private int endIndex;
 	/** 当前位置 */
 	/** 当前位置 */
-	private int index = 0;
+	private int index;
 
 
 	/**
 	/**
 	 * 构造
 	 * 构造

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/collection/BoundedPriorityQueue.java

@@ -35,7 +35,7 @@ public class BoundedPriorityQueue<E> extends PriorityQueue<E>{
 
 
 			@Override
 			@Override
 			public int compare(E o1, E o2) {
 			public int compare(E o1, E o2) {
-				int cResult = 0;
+				int cResult;
 				if(comparator != null) {
 				if(comparator != null) {
 					cResult = comparator.compare(o1, o2);
 					cResult = comparator.compare(o1, o2);
 				}else {
 				}else {

+ 1 - 4
hutool-core/src/main/java/cn/hutool/core/collection/CopiedIter.java

@@ -25,7 +25,6 @@ import java.util.List;
 public class CopiedIter<E> implements Iterator<E>, Iterable<E>, Serializable {
 public class CopiedIter<E> implements Iterator<E>, Iterable<E>, Serializable {
 	private static final long serialVersionUID = 1L;
 	private static final long serialVersionUID = 1L;
 
 
-	private List<E> eleList = new LinkedList<>();
 	private Iterator<E> listIterator;
 	private Iterator<E> listIterator;
 	
 	
 	public static <V> CopiedIter<V> copyOf(Iterator<V> iterator){
 	public static <V> CopiedIter<V> copyOf(Iterator<V> iterator){
@@ -37,9 +36,7 @@ public class CopiedIter<E> implements Iterator<E>, Iterable<E>, Serializable {
 	 * @param iterator 被复制的Iterator
 	 * @param iterator 被复制的Iterator
 	 */
 	 */
 	public CopiedIter(Iterator<E> iterator) {
 	public CopiedIter(Iterator<E> iterator) {
-		while (iterator.hasNext()) {
-			eleList.add(iterator.next());
-		}
+		final List<E> eleList = CollUtil.newArrayList(iterator);
 		this.listIterator = eleList.iterator();
 		this.listIterator = eleList.iterator();
 	}
 	}
 
 

+ 6 - 9
hutool-core/src/main/java/cn/hutool/core/collection/IterUtil.java

@@ -376,7 +376,7 @@ public class IterUtil {
 	 * @return Map
 	 * @return Map
 	 */
 	 */
 	public static <K, V> HashMap<K, V> toMap(Iterable<Entry<K, V>> entryIter) {
 	public static <K, V> HashMap<K, V> toMap(Iterable<Entry<K, V>> entryIter) {
-		final HashMap<K, V> map = new HashMap<K, V>();
+		final HashMap<K, V> map = new HashMap<>();
 		if (isNotEmpty(entryIter)) {
 		if (isNotEmpty(entryIter)) {
 			for (Entry<K, V> entry : entryIter) {
 			for (Entry<K, V> entry : entryIter) {
 				map.put(entry.getKey(), entry.getValue());
 				map.put(entry.getKey(), entry.getValue());
@@ -500,7 +500,7 @@ public class IterUtil {
 	 * @return {@link Iterator}
 	 * @return {@link Iterator}
 	 */
 	 */
 	public static <E> Iterator<E> asIterator(Enumeration<E> e) {
 	public static <E> Iterator<E> asIterator(Enumeration<E> e) {
-		return new EnumerationIter<E>(e);
+		return new EnumerationIter<>(e);
 	}
 	}
 
 
 	/**
 	/**
@@ -571,13 +571,10 @@ public class IterUtil {
 	 */
 	 */
 	public static Class<?> getElementType(Iterator<?> iterator) {
 	public static Class<?> getElementType(Iterator<?> iterator) {
 		final Iterator<?> iter2 = new CopiedIter<>(iterator);
 		final Iterator<?> iter2 = new CopiedIter<>(iterator);
-		if (null != iter2) {
-			Object t;
-			while (iter2.hasNext()) {
-				t = iter2.next();
-				if (null != t) {
-					return t.getClass();
-				}
+		if (iter2.hasNext()) {
+			final Object t = iter2.next();
+			if (null != t) {
+				return t.getClass();
 			}
 			}
 		}
 		}
 		return null;
 		return null;