From 6013591fac1444df88bb75542367633373603a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=85=B6=E8=8B=97?= Date: Thu, 5 Mar 2020 10:44:36 +0800 Subject: [PATCH] Polish containsAny of CollectionUtils by reusing findFirstMatch --- .../java/org/springframework/util/CollectionUtils.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index 84b1fd1c67f..1cd16243fd3 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -181,15 +181,7 @@ public abstract class CollectionUtils { * @return whether any of the candidates has been found */ public static boolean containsAny(Collection source, Collection candidates) { - if (isEmpty(source) || isEmpty(candidates)) { - return false; - } - for (Object candidate : candidates) { - if (source.contains(candidate)) { - return true; - } - } - return false; + return findFirstMatch(source, candidates) != null; } /**