mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 11:08:08 +01:00
QInspectCommand now uses PlayerContainer
This commit is contained in:
parent
7415c3ebe2
commit
88e79e3f4d
@ -2,8 +2,12 @@ package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.calculation.ActivityIndex;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.GeoInfoMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
@ -16,10 +20,12 @@ import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.settings.DefaultMessages;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -64,15 +70,13 @@ public class QInspectCommand extends CommandNode {
|
||||
return;
|
||||
}
|
||||
|
||||
Database database = Database.getActive();
|
||||
if (!database.check().isPlayerRegistered(uuid)) {
|
||||
PlayerContainer container = Database.getActive().fetch().getPlayerContainer(uuid);
|
||||
if (!container.getValue(PlayerKeys.REGISTERED).isPresent()) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_FAIL_USERNAME_NOT_KNOWN).toString());
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerProfile playerProfile = database.fetch().getPlayerProfile(uuid);
|
||||
|
||||
sendMessages(sender, playerProfile);
|
||||
sendMessages(sender, container);
|
||||
} catch (DBOpException e) {
|
||||
if (e.isFatal()) {
|
||||
sender.sendMessage("§cFatal database exception occurred: " + e.getMessage());
|
||||
@ -87,7 +91,7 @@ public class QInspectCommand extends CommandNode {
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
private void sendMessages(ISender sender, PlayerProfile profile) {
|
||||
private void sendMessages(ISender sender, PlayerContainer container) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
ColorScheme colorScheme = plugin.getColorScheme();
|
||||
@ -96,23 +100,27 @@ public class QInspectCommand extends CommandNode {
|
||||
String colS = colorScheme.getSecondaryColor();
|
||||
String colT = colorScheme.getTertiaryColor();
|
||||
|
||||
String ball = DefaultMessages.BALL.parse();
|
||||
sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT).toString() + ": " + colT + container.getValue(PlayerKeys.NAME).orElse("Unknown"));
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT).toString() + ": " + colT + profile.getName());
|
||||
ActivityIndex activityIndex = new ActivityIndex(container, now);
|
||||
Long registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
Long lastSeen = container.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
|
||||
List<GeoInfo> geoInfo = container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
|
||||
Optional<GeoInfo> mostRecentGeoInfo = new GeoInfoMutator(geoInfo).mostRecent();
|
||||
String loginLocation = mostRecentGeoInfo.isPresent() ? mostRecentGeoInfo.get().getGeolocation() : "-";
|
||||
SessionsMutator sessionsMutator = new SessionsMutator(container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()));
|
||||
|
||||
ActivityIndex activityIndex = profile.getActivityIndex(now);
|
||||
|
||||
sender.sendMessage(colT + ball + " " + colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getGroup());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Registered: " + colS + FormatUtils.formatTimeStampYear(profile.getRegistered()));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Last Seen: " + colS + FormatUtils.formatTimeStampYear(profile.getLastSeen()));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Logged in from: " + colS + profile.getMostRecentGeoInfo().getGeolocation());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Playtime: " + colS + FormatUtils.formatTimeAmount(profile.getTotalPlaytime()));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Longest Session: " + colS + FormatUtils.formatTimeAmount(profile.getLongestSession(0, now)));
|
||||
sender.sendMessage(colT + ball + " " + colM + " Times Kicked: " + colS + profile.getTimesKicked());
|
||||
sender.sendMessage(colM + " Activity Index: " + colS + activityIndex.getFormattedValue() + " | " + activityIndex.getGroup());
|
||||
sender.sendMessage(colM + " Registered: " + colS + (registered != 0 ? FormatUtils.formatTimeStampYear(registered) : "-"));
|
||||
sender.sendMessage(colM + " Last Seen: " + colS + (lastSeen != 0 ? FormatUtils.formatTimeStampYear(lastSeen) : "-"));
|
||||
sender.sendMessage(colM + " Logged in from: " + colS + loginLocation);
|
||||
sender.sendMessage(colM + " Playtime: " + colS + FormatUtils.formatTimeAmount(sessionsMutator.toPlaytime()));
|
||||
sender.sendMessage(colM + " Longest Session: " + colS + FormatUtils.formatTimeAmount(sessionsMutator.toLongestSessionLength()));
|
||||
sender.sendMessage(colM + " Times Kicked: " + colS + container.getValue(PlayerKeys.KICK_COUNT).orElse(0));
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(colT + ball + " " + colM + " Player Kills : " + colS + profile.getPlayerKills().count());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Mob Kills : " + colS + profile.getMobKillCount());
|
||||
sender.sendMessage(colT + ball + " " + colM + " Deaths : " + colS + profile.getDeathCount());
|
||||
sender.sendMessage(colM + " Player Kills : " + colS + sessionsMutator.toPlayerKillCount());
|
||||
sender.sendMessage(colM + " Mob Kills : " + colS + sessionsMutator.toMobKillCount());
|
||||
sender.sendMessage(colM + " Deaths : " + colS + sessionsMutator.toDeathCount());
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Container for data about a player on a single server.
|
||||
* Container for data about a player linked to a single server.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.keys.PerServerKeys For Key objects.
|
||||
*/
|
||||
public class PerServerData extends HashMap<UUID, DataContainer> {
|
||||
public class PerServerContainer extends HashMap<UUID, DataContainer> {
|
||||
}
|
@ -17,6 +17,7 @@ import java.util.UUID;
|
||||
public class CommonKeys {
|
||||
|
||||
public static final Key<UUID> UUID = new Key<>(UUID.class, "uuid");
|
||||
public static final Key<String> NAME = new Key<>(String.class, "name");
|
||||
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
||||
|
||||
public static final Key<List<Session>> SESSIONS = new Key<>(new Type<List<Session>>() {}, "sessions");
|
||||
|
@ -3,15 +3,16 @@ package com.djrapitops.plan.data.store.keys;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Key objects for PerServerData container.
|
||||
* Key objects for PerServerContainer container.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.containers.PerServerData For the DataContainer.
|
||||
* @see PerServerContainer For the DataContainer.
|
||||
*/
|
||||
public class PerServerKeys {
|
||||
|
||||
|
@ -5,7 +5,7 @@ import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.Type;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
@ -21,7 +21,7 @@ import java.util.UUID;
|
||||
public class PlayerKeys {
|
||||
|
||||
public static final Key<UUID> UUID = CommonKeys.UUID;
|
||||
public static final Key<String> NAME = new Key<>(String.class, "name");
|
||||
public static final Key<String> NAME = CommonKeys.NAME;
|
||||
public static final Key<List<Nickname>> NICKNAMES = new Key<>(new Type<List<Nickname>>() {}, "nicknames");
|
||||
|
||||
public static final Key<Long> REGISTERED = CommonKeys.REGISTERED;
|
||||
@ -37,7 +37,7 @@ public class PlayerKeys {
|
||||
public static final Key<Integer> PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT;
|
||||
public static final Key<Integer> MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT;
|
||||
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||
public static final Key<PerServerData> PER_SERVER = new Key<>(PerServerData.class, "per_server_data");
|
||||
public static final Key<PerServerContainer> PER_SERVER = new Key<>(PerServerContainer.class, "per_server_data");
|
||||
public static final Key<Long> LAST_SEEN = CommonKeys.LAST_SEEN;
|
||||
|
||||
public static final Key<Boolean> BANNED = CommonKeys.BANNED;
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.djrapitops.plan.data.store.mutators;
|
||||
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.utilities.comparators.GeoInfoComparator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Mutator for lists of GeoInfo objects.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see GeoInfo for the object.
|
||||
*/
|
||||
public class GeoInfoMutator {
|
||||
|
||||
private final List<GeoInfo> geoInfo;
|
||||
|
||||
public GeoInfoMutator(List<GeoInfo> geoInfo) {
|
||||
this.geoInfo = geoInfo;
|
||||
}
|
||||
|
||||
public GeoInfoMutator forCollection(Collection<GeoInfo> collection) {
|
||||
return new GeoInfoMutator(new ArrayList<>(collection));
|
||||
}
|
||||
|
||||
public Optional<GeoInfo> mostRecent() {
|
||||
if (geoInfo.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
geoInfo.sort(new GeoInfoComparator());
|
||||
return Optional.of(geoInfo.get(0));
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package com.djrapitops.plan.data.store.mutators;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
@ -10,15 +10,15 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Mutator for PerServerData object.
|
||||
* Mutator for PerServerContainer object.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PerServerDataMutator {
|
||||
|
||||
private final PerServerData data;
|
||||
private final PerServerContainer data;
|
||||
|
||||
public PerServerDataMutator(PerServerData data) {
|
||||
public PerServerDataMutator(PerServerContainer data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -123,4 +123,8 @@ public class SessionsMutator {
|
||||
public int count() {
|
||||
return sessions.size();
|
||||
}
|
||||
|
||||
public int toPlayerKillCount() {
|
||||
return toPlayerKillList().size();
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.djrapitops.plan.data.store.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Map object that has ServerUUID as keys.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PerServer<T> extends HashMap<UUID, T> {
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ import com.djrapitops.plan.data.ServerProfile;
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.data.container.*;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
@ -171,19 +171,19 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
return container;
|
||||
}
|
||||
|
||||
private PerServerData getPerServerData(UUID uuid) {
|
||||
PerServerData perServerData = new PerServerData();
|
||||
private PerServerContainer getPerServerData(UUID uuid) {
|
||||
PerServerContainer perServerContainer = new PerServerContainer();
|
||||
|
||||
Map<UUID, UserInfo> allUserInfo = userInfoTable.getAllUserInfo(uuid);
|
||||
for (Map.Entry<UUID, UserInfo> entry : allUserInfo.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
UserInfo info = entry.getValue();
|
||||
|
||||
DataContainer perServer = perServerData.getOrDefault(serverUUID, new DataContainer());
|
||||
DataContainer perServer = perServerContainer.getOrDefault(serverUUID, new DataContainer());
|
||||
perServer.putRawData(PlayerKeys.REGISTERED, info.getRegistered());
|
||||
perServer.putRawData(PlayerKeys.BANNED, info.isBanned());
|
||||
perServer.putRawData(PlayerKeys.OPERATOR, info.isOpped());
|
||||
perServerData.put(serverUUID, perServer);
|
||||
perServerContainer.put(serverUUID, perServer);
|
||||
}
|
||||
|
||||
Map<UUID, List<Session>> sessions = sessionsTable.getSessions(uuid);
|
||||
@ -191,7 +191,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
UUID serverUUID = entry.getKey();
|
||||
List<Session> serverSessions = entry.getValue();
|
||||
|
||||
DataContainer perServer = perServerData.getOrDefault(serverUUID, new DataContainer());
|
||||
DataContainer perServer = perServerContainer.getOrDefault(serverUUID, new DataContainer());
|
||||
perServer.putRawData(PerServerKeys.SESSIONS, serverSessions);
|
||||
|
||||
perServer.putSupplier(PerServerKeys.LAST_SEEN, () ->
|
||||
@ -208,10 +208,10 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
perServer.putSupplier(PerServerKeys.DEATH_COUNT, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toDeathCount());
|
||||
|
||||
perServerData.put(serverUUID, perServer);
|
||||
perServerContainer.put(serverUUID, perServer);
|
||||
}
|
||||
|
||||
return perServerData;
|
||||
return perServerContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@ import com.djrapitops.plan.data.Actions;
|
||||
import com.djrapitops.plan.data.calculation.ActivityIndex;
|
||||
import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.PerServerDataMutator;
|
||||
@ -107,8 +107,8 @@ public class InspectPage extends Page {
|
||||
|
||||
addValue("toLastSeen", lastSeen != 0 ? FormatUtils.formatTimeStampYear(lastSeen) : "-");
|
||||
|
||||
PerServerData perServerData = container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerData());
|
||||
PerServerDataMutator perServerDataMutator = new PerServerDataMutator(perServerData);
|
||||
PerServerContainer perServerContainer = container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer());
|
||||
PerServerDataMutator perServerDataMutator = new PerServerDataMutator(perServerContainer);
|
||||
|
||||
Map<UUID, WorldTimes> worldTimesPerServer = perServerDataMutator.worldTimesPerServer();
|
||||
addValue("serverPieSeries", new ServerPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries());
|
||||
|
@ -5,7 +5,7 @@ import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for comparing Actions so that latest is the first component.
|
||||
* Comparator for comparing GeoInfo so that most recent is the first component.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -7,7 +7,7 @@ package com.djrapitops.plan.utilities.html.structure;
|
||||
import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
@ -31,7 +31,7 @@ public class ServerAccordion extends AbstractAccordion {
|
||||
private final StringBuilder viewScript;
|
||||
|
||||
private final Map<UUID, String> serverNames;
|
||||
private PerServerData perServer;
|
||||
private PerServerContainer perServer;
|
||||
|
||||
public ServerAccordion(PlayerContainer container, Map<UUID, String> serverNames) {
|
||||
super("server_accordion");
|
||||
@ -39,7 +39,7 @@ public class ServerAccordion extends AbstractAccordion {
|
||||
viewScript = new StringBuilder();
|
||||
|
||||
this.serverNames = serverNames;
|
||||
Optional<PerServerData> perServerData = container.getValue(PlayerKeys.PER_SERVER);
|
||||
Optional<PerServerContainer> perServerData = container.getValue(PlayerKeys.PER_SERVER);
|
||||
if (perServerData.isPresent()) {
|
||||
perServer = perServerData.get();
|
||||
} else {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.utilities.comparators;
|
||||
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.container.UserInfo;
|
||||
@ -8,131 +9,147 @@ import com.djrapitops.plan.system.settings.locale.Message;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
||||
import com.google.common.collect.Ordering;
|
||||
import org.junit.Test;
|
||||
import utilities.RandomData;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ComparatorTest {
|
||||
|
||||
@Test
|
||||
public void testPointComparator() {
|
||||
public void pointComparator() {
|
||||
List<Point> points = RandomData.randomPoints();
|
||||
|
||||
List<Long> longValues = points.stream().map(Point::getX).map(i -> (long) (double) i)
|
||||
List<Long> expected = points.stream().map(Point::getX).map(i -> (long) (double) i)
|
||||
.sorted(Long::compare).collect(Collectors.toList());
|
||||
|
||||
points.sort(new PointComparator());
|
||||
|
||||
List<Long> afterSort = points.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
assertEquals(longValues, afterSort);
|
||||
List<Long> result = points.stream().map(Point::getX).map(i -> (long) (double) i).collect(Collectors.toList());
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionDataComparator() {
|
||||
public void sessionDataComparator() {
|
||||
List<Session> sessions = RandomData.randomSessions();
|
||||
|
||||
List<Long> longValues = sessions.stream().map(Session::getSessionStart)
|
||||
List<Long> expected = sessions.stream().map(Session::getSessionStart)
|
||||
.sorted(Long::compare).collect(Collectors.toList());
|
||||
Collections.reverse(expected);
|
||||
|
||||
Collections.reverse(longValues);
|
||||
sessions.sort(new SessionStartComparator());
|
||||
List<Long> afterSort = sessions.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
List<Long> result = sessions.stream().map(Session::getSessionStart).collect(Collectors.toList());
|
||||
|
||||
assertEquals(longValues, afterSort);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTPSComparator() {
|
||||
public void tpsComparator() {
|
||||
List<TPS> tpsList = RandomData.randomTPS();
|
||||
|
||||
List<Long> longValues = tpsList.stream().map(TPS::getDate)
|
||||
List<Long> expected = tpsList.stream().map(TPS::getDate)
|
||||
.sorted(Long::compare).collect(Collectors.toList());
|
||||
|
||||
tpsList.sort(new TPSComparator());
|
||||
List<Long> afterSort = tpsList.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
List<Long> result = tpsList.stream().map(TPS::getDate).collect(Collectors.toList());
|
||||
|
||||
assertEquals(longValues, afterSort);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDataLastPlayedComparator() {
|
||||
public void userDataLastPlayedComparator() {
|
||||
List<UserInfo> userInfo = RandomData.randomUserData();
|
||||
|
||||
List<Long> longValues = userInfo.stream().map(UserInfo::getLastSeen)
|
||||
List<Long> expected = userInfo.stream().map(UserInfo::getLastSeen)
|
||||
.sorted(Long::compare).collect(Collectors.toList());
|
||||
Collections.reverse(expected);
|
||||
|
||||
Collections.reverse(longValues);
|
||||
System.out.println(longValues);
|
||||
userInfo.sort(new UserInfoLastPlayedComparator());
|
||||
List<Long> afterSort = userInfo.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
System.out.println(afterSort);
|
||||
assertEquals(longValues, afterSort);
|
||||
List<Long> result = userInfo.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDataNameComparator() {
|
||||
public void userDataNameComparator() {
|
||||
List<UserInfo> userInfo = RandomData.randomUserData();
|
||||
|
||||
List<String> stringValues = userInfo.stream().map(UserInfo::getName)
|
||||
List<String> expected = userInfo.stream().map(UserInfo::getName)
|
||||
.sorted().collect(Collectors.toList());
|
||||
|
||||
userInfo.sort(new UserInfoNameComparator());
|
||||
List<String> afterSort = userInfo.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
List<String> result = userInfo.stream().map(UserInfo::getName).collect(Collectors.toList());
|
||||
|
||||
assertEquals(stringValues, afterSort);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
public void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
List<WebUser> webUsers = RandomData.randomWebUsers();
|
||||
|
||||
List<Integer> intValues = webUsers.stream().map(WebUser::getPermLevel)
|
||||
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
||||
.sorted(Integer::compare).collect(Collectors.toList());
|
||||
Collections.reverse(intValues);
|
||||
Collections.reverse(expected);
|
||||
|
||||
webUsers.sort(new WebUserComparator());
|
||||
List<Integer> afterSort = webUsers.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
List<Integer> result = webUsers.stream().map(WebUser::getPermLevel).collect(Collectors.toList());
|
||||
|
||||
assertEquals(intValues, afterSort);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringLengthComparator() {
|
||||
List<String> strings = Ordering.from(new StringLengthComparator())
|
||||
.sortedCopy(Arrays.asList(
|
||||
RandomData.randomString(10),
|
||||
RandomData.randomString(3),
|
||||
RandomData.randomString(20),
|
||||
RandomData.randomString(7),
|
||||
RandomData.randomString(4),
|
||||
RandomData.randomString(86),
|
||||
RandomData.randomString(6))
|
||||
);
|
||||
public void stringLengthComparator() {
|
||||
List<Integer> result = Stream.of(
|
||||
RandomData.randomString(10),
|
||||
RandomData.randomString(3),
|
||||
RandomData.randomString(4),
|
||||
RandomData.randomString(20),
|
||||
RandomData.randomString(7),
|
||||
RandomData.randomString(4),
|
||||
RandomData.randomString(86),
|
||||
RandomData.randomString(6)
|
||||
)
|
||||
.sorted(new StringLengthComparator())
|
||||
.map(String::length)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(86, strings.get(0).length());
|
||||
assertEquals(20, strings.get(1).length());
|
||||
assertEquals(3, strings.get(strings.size() - 1).length());
|
||||
List<Integer> expected = Arrays.asList(86, 20, 10, 7, 6, 4, 4, 3);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocaleEntryComparator() {
|
||||
public void localeEntryComparator() {
|
||||
Map<Msg, Message> messageMap = new HashMap<>();
|
||||
messageMap.put(Msg.CMD_CONSTANT_FOOTER, new Message(RandomData.randomString(10)));
|
||||
messageMap.put(Msg.ANALYSIS_3RD_PARTY, new Message(RandomData.randomString(10)));
|
||||
messageMap.put(Msg.MANAGE_FAIL_NO_PLAYERS, new Message(RandomData.randomString(10)));
|
||||
|
||||
List<String> sorted = messageMap.entrySet().stream()
|
||||
List<Msg> result = messageMap.entrySet().stream()
|
||||
.sorted(new LocaleEntryComparator())
|
||||
.map(entry -> entry.getKey().name())
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(Msg.ANALYSIS_3RD_PARTY.name(), sorted.get(0));
|
||||
assertEquals(Msg.CMD_CONSTANT_FOOTER.name(), sorted.get(1));
|
||||
assertEquals(Msg.MANAGE_FAIL_NO_PLAYERS.name(), sorted.get(2));
|
||||
List<Msg> expected = Arrays.asList(
|
||||
Msg.ANALYSIS_3RD_PARTY,
|
||||
Msg.CMD_CONSTANT_FOOTER,
|
||||
Msg.MANAGE_FAIL_NO_PLAYERS
|
||||
);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void geoInfoComparator() {
|
||||
List<GeoInfo> geoInfos = RandomData.randomGeoInfo();
|
||||
|
||||
List<Long> expected = geoInfos.stream().map(GeoInfo::getLastUsed)
|
||||
.sorted(Long::compare).collect(Collectors.toList());
|
||||
Collections.reverse(expected);
|
||||
|
||||
geoInfos.sort(new GeoInfoComparator());
|
||||
List<Long> result = geoInfos.stream().map(GeoInfo::getLastUsed).collect(Collectors.toList());
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package utilities;
|
||||
|
||||
import com.djrapitops.plan.data.WebUser;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.container.UserInfo;
|
||||
@ -74,4 +75,13 @@ public class RandomData {
|
||||
}
|
||||
return test;
|
||||
}
|
||||
|
||||
public static List<GeoInfo> randomGeoInfo() {
|
||||
List<GeoInfo> test = new ArrayList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
GeoInfo geoInfo = new GeoInfo(randomString(10), randomString(10), r.nextLong(), "");
|
||||
test.add(geoInfo);
|
||||
}
|
||||
return test;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user