mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 03:41:03 +01:00
Replace STRING#replace(REMOVED, "") with StringUtils.remove(STRING, REMOVED) (better performance & more readable / understandable)
This commit is contained in:
parent
3579a84a75
commit
5a063ace49
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.data.additional;
|
|||||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
import com.djrapitops.pluginbridge.plan.Bridge;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -52,7 +53,7 @@ public class HookHandler {
|
|||||||
configHandler.createSection(dataSource);
|
configHandler.createSection(dataSource);
|
||||||
}
|
}
|
||||||
if (configHandler.isEnabled(dataSource)) {
|
if (configHandler.isEnabled(dataSource)) {
|
||||||
Log.debug("Registered a new datasource: " + dataSource.getPlaceholder("").replace("%", ""));
|
Log.debug("Registered a new datasource: " + StringUtils.remove(dataSource.getPlaceholder(""), '%'));
|
||||||
additionalDataSources.add(dataSource);
|
additionalDataSources.add(dataSource);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -4,6 +4,7 @@ import main.java.com.djrapitops.plan.api.IPlan;
|
|||||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||||
import main.java.com.djrapitops.plan.database.tables.*;
|
import main.java.com.djrapitops.plan.database.tables.*;
|
||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -150,7 +151,7 @@ public abstract class Database {
|
|||||||
* @return sqlite/mysql
|
* @return sqlite/mysql
|
||||||
*/
|
*/
|
||||||
public String getConfigName() {
|
public String getConfigName() {
|
||||||
return getName().toLowerCase().replace(" ", "");
|
return StringUtils.remove(getName().toLowerCase(), ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isNewDatabase() throws SQLException;
|
public abstract boolean isNewDatabase() throws SQLException;
|
||||||
|
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.utilities;
|
|||||||
import com.djrapitops.plugin.utilities.Format;
|
import com.djrapitops.plugin.utilities.Format;
|
||||||
import com.djrapitops.plugin.utilities.FormattingUtils;
|
import com.djrapitops.plugin.utilities.FormattingUtils;
|
||||||
import main.java.com.djrapitops.plan.Settings;
|
import main.java.com.djrapitops.plan.Settings;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -136,7 +137,7 @@ public class FormatUtils {
|
|||||||
}
|
}
|
||||||
builder.append(s);
|
builder.append(s);
|
||||||
}
|
}
|
||||||
String formattedTime = builder.toString().replace("%zero%", "");
|
String formattedTime = StringUtils.remove(builder.toString(), "%zero%");
|
||||||
if (formattedTime.isEmpty()) {
|
if (formattedTime.isEmpty()) {
|
||||||
return Settings.FORMAT_SECONDS.toString().replace("%seconds%", "0");
|
return Settings.FORMAT_SECONDS.toString().replace("%seconds%", "0");
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import main.java.com.djrapitops.plan.utilities.comparators.UserInfoLastPlayedCom
|
|||||||
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
|
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
|
import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -191,7 +192,7 @@ public class Analysis {
|
|||||||
Log.debug("Analysis", "Additional Sources: " + sources.size());
|
Log.debug("Analysis", "Additional Sources: " + sources.size());
|
||||||
sources.parallelStream().filter(Verify::notNull).forEach(source -> {
|
sources.parallelStream().filter(Verify::notNull).forEach(source -> {
|
||||||
try {
|
try {
|
||||||
Benchmark.start("Source " + source.getPlaceholder("").replace("%", ""));
|
Benchmark.start("Source " + StringUtils.remove(source.getPlaceholder(""), '%'));
|
||||||
final List<AnalysisType> analysisTypes = source.getAnalysisTypes();
|
final List<AnalysisType> analysisTypes = source.getAnalysisTypes();
|
||||||
if (analysisTypes.isEmpty()) {
|
if (analysisTypes.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -217,11 +218,11 @@ public class Analysis {
|
|||||||
replaceMap.put(source.getPlaceholder(boolTot.getPlaceholderModifier()), AnalysisUtils.getBooleanTotal(boolTot, source, uuids));
|
replaceMap.put(source.getPlaceholder(boolTot.getPlaceholderModifier()), AnalysisUtils.getBooleanTotal(boolTot, source, uuids));
|
||||||
}
|
}
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||||
Log.error("A PluginData-source caused an exception: " + source.getPlaceholder("").replace("%", ""));
|
Log.error("A PluginData-source caused an exception: " + StringUtils.remove(source.getPlaceholder(""), '%'));
|
||||||
|
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
} finally {
|
} finally {
|
||||||
Benchmark.stop("Analysis", "Source " + source.getPlaceholder("").replace("%", ""));
|
Benchmark.stop("Analysis", "Source " + StringUtils.remove(source.getPlaceholder(""), '%'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Benchmark.stop("Analysis", "3rd party");
|
Benchmark.stop("Analysis", "3rd party");
|
||||||
|
@ -7,6 +7,7 @@ import main.java.com.djrapitops.plan.data.additional.PluginData;
|
|||||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator;
|
import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -194,8 +195,10 @@ public class AnalysisUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String logPluginDataCausedError(PluginData source, Throwable e) {
|
private static String logPluginDataCausedError(PluginData source, Throwable e) {
|
||||||
Log.error("A PluginData-source caused an exception: " + source.getPlaceholder("").replace("%", ""));
|
String placeholder = StringUtils.remove(source.getPlaceholder(""), '%');
|
||||||
Log.toLog("PluginData-source caused an exception: " + source.getPlaceholder("").replace("%", ""), e);
|
|
||||||
|
Log.error("A PluginData-source caused an exception: " + placeholder);
|
||||||
|
Log.toLog("PluginData-source caused an exception: " + placeholder, e);
|
||||||
return source.parseContainer("", "Exception during calculation.");
|
return source.parseContainer("", "Exception during calculation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.utilities.html;
|
|||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
import main.java.com.djrapitops.plan.Settings;
|
import main.java.com.djrapitops.plan.Settings;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -93,7 +94,7 @@ public class HtmlUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String removeXSS(String string) {
|
public static String removeXSS(String string) {
|
||||||
return string.replaceAll("(<!--)|(-->)|(</?script>)", "");
|
return StringUtils.removeAll(string,"(<!--)|(-->)|(</?script>)");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +115,7 @@ public class HtmlUtils {
|
|||||||
string = Html.SPAN.parse(string);
|
string = Html.SPAN.parse(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.replace("§r", "");
|
return StringUtils.remove(string, "§r");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String separateWithQuotes(String... strings) {
|
public static String separateWithQuotes(String... strings) {
|
||||||
|
@ -9,6 +9,7 @@ import main.java.com.djrapitops.plan.data.TPS;
|
|||||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||||
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
import main.java.com.djrapitops.plan.utilities.analysis.Point;
|
||||||
import main.java.com.djrapitops.plan.utilities.html.graphs.*;
|
import main.java.com.djrapitops.plan.utilities.html.graphs.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import test.java.utils.RandomData;
|
import test.java.utils.RandomData;
|
||||||
@ -57,7 +58,7 @@ public class GraphTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSeriesCreator() {
|
public void testSeriesCreator() {
|
||||||
String result = SeriesCreator.seriesGraph(points, false, false).replaceAll("[\\[\\]]", "");
|
String result = StringUtils.removeAll(SeriesCreator.seriesGraph(points, false, false), "[\\[\\]]");
|
||||||
String[] splittedResult = result.split(",");
|
String[] splittedResult = result.split(",");
|
||||||
|
|
||||||
Map<String, String> expected = new LinkedHashMap<>();
|
Map<String, String> expected = new LinkedHashMap<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user