diff --git a/src/main/java/fr/xephi/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java index 79f1bf9f..ab2d72db 100644 --- a/src/main/java/fr/xephi/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -4,7 +4,6 @@ import fr.xephi.authme.datasource.DataSourceType; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.BackupSettings; import fr.xephi.authme.settings.properties.DatabaseSettings; -import fr.xephi.authme.util.StringUtils; import java.io.File; import java.io.FileInputStream; @@ -47,7 +46,7 @@ public class PerformBackup { this.tblname = settings.getProperty(DatabaseSettings.MYSQL_TABLE); String dateString = DATE_FORMAT.format(new Date()); - this.path = StringUtils.join(File.separator, + this.path = String.join(File.separator, instance.getDataFolder().getPath(), "backups", "backup" + dateString); } diff --git a/src/main/java/fr/xephi/authme/command/CommandUtils.java b/src/main/java/fr/xephi/authme/command/CommandUtils.java index 016cbce1..9ea1f5c5 100644 --- a/src/main/java/fr/xephi/authme/command/CommandUtils.java +++ b/src/main/java/fr/xephi/authme/command/CommandUtils.java @@ -1,7 +1,6 @@ package fr.xephi.authme.command; import com.google.common.collect.Lists; -import fr.xephi.authme.util.StringUtils; import java.util.ArrayList; import java.util.List; @@ -25,18 +24,6 @@ public final class CommandUtils { return command.getArguments().size(); } - /** - * Provide a textual representation of a list of labels to show it as a command. For example, a list containing - * the items ["authme", "register", "player"] will return "authme register player". - * - * @param labels The labels to format - * - * @return The space-separated labels - */ - public static String labelsToString(Iterable labels) { - return StringUtils.join(" ", labels); - } - public static String constructCommandPath(CommandDescription command) { StringBuilder sb = new StringBuilder(); String prefix = "/"; diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index 3b446a7f..f8d39d05 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -6,7 +6,6 @@ import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import javax.inject.Inject; @@ -70,7 +69,7 @@ public class AccountsCommand implements ExecutableCommand { private static void outputAccountsList(CommandSender sender, String playerName, List accountList) { sender.sendMessage("[AuthMe] " + playerName + " has " + accountList.size() + " accounts."); - String message = "[AuthMe] " + StringUtils.join(", ", accountList) + "."; + String message = "[AuthMe] " + String.join(", ", accountList) + "."; sender.sendMessage(message); } } diff --git a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java index ebe8c0cb..cb9793d2 100644 --- a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java +++ b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java @@ -187,7 +187,7 @@ public class HelpProvider implements SettingsDependent { } lines.add(ChatColor.GOLD + "Commands:"); - String parentCommandPath = CommandUtils.labelsToString(parentLabels); + String parentCommandPath = String.join(" ", parentLabels); for (CommandDescription child : command.getChildren()) { lines.add(" /" + parentCommandPath + " " + child.getLabels().get(0) + ChatColor.GRAY + ChatColor.ITALIC + ": " + child.getDescription()); diff --git a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java b/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java index 19be41c3..083cfe2c 100644 --- a/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java +++ b/src/main/java/fr/xephi/authme/converter/AbstractDataSourceConverter.java @@ -4,7 +4,6 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSourceType; -import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -67,7 +66,7 @@ public abstract class AbstractDataSourceConverter implemen if (!skippedPlayers.isEmpty()) { logAndSendMessage(sender, "Skipped conversion for players which were already in " - + destinationType + ": " + StringUtils.join(", ", skippedPlayers)); + + destinationType + ": " + String.join(", ", skippedPlayers)); } logAndSendMessage(sender, "Database successfully converted from " + source.getType() + " to " + destinationType); diff --git a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java index b189fd07..fcbaa1b6 100644 --- a/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java +++ b/src/main/java/fr/xephi/authme/listener/FailedVerificationException.java @@ -1,7 +1,6 @@ package fr.xephi.authme.listener; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.util.StringUtils; /** * Exception thrown when a verification has failed. @@ -27,7 +26,7 @@ public class FailedVerificationException extends Exception { @Override public String toString() { - return getClass().getSimpleName() + ": reason=" + (reason == null ? "null" : reason) - + ";args=" + (args == null ? "null" : StringUtils.join(", ", args)); + return getClass().getSimpleName() + ": reason=" + reason + + ";args=" + (args == null ? "null" : String.join(", ", args)); } } diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 8be5b540..21eae43d 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -102,7 +102,7 @@ public class AsyncRegister implements AsynchronousProcess { List otherAccounts = database.getAllAuthsByIp(ip); if (otherAccounts.size() >= maxRegPerIp) { service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerIp), - Integer.toString(otherAccounts.size()), StringUtils.join(", ", otherAccounts)); + Integer.toString(otherAccounts.size()), String.join(", ", otherAccounts)); return false; } } diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index 377dd9f7..a02418ca 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -5,7 +5,6 @@ import net.ricecode.similarity.StringSimilarityService; import net.ricecode.similarity.StringSimilarityServiceImpl; import java.io.File; -import java.util.Arrays; /** * Utility class for String operations. @@ -69,44 +68,6 @@ public final class StringUtils { return str == null || str.trim().isEmpty(); } - /** - * Join a list of elements into a single string with the specified delimiter. - * - * @param delimiter The delimiter to use - * @param elements The elements to join - * - * @return A new String that is composed of the elements separated by the delimiter - */ - public static String join(String delimiter, Iterable elements) { - if (delimiter == null) { - delimiter = ""; - } - StringBuilder sb = new StringBuilder(); - for (String element : elements) { - if (!isEmpty(element)) { - // Add the separator if it isn't the first element - if (sb.length() > 0) { - sb.append(delimiter); - } - sb.append(element); - } - } - - return sb.toString(); - } - - /** - * Join a list of elements into a single string with the specified delimiter. - * - * @param delimiter The delimiter to use - * @param elements The elements to join - * - * @return A new String that is composed of the elements separated by the delimiter - */ - public static String join(String delimiter, String... elements) { - return join(delimiter, Arrays.asList(elements)); - } - /** * Format the information from a Throwable as string, retaining the type and its message. * @@ -126,7 +87,7 @@ public final class StringUtils { * @return The created path */ public static String makePath(String... elements) { - return join(File.separator, elements); + return String.join(File.separator, elements); } } diff --git a/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java b/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java index 8d331f9c..6ae87df6 100644 --- a/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java +++ b/src/test/java/fr/xephi/authme/ConsoleLoggerTest.java @@ -4,7 +4,6 @@ import fr.xephi.authme.output.LogLevel; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.SecuritySettings; -import fr.xephi.authme.util.StringUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -135,7 +134,7 @@ public class ConsoleLoggerTest { assertThat(loggedLines.get(1), containsString("[WARN] Exception occurred: [IllegalStateException]: Test exception message")); // Check that we have this class' full name somewhere in the file -> stacktrace of Exception e - assertThat(StringUtils.join("", loggedLines), containsString(getClass().getCanonicalName())); + assertThat(String.join("", loggedLines), containsString(getClass().getCanonicalName())); } @Test diff --git a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java index d5db0c55..944424f5 100644 --- a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java @@ -296,17 +296,12 @@ public class CommandInitializerTest { * @return List of all bindings that lead to the command */ private static List getAbsoluteLabels(CommandDescription command) { - String parentPath = ""; - CommandDescription elem = command.getParent(); - while (elem != null) { - parentPath = elem.getLabels().get(0) + " " + parentPath; - elem = elem.getParent(); - } - parentPath = parentPath.trim(); + CommandDescription parent = command.getParent(); + String parentPath = (parent == null) ? "" : parent.getLabels().get(0) + " "; List bindings = new ArrayList<>(command.getLabels().size()); for (String label : command.getLabels()) { - bindings.add(StringUtils.join(" ", parentPath, label)); + bindings.add(parentPath + label); } return bindings; } diff --git a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java index bdff3c25..2d73549d 100644 --- a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java @@ -3,10 +3,6 @@ package fr.xephi.authme.command; import fr.xephi.authme.TestHelper; import org.junit.Test; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -15,42 +11,6 @@ import static org.junit.Assert.assertThat; */ public class CommandUtilsTest { - @Test - public void shouldPrintPartsForStringRepresentation() { - // given - Iterable parts = Arrays.asList("some", "parts", "for", "test"); - - // when - String str = CommandUtils.labelsToString(parts); - - // then - assertThat(str, equalTo("some parts for test")); - } - - @Test - public void shouldPrintEmptyStringForNoArguments() { - // given - List parts = Collections.emptyList(); - - // when - String str = CommandUtils.labelsToString(parts); - - // then - assertThat(str, equalTo("")); - } - - @Test - public void shouldPrintLabels() { - // given - List labels = Arrays.asList("authme", "help", "reload"); - - // when - String result = CommandUtils.labelsToString(labels); - - // then - assertThat(result, equalTo("authme help reload")); - } - @Test public void shouldReturnCommandPath() { // given diff --git a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java index 19685ff8..c77b5724 100644 --- a/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java +++ b/src/test/java/fr/xephi/authme/listener/OnJoinVerifierTest.java @@ -13,7 +13,6 @@ import fr.xephi.authme.settings.properties.ProtectionSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.ValidationService; import org.bukkit.Server; import org.bukkit.entity.Player; @@ -511,7 +510,7 @@ public class OnJoinVerifierTest { @Override public void describeTo(Description description) { description.appendValue("VerificationFailedException: reason=" + messageKey + ";args=" - + (args == null ? "null" : StringUtils.join(", ", args))); + + (args == null ? "null" : String.join(", ", args))); } }; } diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java b/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java index 607560d6..5cbf36a7 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesFileConsistencyTest.java @@ -32,7 +32,7 @@ public class MessagesFileConsistencyTest { if (!errors.isEmpty()) { fail("Validation errors in " + MESSAGES_FILE + ":\n- " - + StringUtils.join("\n- ", errors)); + + String.join("\n- ", errors)); } } @@ -55,7 +55,7 @@ public class MessagesFileConsistencyTest { if (!missingTags.isEmpty()) { String pluralS = missingTags.size() > 1 ? "s" : ""; errors.add(String.format("Message with key '%s' missing tag%s: %s", key, pluralS, - StringUtils.join(", ", missingTags))); + String.join(", ", missingTags))); } } } diff --git a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java b/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java index fc7b74e5..4f76882f 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesFileYamlCheckerTest.java @@ -48,7 +48,7 @@ public class MessagesFileYamlCheckerTest { // then if (!errors.isEmpty()) { - fail("Errors during verification of message files:\n-" + StringUtils.join("\n-", errors)); + fail("Errors during verification of message files:\n-" + String.join("\n-", errors)); } } diff --git a/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java b/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java index 55c22eb8..bd18df8a 100644 --- a/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/permission/PermissionConsistencyTest.java @@ -2,7 +2,6 @@ package fr.xephi.authme.permission; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -65,7 +64,7 @@ public class PermissionConsistencyTest { // then if (!errors.isEmpty()) { - fail("Found consistency issues!\n" + StringUtils.join("\n", errors)); + fail("Found consistency issues!\n" + String.join("\n", errors)); } } @@ -90,7 +89,7 @@ public class PermissionConsistencyTest { // then if (!errors.isEmpty()) { - fail("Found consistency issues!\n" + StringUtils.join("\n", errors)); + fail("Found consistency issues!\n" + String.join("\n", errors)); } } @@ -172,7 +171,7 @@ public class PermissionConsistencyTest { } if (!badChildren.isEmpty()) { errorList.add("Permission '" + definition.node + "' has children that are not logically below it: " - + StringUtils.join(", ", badChildren)); + + String.join(", ", badChildren)); } } diff --git a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java index a495254a..768dd98e 100644 --- a/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/ConfigFileConsistencyTest.java @@ -8,7 +8,6 @@ import com.github.authme.configme.resource.PropertyResource; import com.github.authme.configme.resource.YamlFileResource; import fr.xephi.authme.TestHelper; import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever; -import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -54,7 +53,7 @@ public class ConfigFileConsistencyTest { missingProperties.add(path); } } - fail("Found missing properties!\n-" + StringUtils.join("\n-", missingProperties)); + fail("Found missing properties!\n-" + String.join("\n-", missingProperties)); } } @@ -78,7 +77,7 @@ public class ConfigFileConsistencyTest { // then if (!unknownPaths.isEmpty()) { fail("Found " + unknownPaths.size() + " unknown property paths in the project's config.yml: \n- " - + StringUtils.join("\n- ", unknownPaths)); + + String.join("\n- ", unknownPaths)); } } diff --git a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java index a09ac87c..72826b4c 100644 --- a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java @@ -5,8 +5,6 @@ import org.junit.Test; import java.io.File; import java.net.MalformedURLException; -import java.util.Arrays; -import java.util.List; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -65,51 +63,6 @@ public class StringUtilsTest { assertFalse(StringUtils.isEmpty(" test")); } - @Test - public void shouldJoinStrings() { - // given - List elements = Arrays.asList("test", "for", null, "join", "StringUtils"); - - // when - String result = StringUtils.join(", ", elements); - - // then - assertThat(result, equalTo("test, for, join, StringUtils")); - } - - @Test - public void shouldJoinStringArray() { - // given - String[] elements = {"A", "test", "sentence", "for", "the join", null, "method"}; - - // when - String result = StringUtils.join("_", elements); - - // then - assertThat(result, equalTo("A_test_sentence_for_the join_method")); - } - - @Test - public void shouldNotHaveDelimiter() { - // given - List elements = Arrays.asList(" ", null, "\t", "hello", null); - - // when - String result = StringUtils.join("-", elements); - - // then - assertThat(result, equalTo("hello")); - } - - @Test - public void shouldJoinWithNullDelimiter() { - // given/when - String result = StringUtils.join(null, "A", "Few", "Words", "\n", "To", "Join"); - - // then - assertThat(result, equalTo("AFewWordsToJoin")); - } - @Test public void shouldFormatException() { // given diff --git a/src/test/java/tools/checktestmocks/CheckTestMocks.java b/src/test/java/tools/checktestmocks/CheckTestMocks.java index 8e301134..b6d79c07 100644 --- a/src/test/java/tools/checktestmocks/CheckTestMocks.java +++ b/src/test/java/tools/checktestmocks/CheckTestMocks.java @@ -1,10 +1,8 @@ package tools.checktestmocks; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import fr.xephi.authme.ClassCollector; import fr.xephi.authme.TestHelper; -import fr.xephi.authme.util.StringUtils; import org.mockito.Mock; import tools.utils.AutoToolTask; import tools.utils.InjectorUtils; @@ -16,6 +14,7 @@ import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; +import java.util.stream.Collectors; /** * Task checking if all tests' {@code @Mock} fields have a corresponding @@ -41,7 +40,7 @@ public class CheckTestMocks implements AutoToolTask { for (Class clazz : collector.collectClasses(c -> isTestClassWithMocks(c))) { checkClass(clazz); } - System.out.println(StringUtils.join("\n", errors)); + System.out.println(String.join("\n", errors)); } /** @@ -112,8 +111,9 @@ public class CheckTestMocks implements AutoToolTask { } private static String formatClassList(Collection> coll) { - Collection classNames = Collections2.transform(coll, Class::getSimpleName); - return StringUtils.join(", ", classNames); + return coll.stream() + .map(Class::getSimpleName) + .collect(Collectors.joining(", ")); } } diff --git a/src/test/java/tools/messages/translation/MessageExport.java b/src/test/java/tools/messages/translation/MessageExport.java index 270c460d..1b37347c 100644 --- a/src/test/java/tools/messages/translation/MessageExport.java +++ b/src/test/java/tools/messages/translation/MessageExport.java @@ -1,7 +1,5 @@ package tools.messages.translation; -import fr.xephi.authme.util.StringUtils; - /** * Container class for one translatable message. */ @@ -14,7 +12,7 @@ public class MessageExport { public MessageExport(String key, String[] tags, String defaultMessage, String translatedMessage) { this.key = key; - this.tags = StringUtils.join(",", tags); + this.tags = String.join(",", tags); this.defaultMessage = defaultMessage; this.translatedMessage = translatedMessage; }