From c8427181bebf65706f1db402ef4bab4197a9a199 Mon Sep 17 00:00:00 2001 From: wangxw Date: Wed, 3 Mar 2021 18:36:18 +0800 Subject: [PATCH] optimize size() method to isEmpty() --- .../src/main/java/com/alibaba/cola/dto/MultiResponse.java | 2 +- .../src/main/java/com/alibaba/cola/dto/PageResponse.java | 2 +- .../src/main/java/com/alibaba/cola/exception/Assert.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/MultiResponse.java b/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/MultiResponse.java index 6ee797575..3b0970305 100644 --- a/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/MultiResponse.java +++ b/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/MultiResponse.java @@ -26,7 +26,7 @@ public void setData(Collection data) { } public boolean isEmpty() { - return data == null || data.size() == 0; + return data == null || data.isEmpty(); } public boolean isNotEmpty() { diff --git a/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/PageResponse.java b/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/PageResponse.java index d46cfee0a..40f1fb0e5 100644 --- a/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/PageResponse.java +++ b/cola-components/cola-component-dto/src/main/java/com/alibaba/cola/dto/PageResponse.java @@ -75,7 +75,7 @@ public int getTotalPages() { } public boolean isEmpty() { - return data == null || data.size() == 0; + return data == null || data.isEmpty(); } public boolean isNotEmpty() { diff --git a/cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java b/cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java index 14adfe2fb..2012ff5a7 100644 --- a/cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java +++ b/cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java @@ -95,13 +95,13 @@ public static void notNull(Object object) { } public static void notEmpty(Collection collection, String errorCode, String errMessage) { - if (collection == null || collection.size() <= 0) { + if (collection == null || collection.isEmpty()) { throw new BizException(errorCode, errMessage); } } public static void notEmpty(Collection collection, String errMessage) { - if (collection == null || collection.size() <= 0) { + if (collection == null || collection.isEmpty()) { throw new BizException(errMessage); } }