From 57df709cd8d303c036d61128f6ecf094219245b8 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 8 Jun 2019 15:40:51 +0200 Subject: [PATCH] Replace things like size == 0 with isEmpty --- .../java/org/airsonic/player/controller/MoreController.java | 2 +- .../java/org/airsonic/player/controller/UploadController.java | 2 +- .../airsonic/player/security/JWTAuthenticationProvider.java | 4 ++-- .../java/org/airsonic/player/service/SettingsService.java | 2 +- .../org/airsonic/player/service/metadata/MetaDataParser.java | 2 +- .../src/main/java/org/airsonic/player/util/StringUtil.java | 2 +- .../src/main/java/org/airsonic/player/util/Util.java | 2 +- .../airsonic/player/validator/PasswordSettingsValidator.java | 2 +- .../org/airsonic/player/validator/UserSettingsValidator.java | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/MoreController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/MoreController.java index 7c30fd9c..c5663a02 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/MoreController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/MoreController.java @@ -67,7 +67,7 @@ public class MoreController { String uploadDirectory = null; List musicFolders = settingsService.getMusicFoldersForUser(user.getUsername()); - if (musicFolders.size() > 0) { + if (!musicFolders.isEmpty()) { uploadDirectory = new File(musicFolders.get(0).getPath(), "Incoming").getPath(); } diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/UploadController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/UploadController.java index 722fe717..428aa965 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/UploadController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/UploadController.java @@ -122,7 +122,7 @@ public class UploadController { if (!item.isFormField()) { String fileName = item.getName(); - if (fileName.trim().length() > 0) { + if (!fileName.trim().isEmpty()) { File targetFile = new File(dir, new File(fileName).getName()); diff --git a/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java b/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java index 762874be..6d144b07 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java +++ b/airsonic-main/src/main/java/org/airsonic/player/security/JWTAuthenticationProvider.java @@ -78,8 +78,8 @@ public class JWTAuthenticationProvider implements AuthenticationProvider { MapDifference> difference = Maps.difference(expected.getQueryParams(), requested.getQueryParams()); - if(difference.entriesDiffering().size() != 0 || - difference.entriesOnlyOnLeft().size() != 0 || + if(!difference.entriesDiffering().isEmpty() || + !difference.entriesOnlyOnLeft().isEmpty() || difference.entriesOnlyOnRight().size() != 1 || difference.entriesOnlyOnRight().get(JWTSecurityService.JWT_PARAM_NAME) == null) { logger.debug("False: expected query params [{}] do not match requested query params [{}]", expected.getQueryParams(), requested.getQueryParams()); diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java b/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java index b74e4943..be588141 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/SettingsService.java @@ -764,7 +764,7 @@ public class SettingsService { } private void compileExcludePattern() { - if (getExcludePatternString() != null && getExcludePatternString().trim().length() > 0) { + if (getExcludePatternString() != null && !getExcludePatternString().trim().isEmpty()) { excludePattern = Pattern.compile(getExcludePatternString()); } else { excludePattern = null; diff --git a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/MetaDataParser.java b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/MetaDataParser.java index 95cc43f1..6dfac02f 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/service/metadata/MetaDataParser.java +++ b/airsonic-main/src/main/java/org/airsonic/player/service/metadata/MetaDataParser.java @@ -164,6 +164,6 @@ public abstract class MetaDataParser { } String result = title.replaceFirst("^\\d{2}[. -]+", ""); - return result.length() == 0 ? title : result; + return result.isEmpty() ? title : result; } } \ No newline at end of file diff --git a/airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java b/airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java index 17d30bd2..b389fd93 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java +++ b/airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java @@ -285,7 +285,7 @@ public final class StringUtil { List result = new ArrayList(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { line = line.trim(); - if (!line.startsWith("#") && line.length() > 0) { + if (!line.startsWith("#") && !line.isEmpty()) { result.add(line); } } diff --git a/airsonic-main/src/main/java/org/airsonic/player/util/Util.java b/airsonic-main/src/main/java/org/airsonic/player/util/Util.java index 7fdb8f37..8cbd8cdb 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/util/Util.java +++ b/airsonic-main/src/main/java/org/airsonic/player/util/Util.java @@ -132,7 +132,7 @@ public final class Util { public static String getURLForRequest(HttpServletRequest request) { String url = request.getRequestURL().toString(); String queryString = request.getQueryString(); - if (queryString != null && queryString.length() > 0) url += "?" + queryString; + if (queryString != null && !queryString.isEmpty()) url += "?" + queryString; return url; } diff --git a/airsonic-main/src/main/java/org/airsonic/player/validator/PasswordSettingsValidator.java b/airsonic-main/src/main/java/org/airsonic/player/validator/PasswordSettingsValidator.java index f9e4ee2e..402a8609 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/validator/PasswordSettingsValidator.java +++ b/airsonic-main/src/main/java/org/airsonic/player/validator/PasswordSettingsValidator.java @@ -40,7 +40,7 @@ public class PasswordSettingsValidator implements Validator { public void validate(Object obj, Errors errors) { PasswordSettingsCommand command = (PasswordSettingsCommand) obj; - if (command.getPassword() == null || command.getPassword().length() == 0) { + if (command.getPassword() == null || command.getPassword().isEmpty()) { errors.rejectValue("password", "usersettings.nopassword"); } else if (!command.getPassword().equals(command.getConfirmPassword())) { errors.rejectValue("password", "usersettings.wrongpassword"); diff --git a/airsonic-main/src/main/java/org/airsonic/player/validator/UserSettingsValidator.java b/airsonic-main/src/main/java/org/airsonic/player/validator/UserSettingsValidator.java index 72148b03..e3d912f6 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/validator/UserSettingsValidator.java +++ b/airsonic-main/src/main/java/org/airsonic/player/validator/UserSettingsValidator.java @@ -60,7 +60,7 @@ public class UserSettingsValidator implements Validator { String confirmPassword = command.getConfirmPassword(); if (command.isNewUser()) { - if (username == null || username.length() == 0) { + if (username == null || username.isEmpty()) { errors.rejectValue("username", "usersettings.nousername"); } else if (securityService.getUserByName(username) != null) { errors.rejectValue("username", "usersettings.useralreadyexists");