Untitled
unknown
java
a year ago
1.5 kB
8
Indexable
public List<Pair<String, Integer>> getTop(Stat stat) {
Validate.isTrue(isConnected());
MongoDatabase database = client.getDatabase(databaseName);
MongoCollection<Document> collection = database.getCollection("stats");
List<Pair<String, Integer>> list = new ArrayList<>();
try (MongoCursor<Document> iterator = collection.find().iterator()) {
while (iterator.hasNext()) {
Document doc = iterator.next();
String[] groups = {"SOLO", "DOUBLES", "TRIO", "SQUAD", "FOUR_VS_FOUR"};
List<List<Integer>> dataLists = Arrays.stream(groups)
.map(group -> doc.getList("data_" + group, Integer.class, Stat.DEFAULTS))
.toList();
Integer data = IntStream.range(0, Stat.DEFAULTS.size())
.map(j -> dataLists.stream().mapToInt(subList -> subList.get(j)).sum())
.boxed()
.toList()
.get(stat.getIndex());
list.add(new Pair<>(doc.getString("username_case_sensitive"), stat == Stat.LEVEL ? Stat.getLevel(data) : data));
}
} catch (Exception e) {
e.printStackTrace();
}
while (list.size() < 20) {
list.add(new Pair<>("None", 0));
}
list.sort(Comparator.comparingInt(pair -> -pair.value()));
return list.subList(0, 12);
}Editor is loading...
Leave a Comment