mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-10 18:37:57 +01:00
Further migration to Java 8 and more things
1. Replace unnecessary statement lambda to expression lambda (without the {} when only one expression is present) 2. Change map.get(i) == null ... to map.computeIfAbsent 3. Simplifies comparators
This commit is contained in:
parent
cb860d16f4
commit
8a90f60142
@ -90,9 +90,7 @@ public class ManageImportCommand extends SubCommand {
|
||||
|
||||
private void list(Map<String, Importer> importers, ISender sender) {
|
||||
sender.sendMessage(Phrase.CMD_FOOTER.parse());
|
||||
importers.entrySet().stream().forEach(e -> {
|
||||
sender.sendMessage(Phrase.CMD_BALL + " " + e.getKey() + ": " + e.getValue().getInfo());
|
||||
});
|
||||
importers.entrySet().stream().forEach(e -> sender.sendMessage(Phrase.CMD_BALL + " " + e.getKey() + ": " + e.getValue().getInfo()));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER.parse());
|
||||
}
|
||||
}
|
||||
|
@ -379,9 +379,7 @@ public class DataCacheHandler extends SessionCache {
|
||||
*/
|
||||
public void saveHandlerDataToCache() {
|
||||
final List<IPlayer> onlinePlayers = plugin.fetch().getOnlinePlayers();
|
||||
onlinePlayers.stream().forEach((p) -> {
|
||||
saveHandlerDataToCache(p, false);
|
||||
});
|
||||
onlinePlayers.stream().forEach((p) -> saveHandlerDataToCache(p, false));
|
||||
}
|
||||
|
||||
private void saveHandlerDataToCache(IPlayer player, boolean pool) {
|
||||
|
@ -327,9 +327,7 @@ public abstract class SQLDB extends Database {
|
||||
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
||||
data.addSessions(sessions);
|
||||
data.setPlayerKills(killsTable.getPlayerKills(userId));
|
||||
processors.stream().forEach((processor) -> {
|
||||
processor.process(data);
|
||||
});
|
||||
processors.stream().forEach((processor) -> processor.process(data));
|
||||
Benchmark.stop("Database: Give userdata to processors");
|
||||
setAvailable();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.utilities.comparators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,10 +20,8 @@ public class MapComparator {
|
||||
*/
|
||||
public static List<String[]> sortByValue(Map<String, Integer> hashMap) {
|
||||
List<String[]> sortedList = new ArrayList<>();
|
||||
hashMap.keySet().stream().forEach((key) -> {
|
||||
sortedList.add(new String[]{"" + hashMap.get(key), key});
|
||||
});
|
||||
sortedList.sort((String[] strings, String[] otherStrings) -> Integer.parseInt(strings[0]) - (Integer.parseInt(otherStrings[0])));
|
||||
hashMap.keySet().stream().forEach((key) -> sortedList.add(new String[]{"" + hashMap.get(key), key}));
|
||||
sortedList.sort(Comparator.comparingInt(strings -> Integer.parseInt(strings[0])));
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
@ -34,10 +32,8 @@ public class MapComparator {
|
||||
*/
|
||||
public static List<String[]> sortByValueLong(Map<String, Long> hashMap) {
|
||||
List<String[]> sortedList = new ArrayList<>();
|
||||
hashMap.keySet().stream().forEach((key) -> {
|
||||
sortedList.add(new String[]{"" + hashMap.get(key), key});
|
||||
});
|
||||
sortedList.sort((String[] strings, String[] otherStrings) -> Long.valueOf(strings[0]).compareTo(Long.valueOf(otherStrings[0])));
|
||||
hashMap.keySet().stream().forEach((key) -> sortedList.add(new String[]{"" + hashMap.get(key), key}));
|
||||
sortedList.sort(Comparator.comparing(strings -> Long.valueOf(strings[0])));
|
||||
return sortedList;
|
||||
}
|
||||
|
||||
|
@ -5,16 +5,18 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.database;
|
||||
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import main.java.com.djrapitops.plan.database.Container;
|
||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||
import org.junit.After;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -61,9 +63,7 @@ public class DBUtilsTest {
|
||||
Map<Integer, List<Integer>> map = new HashMap<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 300; j++) {
|
||||
if (map.get(i) == null) {
|
||||
map.put(i, new ArrayList<>());
|
||||
}
|
||||
map.computeIfAbsent(i, k -> new ArrayList<>());
|
||||
map.get(i).add(j);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user