Fixed new code smells:

- Unused method in PlayersTableJSONParser
- String duplication in PlayersTableJSONParser
- MethodWrapper Serializable (Used in an Exception)
- String duplication in DeleteIPHashesPatch
- Unused constructor parameter in ProviderValueGatherer
- Locale#equals
- Unused instance variable in WebServer
This commit is contained in:
Rsl1122 2019-05-03 14:25:08 +03:00
parent c22d05ec1c
commit 83343471a6
7 changed files with 32 additions and 22 deletions

View File

@ -36,18 +36,21 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.*;
*/
public class DeleteIPHashesPatch extends Patch {
private static final String IP_HASH = "ip_hash";
private boolean hasNoHashColumn;
@Override
public boolean hasBeenApplied() {
hasNoHashColumn = !hasColumn(GeoInfoTable.TABLE_NAME, "ip_hash");
hasNoHashColumn = !hasColumn(GeoInfoTable.TABLE_NAME, IP_HASH);
String sql = SELECT + "COUNT(1) as c" + FROM + GeoInfoTable.TABLE_NAME +
WHERE + "ip_hash" + IS_NOT_NULL;
WHERE + IP_HASH + IS_NOT_NULL;
return hasNoHashColumn || !query(new HasMoreThanZeroQueryStatement(sql) {
@Override
public void prepare(PreparedStatement statement) {
/* No variables needed */
}
});
}
@ -58,7 +61,7 @@ public class DeleteIPHashesPatch extends Patch {
return;
}
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET ip_hash=?" + WHERE + "ip_hash" + IS_NOT_NULL;
String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET ip_hash=?" + WHERE + IP_HASH + IS_NOT_NULL;
execute(new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {

View File

@ -95,7 +95,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
logger.warn("DataExtension API implementation mistake for " + pluginName + ": " + warning);
}
ProviderValueGatherer gatherer = new ProviderValueGatherer(extension, extractor, dbSystem, serverInfo, logger);
ProviderValueGatherer gatherer = new ProviderValueGatherer(extension, extractor, dbSystem, serverInfo);
gatherer.storeExtensionInformation();
extensionGatherers.put(pluginName, gatherer);

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.extension.DataExtension;
import com.djrapitops.plan.extension.Group;
import com.djrapitops.plan.extension.implementation.MethodType;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
@ -30,7 +31,7 @@ import java.util.UUID;
*
* @author Rsl1122
*/
public class MethodWrapper<T> {
public class MethodWrapper<T> implements Serializable {
private final Method method;
private final Class<T> resultType;

View File

@ -30,7 +30,6 @@ import com.djrapitops.plan.extension.implementation.storage.transactions.StoreTa
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveInvalidResultsTransaction;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.logging.console.PluginLogger;
import java.util.UUID;
@ -58,8 +57,7 @@ public class ProviderValueGatherer {
DataExtension extension,
DataProviderExtractor extractor,
DBSystem dbSystem,
ServerInfo serverInfo,
PluginLogger logger
ServerInfo serverInfo
) {
this.callEvents = extension.callExtensionMethodsOn();
this.extractor = extractor;

View File

@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -125,4 +126,18 @@ public class Locale extends HashMap<Lang, Message> {
}
return replaced;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Locale)) return false;
if (!super.equals(o)) return false;
Locale locale = (Locale) o;
return langCode == locale.langCode;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), langCode);
}
}

View File

@ -59,7 +59,6 @@ public class WebServer implements SubSystem {
private final Locale locale;
private final PlanFiles files;
private final PlanConfig config;
private final ServerInfo serverInfo;
private final ServerProperties serverProperties;
private final RequestHandler requestHandler;
@ -86,7 +85,6 @@ public class WebServer implements SubSystem {
this.locale = locale;
this.files = files;
this.config = config;
this.serverInfo = serverInfo;
this.serverProperties = serverInfo.getServerProperties();
this.requestHandler = requestHandler;

View File

@ -145,13 +145,16 @@ public class PlayersTableJSONParser {
Html link = openPlayerPageInNewTab ? Html.LINK_EXTERNAL : Html.LINK;
String display = "{display:\"";
String sort = "\",sort: ";
appendData(dataJSON,
'"' + link.parse(url, name) + '"',
"{display:\"" + activityString + "\",sort: " + activityIndex + '}',
"{display:\"" + numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(playtime) + "\",sort: " + playtime + '}',
display + activityString + sort + activityIndex + '}',
display + numberFormatters.get(FormatType.TIME_MILLISECONDS).apply(playtime) + sort + playtime + '}',
loginTimes,
"{display:\"" + numberFormatters.get(FormatType.DATE_YEAR).apply(registered) + "\",sort: " + registered + '}',
"{display:\"" + numberFormatters.get(FormatType.DATE_YEAR).apply(lastSeen) + "\",sort: " + lastSeen + '}',
display + numberFormatters.get(FormatType.DATE_YEAR).apply(registered) + sort + registered + '}',
display + numberFormatters.get(FormatType.DATE_YEAR).apply(lastSeen) + sort + lastSeen + '}',
geolocation
);
}
@ -196,14 +199,6 @@ public class PlayersTableJSONParser {
}
}
private String getValue(ExtensionTabData tabData, String key) {
tabData.getPercentage(key).map(data -> data.getFormattedValue(percentageFormatter));
tabData.getNumber(key).map(data -> data.getFormattedValue(numberFormatters.get(data.getFormatType())));
tabData.getString(key).map(ExtensionStringData::getFormattedValue);
return "-";
}
private void appendData(StringBuilder dataJSON, Serializable... dataRows) {
int max = dataRows.length;
for (int i = 0; i < max; i++) {