Minor: Rename StringUtils#isEmpty to #isBlank

- Better fits the naming used by other tools and also the JDK (String#isBlank as of JDK 11)
This commit is contained in:
ljacqu
2022-12-30 08:44:29 +01:00
parent 779e62674e
commit 9fd532d798
20 changed files with 42 additions and 46 deletions
@@ -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
@@ -131,7 +131,7 @@ public class CommandHandler {
private static List<String> skipEmptyArguments(String[] args) {
List<String> cleanArguments = new ArrayList<>();
for (String argument : args) {
if (!StringUtils.isEmpty(argument)) {
if (!StringUtils.isBlank(argument)) {
cleanArguments.add(argument);
}
}
@@ -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) + "...";
@@ -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);
@@ -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);
@@ -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);
@@ -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);
}
}
@@ -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() {
@@ -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"));
@@ -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<String> 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
@@ -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);
}
}