From 86caedac5023dfb03dfe3fc9bea82bd51c9578d4 Mon Sep 17 00:00:00 2001 From: cal101 Date: Sun, 6 Jun 2021 13:37:57 +0000 Subject: [PATCH] [cleanup] erefactor/EclipseJdt - Invert equals arguments if parameter is constant string EclipseJdt cleanup 'InvertEquals' applied by erefactor. For EclipseJdt see https://www.eclipse.org/eclipse/news/4.19/jdt.php For erefactor see https://github.com/cal101/erefactor --- .../main/java/cn/hutool/core/bean/BeanDesc.java | 14 +++++++------- .../src/main/java/cn/hutool/core/img/ImgUtil.java | 2 +- .../src/main/java/cn/hutool/core/net/NetUtil.java | 2 +- .../src/main/java/cn/hutool/core/util/XmlUtil.java | 2 +- .../cn/hutool/core/collection/CollUtilTest.java | 6 +++--- .../cn/hutool/cron/timingwheel/TimerTaskList.java | 2 +- .../src/main/java/cn/hutool/http/HttpRequest.java | 2 +- .../java/cn/hutool/http/useragent/Platform.java | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/bean/BeanDesc.java b/hutool-core/src/main/java/cn/hutool/core/bean/BeanDesc.java index 1b97c84ff..5b32275dd 100644 --- a/hutool-core/src/main/java/cn/hutool/core/bean/BeanDesc.java +++ b/hutool-core/src/main/java/cn/hutool/core/bean/BeanDesc.java @@ -273,19 +273,19 @@ public class BeanDesc implements Serializable { if (fieldName.startsWith("is")) { // 字段已经是is开头 if (methodName.equals(fieldName) // isName -》 isName - || methodName.equals("get" + handledFieldName)// isName -》 getIsName - || methodName.equals("is" + handledFieldName)// isName -》 isIsName + || ("get" + handledFieldName).equals(methodName)// isName -》 getIsName + || ("is" + handledFieldName).equals(methodName)// isName -》 isIsName ) { return true; } - } else if (methodName.equals("is" + handledFieldName)) { + } else if (("is" + handledFieldName).equals(methodName)) { // 字段非is开头, name -》 isName return true; } } // 包括boolean的任何类型只有一种匹配情况:name -》 getName - return methodName.equals("get" + handledFieldName); + return ("get" + handledFieldName).equals(methodName); } /** @@ -324,15 +324,15 @@ public class BeanDesc implements Serializable { // 针对Boolean类型特殊检查 if (isBooleanField && fieldName.startsWith("is")) { // 字段是is开头 - if (methodName.equals("set" + StrUtil.removePrefix(fieldName, "is"))// isName -》 setName - || methodName.equals("set" + handledFieldName)// isName -》 setIsName + if (("set" + StrUtil.removePrefix(fieldName, "is")).equals(methodName)// isName -》 setName + || ("set" + handledFieldName).equals(methodName)// isName -》 setIsName ) { return true; } } // 包括boolean的任何类型只有一种匹配情况:name -》 setName - return methodName.equals("set" + fieldName); + return ("set" + fieldName).equals(methodName); } // ------------------------------------------------------------------------------------------------------ Private method end } diff --git a/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java b/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java index d7938c95e..b75e32e70 100644 --- a/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/img/ImgUtil.java @@ -1166,7 +1166,7 @@ public class ImgUtil { * @since 4.3.2 */ public static BufferedImage toBufferedImage(Image image, String imageType) { - final int type = imageType.equalsIgnoreCase(IMAGE_TYPE_PNG) + final int type = IMAGE_TYPE_PNG.equalsIgnoreCase(imageType) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; return toBufferedImage(image, type); diff --git a/hutool-core/src/main/java/cn/hutool/core/net/NetUtil.java b/hutool-core/src/main/java/cn/hutool/core/net/NetUtil.java index 0797b1677..ec40ab6a1 100644 --- a/hutool-core/src/main/java/cn/hutool/core/net/NetUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/net/NetUtil.java @@ -243,7 +243,7 @@ public class NetUtil { long cBegin = NetUtil.ipv4ToLong("192.168.0.0"); long cEnd = NetUtil.ipv4ToLong("192.168.255.255"); - isInnerIp = isInner(ipNum, aBegin, aEnd) || isInner(ipNum, bBegin, bEnd) || isInner(ipNum, cBegin, cEnd) || ipAddress.equals(LOCAL_IP); + isInnerIp = isInner(ipNum, aBegin, aEnd) || isInner(ipNum, bBegin, bEnd) || isInner(ipNum, cBegin, cEnd) || LOCAL_IP.equals(ipAddress); return isInnerIp; } diff --git a/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java index 85515d20d..659484535 100644 --- a/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/XmlUtil.java @@ -1508,7 +1508,7 @@ public class XmlUtil { */ @Override public String getNamespaceURI(String prefix) { - if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { + if (prefix == null || XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { return prefixUri.get(DEFAULT_NS); } else { return prefixUri.get(prefix); diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index 446716cb3..5b9ac9619 100644 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -102,7 +102,7 @@ public class CollUtilTest { Collection union = CollUtil.union(list1, list2); - Assert.assertEquals(3, CollUtil.count(union, t -> t.equals("b"))); + Assert.assertEquals(3, CollUtil.count(union, t -> "b".equals(t))); } @Test @@ -111,7 +111,7 @@ public class CollUtilTest { ArrayList list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d"); Collection intersection = CollUtil.intersection(list1, list2); - Assert.assertEquals(2, CollUtil.count(intersection, t -> t.equals("b"))); + Assert.assertEquals(2, CollUtil.count(intersection, t -> "b".equals(t))); } @Test @@ -236,7 +236,7 @@ public class CollUtilTest { final String[] result = new String[1]; CollUtil.forEach(map, (key, value, index) -> { - if (key.equals("a")) { + if ("a".equals(key)) { result[0] = value; } }); diff --git a/hutool-cron/src/main/java/cn/hutool/cron/timingwheel/TimerTaskList.java b/hutool-cron/src/main/java/cn/hutool/cron/timingwheel/TimerTaskList.java index 3e3d4b342..6de8c3323 100644 --- a/hutool-cron/src/main/java/cn/hutool/cron/timingwheel/TimerTaskList.java +++ b/hutool-cron/src/main/java/cn/hutool/cron/timingwheel/TimerTaskList.java @@ -76,7 +76,7 @@ public class TimerTaskList implements Delayed { */ public void removeTask(TimerTask timerTask) { synchronized (this) { - if (timerTask.timerTaskList.equals(this)) { + if (this.equals(timerTask.timerTaskList)) { timerTask.next.prev = timerTask.prev; timerTask.prev.next = timerTask.next; timerTask.timerTaskList = null; diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index df64abc75..36f4aa118 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -387,7 +387,7 @@ public class HttpRequest extends HttpBase { public boolean isKeepAlive() { String connection = header(Header.CONNECTION); if (connection == null) { - return !httpVersion.equalsIgnoreCase(HTTP_1_0); + return !HTTP_1_0.equalsIgnoreCase(httpVersion); } return false == "close".equalsIgnoreCase(connection); diff --git a/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java b/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java index c57b4cac6..70956ae4c 100644 --- a/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java +++ b/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java @@ -109,7 +109,7 @@ public class Platform extends UserAgentInfo { * @since 5.2.3 */ public boolean isIPhoneOrIPod() { - return IPHONE.equals(this) || IPOD.equals(this); + return this.equals(IPHONE) || this.equals(IPOD); } /** @@ -119,7 +119,7 @@ public class Platform extends UserAgentInfo { * @since 5.2.3 */ public boolean isIPad() { - return IPAD.equals(this); + return this.equals(IPAD); } /** @@ -139,7 +139,7 @@ public class Platform extends UserAgentInfo { * @since 5.2.3 */ public boolean isAndroid() { - return ANDROID.equals(this) || GOOGLE_TV.equals(this); + return this.equals(ANDROID) || this.equals(GOOGLE_TV); } }