diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java index e195c4752..040894f95 100644 --- a/src/main/java/fr/xephi/authme/command/CommandDescription.java +++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java @@ -226,8 +226,8 @@ public class CommandDescription { */ public CommandDescription build() { checkArgument(!Utils.isCollectionEmpty(labels), "Labels may not be empty"); - checkArgument(!StringUtils.isEmpty(description), "Description may not be empty"); - checkArgument(!StringUtils.isEmpty(detailedDescription), "Detailed description may not be empty"); + checkArgument(!StringUtils.isBlank(description), "Description may not be empty"); + checkArgument(!StringUtils.isBlank(detailedDescription), "Detailed description may not be empty"); checkArgument(executableCommand != null, "Executable command must be set"); // parents and permissions may be null; arguments may be empty diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java index 27445e02e..08629c6f5 100644 --- a/src/main/java/fr/xephi/authme/command/CommandHandler.java +++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java @@ -131,7 +131,7 @@ public class CommandHandler { private static List skipEmptyArguments(String[] args) { List cleanArguments = new ArrayList<>(); for (String argument : args) { - if (!StringUtils.isEmpty(argument)) { + if (!StringUtils.isBlank(argument)) { cleanArguments.add(argument); } } diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/debug/PlayerAuthViewer.java b/src/main/java/fr/xephi/authme/command/executable/authme/debug/PlayerAuthViewer.java index ae314e098..99115cfe2 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/debug/PlayerAuthViewer.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/debug/PlayerAuthViewer.java @@ -89,7 +89,7 @@ class PlayerAuthViewer implements DebugSection { * or empty string if the string is null or empty */ private static String safeSubstring(String str, int length) { - if (StringUtils.isEmpty(str)) { + if (StringUtils.isBlank(str)) { return ""; } else if (str.length() < length) { return str.substring(0, str.length() / 2) + "..."; diff --git a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java index 9ceccbaf7..b125bf0a8 100644 --- a/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java +++ b/src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java @@ -160,7 +160,7 @@ public class OnJoinVerifier implements Reloadable { if (auth != null && settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE)) { String realName = auth.getRealName(); // might be null or "Player" - if (StringUtils.isEmpty(realName) || "Player".equals(realName)) { + if (StringUtils.isBlank(realName) || "Player".equals(realName)) { dataSource.updateRealName(connectingName.toLowerCase(Locale.ROOT), connectingName); } else if (!realName.equals(connectingName)) { throw new FailedVerificationException(MessageKey.INVALID_NAME_CASE, realName, connectingName); diff --git a/src/main/java/fr/xephi/authme/mail/SendMailSsl.java b/src/main/java/fr/xephi/authme/mail/SendMailSsl.java index 8c7e1bfff..b7e9fd41f 100644 --- a/src/main/java/fr/xephi/authme/mail/SendMailSsl.java +++ b/src/main/java/fr/xephi/authme/mail/SendMailSsl.java @@ -51,11 +51,11 @@ public class SendMailSsl { * @throws EmailException if the mail is invalid */ public HtmlEmail initializeMail(String emailAddress) throws EmailException { - String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS)) + String senderMail = StringUtils.isBlank(settings.getProperty(EmailSettings.MAIL_ADDRESS)) ? settings.getProperty(EmailSettings.MAIL_ACCOUNT) : settings.getProperty(EmailSettings.MAIL_ADDRESS); - String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)) + String senderName = StringUtils.isBlank(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)) ? senderMail : settings.getProperty(EmailSettings.MAIL_SENDER_NAME); String mailPassword = settings.getProperty(EmailSettings.MAIL_PASSWORD); diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index 113393d25..7399d0ca0 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -324,7 +324,7 @@ public class PermissionsManager implements Reloadable { * False is also returned if this feature isn't supported for the current permissions system. */ public boolean addGroup(OfflinePlayer player, UserGroup groupName) { - if (!isEnabled() || StringUtils.isEmpty(groupName.getGroupName())) { + if (!isEnabled() || StringUtils.isBlank(groupName.getGroupName())) { return false; } return handler.addToGroup(player, groupName); diff --git a/src/main/java/fr/xephi/authme/service/JoinMessageService.java b/src/main/java/fr/xephi/authme/service/JoinMessageService.java index 29f2caa04..d4c5b4c67 100644 --- a/src/main/java/fr/xephi/authme/service/JoinMessageService.java +++ b/src/main/java/fr/xephi/authme/service/JoinMessageService.java @@ -38,7 +38,7 @@ public class JoinMessageService { */ public void sendMessage(String playerName) { String joinMessage = joinMessages.remove(playerName); - if (!StringUtils.isEmpty(joinMessage)) { + if (!StringUtils.isBlank(joinMessage)) { bukkitService.broadcastMessage(joinMessage); } } diff --git a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index 2152baf5c..fe035a8b2 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -114,7 +114,7 @@ public class SettingsMigrationService extends PlainMigrationService { // Old other accounts // -------- public boolean hasOldOtherAccountsCommand() { - return !StringUtils.isEmpty(oldOtherAccountsCommand); + return !StringUtils.isBlank(oldOtherAccountsCommand); } public String getOldOtherAccountsCommand() { diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 6a8b7fa72..47e9711de 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -293,7 +293,7 @@ public class SpawnLoader implements Reloadable { String prefix = pathPrefix + "."; String worldName = configuration.getString(prefix + "world"); World world = Bukkit.getWorld(worldName); - if (!StringUtils.isEmpty(worldName) && world != null) { + if (!StringUtils.isBlank(worldName) && world != null) { return new Location(world, configuration.getDouble(prefix + "x"), configuration.getDouble(prefix + "y"), configuration.getDouble(prefix + "z"), getFloat(configuration, prefix + "yaw"), getFloat(configuration, prefix + "pitch")); @@ -315,7 +315,7 @@ public class SpawnLoader implements Reloadable { String prefix = pathPrefix + "."; String worldName = configuration.getString(prefix + "World"); World world = Bukkit.getWorld(worldName); - if (!StringUtils.isEmpty(worldName) && world != null) { + if (!StringUtils.isBlank(worldName) && world != null) { return new Location(world, configuration.getDouble(prefix + "X"), configuration.getDouble(prefix + "Y"), configuration.getDouble(prefix + "Z"), getFloat(configuration, prefix + "Yaw"), getFloat(configuration, prefix + "Pitch")); diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index 5c8613005..8a8636786 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -14,12 +14,11 @@ public final class StringUtils { } /** - * Get the difference of two strings. + * Calculates the difference of two strings. * - * @param first First string - * @param second Second string - * - * @return The difference value + * @param first first string + * @param second second string + * @return the difference value */ public static double getDifference(String first, String second) { // Make sure the strings are valid. @@ -35,12 +34,11 @@ public final class StringUtils { } /** - * Return whether the given string contains any of the provided elements. + * Returns whether the given string contains any of the provided elements. * - * @param str The string to analyze - * @param pieces The items to check the string for - * - * @return True if the string contains at least one of the items + * @param str the string to analyze + * @param pieces the items to check the string for + * @return true if the string contains at least one of the items */ public static boolean containsAny(String str, Iterable pieces) { if (str == null) { @@ -58,21 +56,19 @@ public final class StringUtils { * Null-safe method for checking whether a string is empty. Note that the string * is trimmed, so this method also considers a string with whitespace as empty. * - * @param str The string to verify - * - * @return True if the string is empty, false otherwise + * @param str the string to verify + * @return true if the string is empty, false otherwise */ - public static boolean isEmpty(String str) { + public static boolean isBlank(String str) { return str == null || str.trim().isEmpty(); } /** - * Check that the given needle is in the middle of the haystack, i.e. that the haystack + * Checks that the given needle is in the middle of the haystack, i.e. that the haystack * contains the needle and that it is not at the very start or end. * * @param needle the needle to search for * @param haystack the haystack to search in - * * @return true if the needle is in the middle of the word, false otherwise */ // Note ljacqu 20170314: `needle` is restricted to char type intentionally because something like diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java index 74c3088e3..4165b0078 100644 --- a/src/main/java/fr/xephi/authme/util/Utils.java +++ b/src/main/java/fr/xephi/authme/util/Utils.java @@ -105,6 +105,6 @@ public final class Utils { * @return true if the email is empty */ public static boolean isEmailEmpty(String email) { - return StringUtils.isEmpty(email) || "your@email.com".equalsIgnoreCase(email); + return StringUtils.isBlank(email) || "your@email.com".equalsIgnoreCase(email); } } diff --git a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java index 964192f30..5cac2462a 100644 --- a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java @@ -138,11 +138,11 @@ public class CommandInitializerTest { String forCommandText = " for command with labels '" + command.getLabels() + "'"; assertThat("has description" + forCommandText, - StringUtils.isEmpty(command.getDescription()), equalTo(false)); + StringUtils.isBlank(command.getDescription()), equalTo(false)); assertThat("short description doesn't end in '.'" + forCommandText, command.getDescription().endsWith("."), equalTo(false)); assertThat("has detailed description" + forCommandText, - StringUtils.isEmpty(command.getDetailedDescription()), equalTo(false)); + StringUtils.isBlank(command.getDetailedDescription()), equalTo(false)); assertThat("detailed description ends in '.'" + forCommandText, command.getDetailedDescription().endsWith("."), equalTo(true)); } diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java index 22533acde..cad80f9f0 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/ConverterCommandTest.java @@ -93,7 +93,7 @@ public class ConverterCommandTest { // when / then for (Map.Entry> entry : ConverterCommand.CONVERTERS.entrySet()) { assertThat("Name is not null or empty", - StringUtils.isEmpty(entry.getKey()), equalTo(false)); + StringUtils.isBlank(entry.getKey()), equalTo(false)); assertThat("Converter class is unique for each entry", classes.add(entry.getValue()), equalTo(true)); diff --git a/src/test/java/fr/xephi/authme/command/help/HelpMessageAndHelpSectionConsistencyTest.java b/src/test/java/fr/xephi/authme/command/help/HelpMessageAndHelpSectionConsistencyTest.java index c0841139f..02a42ba99 100644 --- a/src/test/java/fr/xephi/authme/command/help/HelpMessageAndHelpSectionConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/command/help/HelpMessageAndHelpSectionConsistencyTest.java @@ -23,14 +23,14 @@ public class HelpMessageAndHelpSectionConsistencyTest { // when / then for (HelpMessage message : HelpMessage.values()) { assertThat("Key for message '" + message + "' is empty", - StringUtils.isEmpty(message.getKey()), equalTo(false)); + StringUtils.isBlank(message.getKey()), equalTo(false)); if (!keys.add(message.getKey())) { fail("Key for message '" + message + "' is already used elsewhere"); } } for (HelpSection section : HelpSection.values()) { assertThat("Key for section '" + section + "' is empty", - StringUtils.isEmpty(section.getKey()), equalTo(false)); + StringUtils.isBlank(section.getKey()), equalTo(false)); if (!keys.add(section.getKey())) { fail("Key for section '" + section + "' is already used elsewhere"); } diff --git a/src/test/java/fr/xephi/authme/message/MessageKeyTest.java b/src/test/java/fr/xephi/authme/message/MessageKeyTest.java index b28116341..c60305d68 100644 --- a/src/test/java/fr/xephi/authme/message/MessageKeyTest.java +++ b/src/test/java/fr/xephi/authme/message/MessageKeyTest.java @@ -27,7 +27,7 @@ public class MessageKeyTest { String key = messageKey.getKey(); if (!keys.add(key)) { fail("Found key '" + messageKey.getKey() + "' twice!"); - } else if (StringUtils.isEmpty(key)) { + } else if (StringUtils.isBlank(key)) { fail("Key for message key '" + messageKey + "' is empty"); } } diff --git a/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java b/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java index 1679e9ac3..5243528fc 100644 --- a/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/message/MessagesFileConsistencyTest.java @@ -40,7 +40,7 @@ public class MessagesFileConsistencyTest { final String key = messageKey.getKey(); final String message = reader.getString(key); - if (StringUtils.isEmpty(message)) { + if (StringUtils.isBlank(message)) { errors.add("Messages file should have message for key '" + key + "'"); return; } diff --git a/src/test/java/fr/xephi/authme/message/YamlTextFileCheckerTest.java b/src/test/java/fr/xephi/authme/message/YamlTextFileCheckerTest.java index 98a87e757..59c7b1b5a 100644 --- a/src/test/java/fr/xephi/authme/message/YamlTextFileCheckerTest.java +++ b/src/test/java/fr/xephi/authme/message/YamlTextFileCheckerTest.java @@ -81,7 +81,7 @@ public class YamlTextFileCheckerTest { private void checkFile(File file, String mandatoryKey, List errors) { try { PropertyReader reader = new YamlFileReader(file); - if (StringUtils.isEmpty(reader.getString(mandatoryKey))) { + if (StringUtils.isBlank(reader.getString(mandatoryKey))) { errors.add("Message for '" + mandatoryKey + "' is empty"); } } catch (Exception e) { diff --git a/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java b/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java index e59dae647..8ebcbda1e 100644 --- a/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/security/HashAlgorithmIntegrationTest.java @@ -74,9 +74,9 @@ public class HashAlgorithmIntegrationTest { } HashedPassword hashedPassword = method.computeHash("pwd", "name"); assertThat("Salt should not be null if method.hasSeparateSalt(), and vice versa. Method: '" - + method + "'", StringUtils.isEmpty(hashedPassword.getSalt()), equalTo(!method.hasSeparateSalt())); + + method + "'", StringUtils.isBlank(hashedPassword.getSalt()), equalTo(!method.hasSeparateSalt())); assertThat("Hash should not be empty for method '" + method + "'", - StringUtils.isEmpty(hashedPassword.getHash()), equalTo(false)); + StringUtils.isBlank(hashedPassword.getHash()), equalTo(false)); } } } diff --git a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java index 39a3eb934..fcd000d95 100644 --- a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java @@ -49,15 +49,15 @@ public class StringUtilsTest { } @Test - public void shouldCheckIsEmptyUtil() { + public void shouldCheckIfIsBlankString() { // Should be true for null/empty/whitespace - assertTrue(StringUtils.isEmpty(null)); - assertTrue(StringUtils.isEmpty("")); - assertTrue(StringUtils.isEmpty(" \t")); + assertTrue(StringUtils.isBlank(null)); + assertTrue(StringUtils.isBlank("")); + assertTrue(StringUtils.isBlank(" \t")); // Should be false if string has content - assertFalse(StringUtils.isEmpty("P")); - assertFalse(StringUtils.isEmpty(" test")); + assertFalse(StringUtils.isBlank("P")); + assertFalse(StringUtils.isBlank(" test")); } @Test diff --git a/src/test/java/tools/messages/VerifyMessagesTask.java b/src/test/java/tools/messages/VerifyMessagesTask.java index 5b8407c7e..04e17bba9 100644 --- a/src/test/java/tools/messages/VerifyMessagesTask.java +++ b/src/test/java/tools/messages/VerifyMessagesTask.java @@ -44,7 +44,7 @@ public final class VerifyMessagesTask implements ToolTask { boolean addMissingKeys = "y".equalsIgnoreCase(scanner.nextLine()); List messageFiles; - if (StringUtils.isEmpty(inputFile)) { + if (StringUtils.isBlank(inputFile)) { messageFiles = getMessagesFiles(); } else { File customFile = new File(MAIN_RESOURCES_ROOT, MessagePathHelper.createMessageFilePath(inputFile));