Sort server list

This commit is contained in:
2024-04-27 01:11:54 -04:00
parent f02f33df10
commit e2872269be

View File

@ -43,6 +43,7 @@ public final class ReadMeManager {
regionCounts.put(server.getRegion(), regionCounts.getOrDefault(server.getRegion(), 0) + 1); regionCounts.put(server.getRegion(), regionCounts.getOrDefault(server.getRegion(), 0) + 1);
} }
contents = contents.replace("<region-table-entry>", regionCounts.entrySet().stream() contents = contents.replace("<region-table-entry>", regionCounts.entrySet().stream()
.sorted((a, b) -> Integer.compare(b.getValue(), a.getValue())) // Sort from highest to lowest
.map(entry -> "| " + StringUtils.capitalizeFully(entry.getKey(), '_') + " | " + entry.getValue() + " |") // Map the region to the count .map(entry -> "| " + StringUtils.capitalizeFully(entry.getKey(), '_') + " | " + entry.getValue() + " |") // Map the region to the count
.reduce((a, b) -> a + "\n" + b).orElse("")); // Reduce the entries to a single string .reduce((a, b) -> a + "\n" + b).orElse("")); // Reduce the entries to a single string