From e159919ba540e59d6fb60d0b8c859c979ad81911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Gonz=C3=A1lez=20Castillero?= <64226756+rafgoncas1@users.noreply.github.com> Date: Mon, 21 Mar 2022 16:30:43 +0100 Subject: [PATCH] List/Map emptiness checking and stream variation (#11920) I have changed the way to check for empty maps and lists, instead of checking if the size is greater than 0, It is more understandable and faster using !x.isEmpty() method. Also, instead of using stream().filter().findFirst().isPresent(), it is recomendable using its equivalent stream().anyMatch() which as well makes it easier to understand and efficient. --- .../java/org/openapitools/codegen/CodegenOperation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java index ebafb6b5e42..ca384edfac4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java @@ -68,11 +68,11 @@ public class CodegenOperation { * @return true if parameter exists, false otherwise */ private static boolean nonEmpty(List params) { - return params != null && params.size() > 0; + return params != null && !params.isEmpty(); } private static boolean nonEmpty(Map params) { - return params != null && params.size() > 0; + return params != null && !params.isEmpty(); } /** @@ -189,7 +189,7 @@ public class CodegenOperation { * @return true if responses contain a default response, false otherwise */ public boolean getHasDefaultResponse() { - return responses.stream().filter(response -> response.isDefault).findFirst().isPresent(); + return responses.stream().anyMatch(response -> response.isDefault); } /**