cleanup: prefer List#sort over Collections#sort

This commit is contained in:
P0nk
2021-04-08 07:44:02 +02:00
parent 5730b3b42d
commit ebb3aa7ba3
14 changed files with 28 additions and 24 deletions

View File

@@ -29,7 +29,10 @@ import client.command.Command;
import constants.game.GameConstants; import constants.game.GameConstants;
import server.maps.*; import server.maps.*;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class GotoCommand extends Command { public class GotoCommand extends Command {
@@ -65,7 +68,7 @@ public class GotoCommand extends Command {
public static String GOTO_AREAS_INFO = ""; public static String GOTO_AREAS_INFO = "";
private static void sortGotoEntries(List<Entry<String, Integer>> listEntries) { private static void sortGotoEntries(List<Entry<String, Integer>> listEntries) {
Collections.sort(listEntries, (e1, e2) -> e1.getValue().compareTo(e2.getValue())); listEntries.sort((e1, e2) -> e1.getValue().compareTo(e2.getValue()));
} }
@Override @Override

View File

@@ -188,7 +188,7 @@ public class MapleInventory implements Iterable<Item> {
} }
if (ret.size() > 1) { if (ret.size() > 1) {
Collections.sort(ret, (i1, i2) -> i1.getPosition() - i2.getPosition()); ret.sort((i1, i2) -> i1.getPosition() - i2.getPosition());
} }
return ret; return ret;
@@ -203,7 +203,7 @@ public class MapleInventory implements Iterable<Item> {
} }
if (ret.size() > 1) { if (ret.size() > 1) {
Collections.sort(ret, (i1, i2) -> i1.getPosition() - i2.getPosition()); ret.sort((i1, i2) -> i1.getPosition() - i2.getPosition());
} }
return ret; return ret;

View File

@@ -92,9 +92,9 @@ public class AssignAPProcessor {
statUpdate[2] = chr.getLuk(); statUpdate[2] = chr.getLuk();
statUpdate[3] = chr.getInt(); statUpdate[3] = chr.getInt();
Collections.sort(eqpStrList, Collections.reverseOrder()); eqpStrList.sort(Collections.reverseOrder());
Collections.sort(eqpDexList, Collections.reverseOrder()); eqpDexList.sort(Collections.reverseOrder());
Collections.sort(eqpLukList, Collections.reverseOrder()); eqpLukList.sort(Collections.reverseOrder());
//Autoassigner looks up the 1st/2nd placed equips for their stats to calculate the optimal upgrade. //Autoassigner looks up the 1st/2nd placed equips for their stats to calculate the optimal upgrade.
int eqpStr = getNthHighestStat(eqpStrList, (short) 0) + getNthHighestStat(eqpStrList, (short) 1); int eqpStr = getNthHighestStat(eqpStrList, (short) 0) + getNthHighestStat(eqpStrList, (short) 1);

View File

@@ -451,7 +451,7 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
timedBuffs.add(new Pair<>(curtime - pb.usedTime, pb)); timedBuffs.add(new Pair<>(curtime - pb.usedTime, pb));
} }
Collections.sort(timedBuffs, (p1, p2) -> p1.getLeft().compareTo(p2.getLeft())); timedBuffs.sort((p1, p2) -> p1.getLeft().compareTo(p2.getLeft()));
return timedBuffs; return timedBuffs;
} }

View File

@@ -82,7 +82,7 @@ public class PartySearchStorage {
pscList.add(new PartySearchCharacter(chr)); pscList.add(new PartySearchCharacter(chr));
} }
Collections.sort(pscList, (c1, c2) -> { pscList.sort((c1, c2) -> {
int levelP1 = c1.getLevel(), levelP2 = c2.getLevel(); int levelP1 = c1.getLevel(), levelP2 = c2.getLevel();
return levelP1 > levelP2 ? 1 : (levelP1 == levelP2 ? 0 : -1); return levelP1 > levelP2 ? 1 : (levelP1 == levelP2 ? 0 : -1);
}); });

