Replaced usages of String#split with StringUtils#split

This commit is contained in:
Rsl1122 2019-08-30 15:04:51 +03:00
parent 27d436ce7f
commit 4547272783
21 changed files with 61 additions and 55 deletions

View File

@ -41,6 +41,7 @@ import com.djrapitops.plan.system.storage.file.PlanFiles;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -145,7 +146,7 @@ public class HtmlExport extends SpecificExport {
.replace("href=\"css/", "href=\"../css/")
.replace("src=\"plugins/", "src=\"../plugins/")
.replace("src=\"js/", "src=\"../js/");
List<String> lines = Arrays.asList(html.split("\n"));
List<String> lines = Arrays.asList(StringUtils.split(html, "\n"));
File htmlLocation = new File(getFolder(), "players");
Verify.isTrue(htmlLocation.exists() && htmlLocation.isDirectory() || htmlLocation.mkdirs(),

View File

@ -82,9 +82,7 @@ public class PlayerJSONParser {
Database db = dbSystem.getDatabase();
Map<UUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
String[] pieColors = Arrays.stream(theme.getValue(ThemeVal.GRAPH_WORLD_PIE).split(","))
.map(color -> color.trim().replace("\"", ""))
.toArray(String[]::new);
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);

View File

@ -285,9 +285,7 @@ public class GraphJSONParser {
public Map<String, Object> serverPreferencePieJSONAsMap() {
long now = System.currentTimeMillis();
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
String[] pieColors = Arrays.stream(theme.getValue(ThemeVal.GRAPH_WORLD_PIE).split(","))
.map(color -> color.trim().replace("\"", ""))
.toArray(String[]::new);
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
Map<String, Object> data = new HashMap<>();
data.put("server_pie_colors", pieColors);

View File

@ -26,11 +26,8 @@ import com.djrapitops.plan.system.settings.theme.ThemeVal;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Factory class for different objects representing HTML pie graphs.
@ -52,16 +49,8 @@ public class PieGraphFactory {
this.theme = theme;
}
public Pie activityPie_old(Map<String, Set<UUID>> activityData) {
String[] colors = theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
Map<String, Integer> flatActivityData = activityData.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().size()));
return new ActivityPie(flatActivityData, colors);
}
public Pie activityPie(Map<String, Integer> activityData) {
String[] colors = Arrays.stream(theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(","))
.map(color -> color.trim().replace("\"", ""))
.toArray(String[]::new);
String[] colors = theme.getPieColors(ThemeVal.GRAPH_ACTIVITY_PIE);
return new ActivityPie(activityData, colors);
}
@ -77,9 +66,7 @@ public class PieGraphFactory {
WorldAliasSettings worldAliasSettings = config.getWorldAliasSettings();
Map<String, Long> playtimePerAlias = worldAliasSettings.getPlaytimePerAlias(worldTimes);
Map<String, GMTimes> gmTimesPerAlias = worldAliasSettings.getGMTimesPerAlias(worldTimes);
String[] colors = Arrays.stream(theme.getValue(ThemeVal.GRAPH_WORLD_PIE).split(","))
.map(color -> color.trim().replace("\"", ""))
.toArray(String[]::new);
String[] colors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
boolean orderByPercentage = config.isTrue(DisplaySettings.ORDER_WORLD_PIE_BY_PERC);
return new WorldPie(playtimePerAlias, gmTimesPerAlias, colors, orderByPercentage);
}

View File

@ -24,7 +24,7 @@ import com.djrapitops.plan.utilities.formatting.Formatters;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.*;
import java.util.Map;
/**
* Factory class for different objects representing HTML stack graphs.
@ -46,15 +46,8 @@ public class StackGraphFactory {
this.dayFormatter = formatters.dayLong();
}
public StackGraph activityStackGraph(TreeMap<Long, Map<String, Set<UUID>>> activityData) {
String[] colors = theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
return new ActivityStackGraph(activityData, colors, dayFormatter);
}
public StackGraph activityStackGraph(DateMap<Map<String, Integer>> activityData) {
String[] colors = Arrays.stream(theme.getValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(","))
.map(color -> color.trim().replace("\"", ""))
.toArray(String[]::new);
String[] colors = theme.getPieColors(ThemeVal.GRAPH_ACTIVITY_PIE);
return new ActivityStackGraph(activityData, colors, dayFormatter);
}
}

View File

@ -37,6 +37,7 @@ import com.github.benmanes.caffeine.cache.Caffeine;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -176,8 +177,8 @@ public class RequestHandler implements HttpHandler {
}
String authLine = authorization.get(0);
if (authLine.contains("Basic ")) {
return new BasicAuthentication(authLine.split(" ")[1], dbSystem.getDatabase());
if (StringUtils.contains(authLine, "Basic ")) {
return new BasicAuthentication(StringUtils.split(authLine, ' ')[1], dbSystem.getDatabase());
}
return null;
}

View File

@ -16,6 +16,8 @@
*/
package com.djrapitops.plan.system.delivery.webserver;
import org.apache.commons.lang3.StringUtils;
import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;
@ -33,7 +35,8 @@ public class RequestTarget {
public RequestTarget(URI targetURI) {
resourceString = targetURI.getPath();
resource = Arrays.stream(resourceString.split("/")).filter(part -> !part.isEmpty()).collect(Collectors.toList());
resource = Arrays.stream(StringUtils.split(resourceString, '/'))
.filter(part -> !part.isEmpty()).collect(Collectors.toList());
parameters = new TreeMap<>();
parseParameters(targetURI.getQuery());
@ -44,12 +47,12 @@ public class RequestTarget {
return;
}
String[] keysAndValues = parameterString.split("&");
String[] keysAndValues = StringUtils.split(parameterString, '&');
for (String kv : keysAndValues) {
if (kv.isEmpty()) {
continue;
}
String[] keyAndValue = kv.split("=", 2);
String[] keyAndValue = StringUtils.split(kv, "=", 2);
if (keyAndValue.length >= 2) {
parameters.put(keyAndValue[0], keyAndValue[1]);
}

View File

@ -24,6 +24,7 @@ import com.djrapitops.plan.system.storage.database.Database;
import com.djrapitops.plan.system.storage.database.queries.objects.WebUserQueries;
import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plan.utilities.PassEncryptUtil;
import org.apache.commons.lang3.StringUtils;
/**
* Authentication handling for Basic Auth.
@ -47,7 +48,7 @@ public class BasicAuthentication implements Authentication {
public WebUser getWebUser() throws WebUserAuthException {
String decoded = Base64Util.decode(authenticationString);
String[] userInfo = decoded.split(":");
String[] userInfo = StringUtils.split(decoded, ':');
if (userInfo.length != 2) {
throw new WebUserAuthException(FailReason.USER_AND_PASS_NOT_SPECIFIED);
}

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.system.delivery.webserver.response;
import com.djrapitops.plan.system.storage.file.PlanFiles;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
@ -36,7 +37,7 @@ public class FileResponse extends Response {
}
public static String format(String fileName) {
String[] split = fileName.split("/");
String[] split = StringUtils.split(fileName, '/');
int i;
for (i = 0; i < split.length; i++) {
String s = split[i];
@ -47,7 +48,7 @@ public class FileResponse extends Response {
StringBuilder b = new StringBuilder("web");
for (int j = i; j < split.length; j++) {
String s = split[j];
b.append("/").append(s);
b.append('/').append(s);
}
return b.toString();
}

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import org.apache.commons.lang3.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -55,9 +56,14 @@ public abstract class Response {
}
public Optional<String> getHeader(String called) {
for (String header : header.split("\r\n")) {
if (header.startsWith(called)) {
return Optional.of(header.split(": ")[1]);
if (header != null) {
for (String header : StringUtils.split(header, "\r\n")) {
if (called == null) {
return Optional.of(header);
}
if (StringUtils.startsWith(header, called)) {
return Optional.of(StringUtils.split(header, ':')[1].trim());
}
}
}
return Optional.empty();
@ -84,7 +90,7 @@ public abstract class Response {
}
public int getCode() {
return header == null ? 500 : Integer.parseInt(header.split(" ")[1]);
return getHeader(null).map(h -> Integer.parseInt(StringUtils.split(h, ' ')[1])).orElse(500);
}
@Override

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.system.delivery.webserver.response.errors;
import com.djrapitops.plan.system.delivery.webserver.response.pages.PageResponse;
import com.djrapitops.plan.system.storage.file.PlanFiles;
import com.djrapitops.plan.system.version.VersionCheckSystem;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import java.io.IOException;
@ -50,7 +51,7 @@ public class ErrorResponse extends PageResponse {
public void replacePlaceholders() {
Map<String, String> placeholders = new HashMap<>();
placeholders.put("title", title);
String[] split = title.split(">", 3);
String[] split = StringUtils.split(title, ">", 3);
placeholders.put("titleText", split.length == 3 ? split[2] : title);
placeholders.put("paragraph", paragraph);
placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton()));

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.system.gathering.domain;
import com.djrapitops.plan.system.delivery.domain.DateHolder;
import com.djrapitops.plan.system.delivery.domain.DateMap;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.net.Inet6Address;
@ -61,7 +62,7 @@ public class GeoInfo implements DateHolder, Serializable {
if (address instanceof Inet6Address) {
StringBuilder b = new StringBuilder();
int i = 0;
for (String part : ip.split(":")) {
for (String part : StringUtils.split(ip, ':')) {
if (i >= 3) {
break;
}
@ -75,7 +76,7 @@ public class GeoInfo implements DateHolder, Serializable {
} else {
StringBuilder b = new StringBuilder();
int i = 0;
for (String part : ip.split("\\.")) {
for (String part : StringUtils.split(ip, '.')) {
if (i >= 2) {
break;
}

View File

@ -24,6 +24,7 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.*;
@ -78,7 +79,7 @@ public class ConfigNode {
}
private String[] splitPathInTwo(String path) {
String[] split = path.split("\\.", 2);
String[] split = StringUtils.split(path, "\\.", 2);
if (split.length <= 1) {
return new String[]{split[0], ""};
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.nio.charset.StandardCharsets;
@ -144,7 +145,7 @@ public class ConfigReader implements Closeable {
private ConfigNode parseNode(String line) {
// Parse a node "Key: value"
String[] keyAndValue = line.split(":", 2);
String[] keyAndValue = StringUtils.split(line, ":", 2);
if (keyAndValue.length <= 1) {
return handleMultiline(line);
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.util.ArrayList;
@ -161,7 +162,7 @@ public interface ConfigValueParser<T> {
@Override
public List<String> compose(String fromValue) {
List<String> values = new ArrayList<>();
for (String line : fromValue.split("\\n")) {
for (String line : StringUtils.split(fromValue, "\\n")) {
if (line.trim().isEmpty()) {
continue;
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -110,10 +111,10 @@ public class ConfigWriter {
if (value == null || value.isEmpty()) {
addKey(key, lines);
} else if (value.contains("\n")) {
} else if (StringUtils.contains(value, "\n")) {
// List values include newline characters,
// see ConfigValueParser.StringListParser
addListValue(key, value.split("\\n"), lines);
addListValue(key, StringUtils.split(value, "\\n"), lines);
} else {
addNormalValue(key, value, lines);
}

View File

@ -27,6 +27,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.djrapitops.plan.system.settings.theme.ThemeVal.*;
@ -62,6 +63,12 @@ public class Theme implements SubSystem {
}
}
public String[] getPieColors(ThemeVal variable) {
return Arrays.stream(StringUtils.split(getValue(variable), ','))
.map(color -> StringUtils.remove(StringUtils.trim(color), '"'))
.toArray(String[]::new);
}
@Override
public void enable() throws EnableException {
try {

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.exceptions.EnableException;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -120,7 +121,7 @@ public class PlanFiles implements SubSystem {
private Optional<File> attemptToFind(String resourceName) {
if (dataFolder.exists() && dataFolder.isDirectory()) {
String[] path = resourceName.split("/");
String[] path = StringUtils.split(resourceName, '/');
Path toFile = dataFolder.getAbsoluteFile().toPath().toAbsolutePath();
for (String next : path) {

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.system.version;
import com.djrapitops.plugin.api.utility.Version;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.net.URL;
@ -70,7 +71,7 @@ public class VersionInfoLoader {
if (!line.startsWith("REL") && !line.startsWith("DEV")) {
return Optional.empty();
}
String[] parts = line.split("\\|");
String[] parts = StringUtils.split(line, '|');
if (parts.length < 4) {
return Optional.empty();
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.utilities;
import com.djrapitops.plan.exceptions.PassEncryptException;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
@ -82,7 +83,7 @@ public class PassEncryptUtil {
private static boolean verifyPassword(char[] password, String correctHash) throws CannotPerformOperationException, InvalidHashException {
// Decode the hash into its parameters
String[] params = correctHash.split(":");
String[] params = StringUtils.split(correctHash, ':');
if (params.length != HASH_SECTIONS) {
throw new InvalidHashException(
"Fields are missing from the password hash."

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.utilities.formatting;
import com.djrapitops.plugin.utilities.Format;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.TextStringBuilder;
import java.util.Arrays;
@ -30,7 +31,7 @@ public class ItemNameFormatter implements Formatter<String> {
@Override
public String apply(String name) {
String[] parts = name.split("_");
String[] parts = StringUtils.split(name, '_');
TextStringBuilder builder = new TextStringBuilder();
builder.appendWithSeparators(Arrays.stream(parts).map(part -> new Format(part).capitalize()).iterator(), " ");
return builder.toString();