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.
This commit is contained in:
Rafael González Castillero 2022-03-21 16:30:43 +01:00 committed by GitHub
parent 0a48976ccb
commit e159919ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
/**