mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-03-02 10:41:43 +01:00
Remove StringUtils#join in favor of String#join (Java 8)
This commit is contained in:
parent
e07c685d2a
commit
71ac86ff02
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<String> labels) {
|
||||
return StringUtils.join(" ", labels);
|
||||
}
|
||||
|
||||
public static String constructCommandPath(CommandDescription command) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String prefix = "/";
|
||||
|
@ -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<String> accountList) {
|
||||
sender.sendMessage("[AuthMe] " + playerName + " has " + accountList.size() + " accounts.");
|
||||
String message = "[AuthMe] " + StringUtils.join(", ", accountList) + ".";
|
||||
String message = "[AuthMe] " + String.join(", ", accountList) + ".";
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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<S extends DataSource> 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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -296,17 +296,12 @@ public class CommandInitializerTest {
|
||||
* @return List of all bindings that lead to the command
|
||||
*/
|
||||
private static List<String> 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<String> bindings = new ArrayList<>(command.getLabels().size());
|
||||
for (String label : command.getLabels()) {
|
||||
bindings.add(StringUtils.join(" ", parentPath, label));
|
||||
bindings.add(parentPath + label);
|
||||
}
|
||||
return bindings;
|
||||
}
|
||||
|
@ -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<String> 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<String> parts = Collections.emptyList();
|
||||
|
||||
// when
|
||||
String str = CommandUtils.labelsToString(parts);
|
||||
|
||||
// then
|
||||
assertThat(str, equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPrintLabels() {
|
||||
// given
|
||||
List<String> labels = Arrays.asList("authme", "help", "reload");
|
||||
|
||||
// when
|
||||
String result = CommandUtils.labelsToString(labels);
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo("authme help reload"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCommandPath() {
|
||||
// given
|
||||
|
@ -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)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> 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<String> 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
|
||||
|
@ -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<Class<?>> coll) {
|
||||
Collection<String> classNames = Collections2.transform(coll, Class::getSimpleName);
|
||||
return StringUtils.join(", ", classNames);
|
||||
return coll.stream()
|
||||
.map(Class::getSimpleName)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user