I have a combination of querying a database with jooq and then processing the result with threads. However, I feel that my code is not very readable and not concise enough. How can I improve my code to better express my intentions.
sql .select(field("USER_NAME", String.class)) .from(table("CWD_USER")) .fetch() .stream() .map(f -> f.getValue(field("USER_NAME", String.class))) .collect(Collectors.groupingBy(s -> StringUtils.split(s, "-")[0], Collectors.counting())) .entrySet().stream() .sorted(new java.util.Comparator<Entry<String, Long>>() { @Override public int compare(Entry<String, Long> o1, Entry<String, Long> o2) { return o2.getValue().compareTo(o1.getValue()); } }) .forEach(e -> System.out.println(String.format("%13s: %3d", e.getKey(), e.getValue())));
At first I have problems with multiple threads. First I pass the result from jooq and then I pass the assembled map. Also the comparator seems capable of being noticeable. Of course, I could make a class out of this, but maybe there is another solution.
source share