View File

@@ -579,7 +579,7 @@ public class MapleSessionCoordinator {
public void printSessionTrace() { public void printSessionTrace() {
if (!onlineClients.isEmpty()) { if (!onlineClients.isEmpty()) {
List<Entry<Integer, MapleClient>> elist = new ArrayList<>(onlineClients.entrySet()); List<Entry<Integer, MapleClient>> elist = new ArrayList<>(onlineClients.entrySet());
Collections.sort(elist, (e1, e2) -> e1.getKey().compareTo(e2.getKey())); elist.sort((e1, e2) -> e1.getKey().compareTo(e2.getKey()));
System.out.println("Current online clients: "); System.out.println("Current online clients: ");
for (Entry<Integer, MapleClient> e : elist) { for (Entry<Integer, MapleClient> e : elist) {
@@ -600,7 +600,7 @@ public class MapleSessionCoordinator {
if (!loginRemoteHosts.isEmpty()) { if (!loginRemoteHosts.isEmpty()) {
List<Entry<String, Set<IoSession>>> elist = new ArrayList<>(loginRemoteHosts.entrySet()); List<Entry<String, Set<IoSession>>> elist = new ArrayList<>(loginRemoteHosts.entrySet());
Collections.sort(elist, (e1, e2) -> e1.getKey().compareTo(e2.getKey())); elist.sort((e1, e2) -> e1.getKey().compareTo(e2.getKey()));
System.out.println("Current login sessions: "); System.out.println("Current login sessions: ");
for (Entry<String, Set<IoSession>> e : elist) { for (Entry<String, Set<IoSession>> e : elist) {
@@ -614,7 +614,7 @@ public class MapleSessionCoordinator {
if (!onlineClients.isEmpty()) { if (!onlineClients.isEmpty()) {
List<Entry<Integer, MapleClient>> elist = new ArrayList<>(onlineClients.entrySet()); List<Entry<Integer, MapleClient>> elist = new ArrayList<>(onlineClients.entrySet());
Collections.sort(elist, (e1, e2) -> e1.getKey().compareTo(e2.getKey())); elist.sort((e1, e2) -> e1.getKey().compareTo(e2.getKey()));
str += ("Current online clients:\r\n"); str += ("Current online clients:\r\n");
for (Entry<Integer, MapleClient> e : elist) { for (Entry<Integer, MapleClient> e : elist) {
@@ -635,7 +635,7 @@ public class MapleSessionCoordinator {
if (!loginRemoteHosts.isEmpty()) { if (!loginRemoteHosts.isEmpty()) {
List<Entry<String, Set<IoSession>>> elist = new ArrayList<>(loginRemoteHosts.entrySet()); List<Entry<String, Set<IoSession>>> elist = new ArrayList<>(loginRemoteHosts.entrySet());
Collections.sort(elist, (e1, e2) -> e1.getKey().compareTo(e2.getKey())); elist.sort((e1, e2) -> e1.getKey().compareTo(e2.getKey()));
str += ("Current login sessions:\r\n"); str += ("Current login sessions:\r\n");
for (Entry<String, Set<IoSession>> e : elist) { for (Entry<String, Set<IoSession>> e : elist) {

View File

@@ -234,7 +234,7 @@ public class MapleMonsterAggroCoordinator {
if (!toRemoveIdx.isEmpty()) { if (!toRemoveIdx.isEmpty()) {
// last to first indexes // last to first indexes
Collections.sort(toRemoveIdx, (p1, p2) -> p1 < p2 ? 1 : p1.equals(p2) ? 0 : -1); toRemoveIdx.sort((p1, p2) -> p1 < p2 ? 1 : p1.equals(p2) ? 0 : -1);
for (int idx : toRemoveIdx) { for (int idx : toRemoveIdx) {
sortedAggro.remove(idx); sortedAggro.remove(idx);

View File

@@ -211,7 +211,7 @@ public class MapleParty {
lock.unlock(); lock.unlock();
} }
Collections.sort(histList, (o1, o2) -> (o1.getValue()).compareTo(o2.getValue())); histList.sort((o1, o2) -> (o1.getValue()).compareTo(o2.getValue()));
List<Integer> histSort = new LinkedList<>(); List<Integer> histSort = new LinkedList<>();
for (Entry<Integer, Integer> e : histList) { for (Entry<Integer, Integer> e : histList) {

View File

@@ -461,7 +461,7 @@ public class World {
list.add(e); list.add(e);
} }
Collections.sort(list, (o1, o2) -> o1.getKey() - o2.getKey()); list.sort((o1, o2) -> o1.getKey() - o2.getKey());
return list; return list;
} }
@@ -1844,7 +1844,7 @@ public class World {
} }
} }
Collections.sort(hmsAvailable, (p1, p2) -> p1.getLeft().getPrice() - p2.getLeft().getPrice()); hmsAvailable.sort((p1, p2) -> p1.getLeft().getPrice() - p2.getLeft().getPrice());
hmsAvailable.subList(0, Math.min(hmsAvailable.size(), 200)); //truncates the list to have up to 200 elements hmsAvailable.subList(0, Math.min(hmsAvailable.size(), 200)); //truncates the list to have up to 200 elements
return hmsAvailable; return hmsAvailable;

View File

@@ -233,7 +233,7 @@ public class MapleStorage {
lock.lock(); lock.lock();
try { try {
Collections.sort(items, (o1, o2) -> { items.sort((o1, o2) -> {
if (o1.getInventoryType().getType() < o2.getInventoryType().getType()) { if (o1.getInventoryType().getType() < o2.getInventoryType().getType()) {
return -1; return -1;
} else if (o1.getInventoryType() == o2.getInventoryType()) { } else if (o1.getInventoryType() == o2.getInventoryType()) {

View File

@@ -31,7 +31,6 @@ import tools.MaplePacketCreator;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@@ -92,7 +91,7 @@ public class MaplePlayerNPCPodium {
playerNpcs.add((MaplePlayerNPC) mmo); playerNpcs.add((MaplePlayerNPC) mmo);
} }
Collections.sort(playerNpcs, (p1, p2) -> { playerNpcs.sort((p1, p2) -> {
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history
}); });

View File

@@ -29,8 +29,10 @@ import server.maps.MapleMapObjectType;
import tools.MaplePacketCreator; import tools.MaplePacketCreator;
import java.awt.*; import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.*;
/** /**
* *
@@ -141,7 +143,7 @@ public class MaplePlayerNPCPositioner {
playerNpcs.add((MaplePlayerNPC) mmo); playerNpcs.add((MaplePlayerNPC) mmo);
} }
Collections.sort(playerNpcs, (p1, p2) -> { playerNpcs.sort((p1, p2) -> {
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history
}); });

View File

@@ -79,7 +79,7 @@ public class ItemAction extends MapleQuestAction {
items.add(new ItemData(Integer.parseInt(iEntry.getName()), id, count, prop, job, gender, period)); items.add(new ItemData(Integer.parseInt(iEntry.getName()), id, count, prop, job, gender, period));
} }
Collections.sort(items, (o1, o2) -> o1.map - o2.map); items.sort((o1, o2) -> o1.map - o2.map);
} }
@Override @Override

View File

@@ -986,7 +986,7 @@ public class MaplePacketCreator {
} }
List<Pair<MapleStat, Integer>> mystats = stats; List<Pair<MapleStat, Integer>> mystats = stats;
if (mystats.size() > 1) { if (mystats.size() > 1) {
Collections.sort(mystats, (o1, o2) -> { mystats.sort((o1, o2) -> {
int val1 = o1.getLeft().getValue(); int val1 = o1.getLeft().getValue();
int val2 = o2.getLeft().getValue(); int val2 = o2.getLeft().getValue();
return (val1 < val2 ? -1 : (val1 == val2 ? 0 : 1)); return (val1 < val2 ? -1 : (val1 == val2 ? 0 : 1));