More smells:

- Fixed accidental breakage of a WorldTimes query

Fixed Smells, Level Major (SonarCloud):
- Use of keySet instead of entrySet in LargeStoreQueries
- Unused variable in NicknameQueries now used
- Unused fields removed from UsersTable
- Unused fields removed from PlayerProcessors
- Same variable name as field in WorldMap
This commit is contained in:
Rsl1122 2019-02-14 22:41:29 +02:00
parent 4eb8c6476a
commit 32f3cae7c4
6 changed files with 24 additions and 30 deletions

View File

@ -60,9 +60,10 @@ public class LargeStoreQueries {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every Server
for (UUID serverUUID : ofServers.keySet()) {
for (Map.Entry<UUID, Map<String, Integer>> serverEntry : ofServers.entrySet()) {
UUID serverUUID = serverEntry.getKey();
// Every Command
for (Map.Entry<String, Integer> entry : ofServers.get(serverUUID).entrySet()) {
for (Map.Entry<String, Integer> entry : serverEntry.getValue().entrySet()) {
String command = entry.getKey();
int timesUsed = entry.getValue();
@ -91,15 +92,16 @@ public class LargeStoreQueries {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every User
for (UUID uuid : ofUsers.keySet()) {
for (Map.Entry<UUID, List<GeoInfo>> playerEntry : ofUsers.entrySet()) {
UUID playerUUID = playerEntry.getKey();
// Every GeoInfo
for (GeoInfo info : ofUsers.get(uuid)) {
for (GeoInfo info : playerEntry.getValue()) {
String ip = info.getIp();
String ipHash = info.getIpHash();
String geoLocation = info.getGeolocation();
long lastUsed = info.getDate();
statement.setString(1, uuid.toString());
statement.setString(1, playerUUID.toString());
statement.setString(2, ip);
statement.setString(3, ipHash);
statement.setString(4, geoLocation);
@ -127,9 +129,10 @@ public class LargeStoreQueries {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// Every Server
for (UUID serverUUID : ofServersAndUsers.keySet()) {
for (Map.Entry<UUID, Map<UUID, List<Nickname>>> serverEntry : ofServersAndUsers.entrySet()) {
UUID serverUUID = serverEntry.getKey();
// Every User
for (Map.Entry<UUID, List<Nickname>> entry : ofServersAndUsers.get(serverUUID).entrySet()) {
for (Map.Entry<UUID, List<Nickname>> entry : serverEntry.getValue().entrySet()) {
UUID uuid = entry.getKey();
// Every Nickname
List<Nickname> nicknames = entry.getValue();

View File

@ -181,9 +181,15 @@ public class NicknameQueries {
NicknamesTable.LAST_USED + ", " +
NicknamesTable.USER_UUID + ", " +
NicknamesTable.SERVER_UUID +
FROM + NicknamesTable.TABLE_NAME;
FROM + NicknamesTable.TABLE_NAME +
WHERE + NicknamesTable.SERVER_UUID + "=?";
return new QueryStatement<Map<UUID, List<Nickname>>>(sql, 5000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
return new QueryAllStatement<Map<UUID, List<Nickname>>>(sql, 5000) {
@Override
public Map<UUID, List<Nickname>> processResults(ResultSet set) throws SQLException {
Map<UUID, List<Nickname>> serverMap = new HashMap<>();

View File

@ -40,11 +40,12 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.*;
public class WorldTimesQueries {
private static String worldColumn = "world";
private static final String SELECT_WORLD_TIMES_STATEMENT_START = "SELECT " +
private static final String SELECT_WORLD_TIMES_STATEMENT_START = SELECT +
"SUM(" + WorldTimesTable.SURVIVAL + ") as survival, " +
"SUM(" + WorldTimesTable.CREATIVE + ") as creative, " +
"SUM(" + WorldTimesTable.ADVENTURE + ") as adventure, " +
"SUM(" + WorldTimesTable.SPECTATOR + ") as spectator, " +
WorldTimesTable.SERVER_UUID + ", " +
WorldTable.TABLE_NAME + "." + WorldTable.NAME + " as " + worldColumn +
FROM + WorldTimesTable.TABLE_NAME +
" INNER JOIN " + WorldTable.TABLE_NAME + " on " + WorldTable.TABLE_NAME + "." + WorldTable.ID + "=" + WorldTimesTable.WORLD_ID;

View File

@ -53,16 +53,8 @@ public class UsersTable extends Table {
public UsersTable(SQLDB db) {
super(TABLE_NAME, db);
statementSelectID = "(" + Select.from(tableName, tableName + "." + ID).where(USER_UUID + "=?").toString() + " LIMIT 1)";
insertStatement = Insert.values(tableName,
USER_UUID,
REGISTERED,
USER_NAME);
}
public final String statementSelectID;
private String insertStatement;
public static String createTableSQL(DBType dbType) {
return CreateTableParser.create(TABLE_NAME, dbType)
.column(ID, Sql.INT).primaryKey()

View File

@ -16,10 +16,8 @@
*/
package com.djrapitops.plan.system.processing.processors.player;
import com.djrapitops.plan.system.cache.NicknameCache;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import dagger.Lazy;
import javax.inject.Inject;
@ -35,22 +33,16 @@ import java.util.function.BooleanSupplier;
@Singleton
public class PlayerProcessors {
private final Lazy<ServerInfo> serverInfo;
private final Lazy<DBSystem> dbSystem;
private final Lazy<SessionCache> sessionCache;
private final Lazy<NicknameCache> nicknameCache;
@Inject
public PlayerProcessors(
Lazy<ServerInfo> serverInfo,
Lazy<DBSystem> dbSystem,
Lazy<SessionCache> sessionCache,
Lazy<NicknameCache> nicknameCache
Lazy<SessionCache> sessionCache
) {
this.serverInfo = serverInfo;
this.dbSystem = dbSystem;
this.sessionCache = sessionCache;
this.nicknameCache = nicknameCache;
}
public BanAndOpProcessor banAndOpProcessor(UUID uuid, BooleanSupplier banned, boolean op) {

View File

@ -64,15 +64,15 @@ public class WorldMap implements HighChart {
}
private Map<String, Integer> toGeoCodeCounts(List<String> geoLocations) {
Map<String, Integer> geoCodeCounts = new HashMap<>();
Map<String, Integer> codeCounts = new HashMap<>();
Map<String, String> geoCodes = getGeoCodes();
for (String geoLocation : geoLocations) {
String countryCode = geoCodes.get(geoLocation.toLowerCase());
geoCodeCounts.put(countryCode, geoCodeCounts.getOrDefault(countryCode, 0) + 1);
codeCounts.put(countryCode, codeCounts.getOrDefault(countryCode, 0) + 1);
}
return geoCodeCounts;
return codeCounts;
}
@Override