Skip to content

Instantly share code, notes, and snippets.

@natanbc
Last active December 4, 2017 12:04
Show Gist options
  • Save natanbc/de8f7b457b0fed8df8aec353b5416e7b to your computer and use it in GitHub Desktop.
Save natanbc/de8f7b457b0fed8df8aec353b5416e7b to your computer and use it in GitHub Desktop.
DBL lib indexing
public class Main {
public static void main(String[] args) throws Throwable {
DiscordBotsAPI api = new DiscordBotsAPI();
Map<String, Integer> map = api.index().stream().map(BotInfo::getLib).collect(Collectors.groupingBy(
Function.identity(),
Collectors.collectingAndThen(Collectors.counting(), Long::intValue)
));
int total = map.values().stream().mapToInt(Integer::intValue).sum();
System.out.println("Total: " + total);
System.out.println();
map.entrySet().stream().sorted(Comparator.<Map.Entry<String, Integer>>comparingInt(Map.Entry::getValue).reversed()).forEach(entry->{
System.out.println(entry.getKey() + ": " + entry.getValue() + " bots, " + (entry.getValue().doubleValue()/total * 100) + "%");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment