Remove StringUtils#join in favor of String#join (Java 8)

This commit is contained in:
ljacqu
2016-10-02 12:44:10 +02:00
parent e07c685d2a
commit 71ac86ff02
19 changed files with 27 additions and 181 deletions
@@ -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);
}
}