Fix unwanted Filtering of sessions from inspect page punchcards

Fix some code inspect issues
This commit is contained in:
Rsl1122 2017-07-30 21:44:55 +03:00
parent eb12fe2dfc
commit 8fe7de9bb6
20 changed files with 30 additions and 101 deletions

View File

@ -85,11 +85,11 @@ public class API {
* This method is useful if you have a table and want to link to the inspect
* page.
* <p>
* Html.LINK.parse("Link", "Playername") can be used to get a link
* {@code <a href="Link">Playername</a>}
* Html.LINK.parse("Link", "PlayerName") can be used to get a link
* {@code <a href="Link">PlayerName</a>}
*
* @param name Playername of the player
* @return ip:port/security/player/Playername
* @param name Name of the player
* @return ip:port/security/player/PlayerName
*/
public String getPlayerInspectPageLink(String name) {
return HtmlUtils.getInspectUrlWithProtocol(name);
@ -229,10 +229,10 @@ public class API {
}
/**
* Used to get the playerName of a player who has played on the server.
* Used to get the PlayerName of a player who has played on the server.
*
* @param uuid UUID of the player.
* @return Playername, eg "Rsl1122"
* @return PlayerName, eg "Rsl1122"
* @throws IllegalArgumentException If uuid is null.
* @throws IllegalStateException If the player has not played on the server
* before.
@ -253,7 +253,7 @@ public class API {
* @return UUID of the Player
* @throws Exception if player's name is not registered at Mojang
*/
public UUID playerNameToUUID(String playerName) throws Exception {
public UUID PlayerNameToUUID(String playerName) throws Exception {
return UUIDFetcher.getUUIDOf(playerName);
}

View File

@ -22,8 +22,6 @@ import main.java.com.djrapitops.plan.utilities.HtmlUtils;
*/
public class ListCommand extends SubCommand {
private final Plan plugin;
/**
* Class Constructor.
*
@ -32,7 +30,6 @@ public class ListCommand extends SubCommand {
public ListCommand(Plan plugin) {
super("list, pl", CommandType.CONSOLE, Permissions.INSPECT_OTHER.getPermission(), "List to all cached players", "");
this.plugin = plugin;
setHelp(plugin);
}

View File

@ -18,7 +18,7 @@ import java.util.Set;
*/
public class RegisterCommandFilter extends AbstractFilter {
private Set<String> censoredCommands = ImmutableSet.of("/plan web register", "/plan webuser register", "/plan register");
private final Set<String> censoredCommands = ImmutableSet.of("/plan web register", "/plan webuser register", "/plan register");
@Override
public Result filter(LogEvent event) {

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.data;
/**
* This class is used for storing start and end of a playsession inside UserData
* This class is used for storing start and end of a play session inside UserData
* object.
*
* @author Rsl1122

View File

@ -123,7 +123,7 @@ public abstract class SQLDB extends Database {
try {
getVersion();
newDatabase = false;
} catch (Exception e) {
} catch (Exception ignored) {
}
if (!versionTable.createTable()) {

View File

@ -38,7 +38,7 @@ public class LocationsTable extends Table {
public boolean removeAllData() {
try {
execute("DELETE FROM " + tableName);
} catch (Exception e) {
} catch (Exception ignored) {
}
return true;
}

View File

@ -79,7 +79,7 @@ public class TPSTable extends Table {
} else {
execute("ALTER TABLE " + tableName + " ADD COLUMN " + columnCPUUsage + " double NOT NULL DEFAULT 0");
}
} catch (SQLException e) {
} catch (SQLException ignored) {
}
}

View File

@ -96,7 +96,7 @@ public abstract class Table {
for (String statement : statements) {
try {
execute(statement);
} catch (SQLException e) {
} catch (SQLException ignored) {
}
}
}

View File

@ -123,7 +123,7 @@ public class UsersTable extends Table {
execute("ALTER TABLE " + tableName
+ " DROP COLUMN " + columnDemAge + ","
+ " DROP COLUMN " + columnDemGender);
} catch (Exception e) {
} catch (Exception ignored) {
}
}
}

View File

@ -6,7 +6,6 @@
package main.java.com.djrapitops.plan.ui.html.graphs;
import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import java.util.Collection;
@ -15,7 +14,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
/**
* Utility class for creating Punch Card Data Array for the javascripts.
* Utility class for creating Punch Card Data Array for the JavaScripts.
*
* @author Rsl1122
* @since 3.6.0
@ -30,9 +29,9 @@ public class PunchCardGraphCreator {
}
/**
* Creates a Punchcard series data Array for HighCharts
* Creates a PunchCard series data Array for HighCharts
*
* @param sessions Sessions (Unique/Player) to be placed into the punchcard.
* @param sessions Sessions (Unique/Player) to be placed into the PunchCard.
* @return Data array as a string.
*/
public static String createDataSeries(Collection<SessionData> sessions) {
@ -73,12 +72,10 @@ public class PunchCardGraphCreator {
}
private static List<Long> getSessionStarts(Collection<SessionData> data) {
long now = MiscUtils.getTime();
return data.stream()
.filter(Objects::nonNull)
.filter(SessionData::isValid)
.map(SessionData::getSessionStart)
.filter(start -> now - start < (long) 2592000 * (long) 1000)
.sorted()
.collect(Collectors.toList());
}

View File

@ -26,7 +26,7 @@ public class SessionLengthDistributionGraphCreator {
* Contains values from 0 up to 120 minutes
*
* @param lengths Lengths of all sessions in a list.
* @return Data for Highcharts series.
* @return Data for HighCharts series.
*/
public static String createDataSeries(List<Long> lengths) {
Map<Long, Integer> bars = getValues(lengths);

View File

@ -60,7 +60,7 @@ public class PlayersTableCreator {
String.valueOf(uData.getLastPlayed()), FormatUtils.formatTimeStamp(uData.getLastPlayed()),
String.valueOf(uData.getGeolocation())
));
} catch (NullPointerException e) {
} catch (NullPointerException ignored) {
}
i++;

View File

@ -12,7 +12,7 @@ import java.text.DecimalFormat;
*/
public class FormatUtils {
private static DecimalFormat df = new DecimalFormat(Settings.FORMAT_DECIMALS.toString());
private static final DecimalFormat df = new DecimalFormat(Settings.FORMAT_DECIMALS.toString());
/**
* Constructor used to hide the public constructor

View File

@ -3,15 +3,12 @@ package main.java.com.djrapitops.plan.utilities;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.SessionData;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Rsl1122
@ -84,61 +81,6 @@ public class ManageUtils {
return true;
}
/**
* @param sessions
* @return
*/
public static boolean containsCombinable(List<SessionData> sessions) {
return containsCombinable(sessions, 5000);
}
private static boolean containsCombinable(List<SessionData> sessions, int threshold) {
// Checks if there are starts & ends that are the same, or less than threshold ms away from each other.
return sessions.stream()
.anyMatch(s -> sessions.stream()
.filter(ses -> !ses.equals(s))
.map(SessionData::getSessionStart)
.anyMatch(start -> Math.abs(s.getSessionEnd() - start) < threshold));
}
/**
* @param sessions
* @param loginTimes
* @return
*/
public static List<SessionData> combineSessions(List<SessionData> sessions, Integer loginTimes) {
return combineSessions(sessions, loginTimes, 5000);
}
private static List<SessionData> combineSessions(List<SessionData> sessions, Integer loginTimes, int threshold) {
if (threshold >= 35000) {
return sessions;
}
List<SessionData> newSessions = new ArrayList<>();
List<SessionData> removed = new ArrayList<>();
for (SessionData session : sessions) {
if (removed.contains(session)) {
continue;
}
List<SessionData> close = sessions.stream().filter(ses -> Math.abs(session.getSessionEnd() - ses.getSessionStart()) < threshold).collect(Collectors.toList());
if (!close.isEmpty()) {
long big = MathUtils.getBiggestLong(close.stream().map(SessionData::getSessionEnd).collect(Collectors.toList()));
session.endSession(big);
removed.addAll(close);
}
newSessions.add(session);
}
if (loginTimes == newSessions.size()) {
return newSessions;
}
boolean containsCombinable = containsCombinable(newSessions, threshold);
if (containsCombinable) {
return combineSessions(newSessions, threshold + 1000);
} else {
return newSessions;
}
}
public static Database getDB(Plan plugin, String dbName) {
Database database = null;
for (Database sqldb : plugin.getDatabases()) {

View File

@ -99,7 +99,7 @@ public class MiscUtils {
if (c != null) {
try {
c.close();
} catch (IOException ex) {
} catch (IOException ignored) {
}
}
}
@ -110,7 +110,7 @@ public class MiscUtils {
if (c != null) {
try {
c.close();
} catch (Exception ex) {
} catch (Exception ignored) {
}
}
}

View File

@ -75,7 +75,6 @@ public class PassEncryptUtil {
// Currently, Java only supports SHA1.
if (!params[HASH_ALGORITHM_INDEX].equals("sha1")) {
throw new CannotPerformOperationException(
"Unsupported hash type."
);
}
@ -182,8 +181,8 @@ public class PassEncryptUtil {
@SuppressWarnings("serial")
public static class CannotPerformOperationException extends Exception {
CannotPerformOperationException(String message) {
super(message);
CannotPerformOperationException() {
super("Unsupported hash type.");
}
CannotPerformOperationException(String message, Throwable source) {

View File

@ -53,7 +53,7 @@ public class UUIDUtility {
if (uuid == null) {
uuid = UUIDFetcher.getUUIDOf(playername);
}
} catch (Exception e) {
} catch (Exception ignored) {
}
return uuid;
}

View File

@ -40,7 +40,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
@PrepareForTest(JavaPlugin.class)
public class DataCacheHandlerTest {
private Plan plan;
private Database db;
private DataCacheHandler handler;
private boolean calledSaveCommandUse;
@ -59,7 +58,7 @@ public class DataCacheHandlerTest {
@Before
public void setUp() throws Exception {
TestInit t = TestInit.init();
plan = t.getPlanMock();
Plan plan = t.getPlanMock();
calledSaveCommandUse = false;
calledSaveUserData = false;
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {

View File

@ -24,9 +24,6 @@ import test.java.utils.TestInit;
@PrepareForTest({JavaPlugin.class})
public class DataCacheClearQueueTest {
private Plan plan;
private DataCacheHandler handler;
/**
*
*/
@ -39,8 +36,8 @@ public class DataCacheClearQueueTest {
@Before
public void setUp() throws Exception {
TestInit t = TestInit.init();
plan = t.getPlanMock();
handler = new DataCacheHandler(plan) {
Plan plan = t.getPlanMock();
DataCacheHandler handler = new DataCacheHandler(plan) {
@Override
public boolean getCommandUseFromDb() {
return true;

View File

@ -31,8 +31,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
@PrepareForTest({JavaPlugin.class})
public class DataCacheSaveQueueTest {
private Plan plan;
private Database db;
private boolean calledSaveUserData;
private boolean calledSaveUserData2;
@ -48,10 +46,10 @@ public class DataCacheSaveQueueTest {
@Before
public void setUp() throws Exception {
TestInit t = TestInit.init();
plan = t.getPlanMock();
Plan plan = t.getPlanMock();
calledSaveUserData = false;
calledSaveUserData2 = false;
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
Database db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) {
@Override
public void startConnectionPingTask() {