String (ObjectIntMap<String> fileMap, int iteration) { long[] stops = {1, 2, 3, 5, 10, 20, 30, 50, 100, 200, Long.MAX_VALUE}; int[] histogram = new int[stops.length]; for (ObjectIntMap.Entry<String> entry : fileMap.entries()) { int count = entry.getValue(); int pos = Arrays.binarySearch(stops, count); if (pos < 0) { pos = -pos - 1; } histogram[pos]++; } StringBuilder report = new StringBuilder(); for (int i = 0; i < stops.length; i++) { String range = i == 0 || stops[i - 1] == stops[i] - 1 ? String.valueOf(stops[i]) : (stops[i - 1] + 1) + (stops[i] == Long.MAX_VALUE ? "+" : ".."+stops[i]); report.append(String.format(Locale.ENGLISH, "%s: %-5d| ", range, histogram[i])); } return String.format(Locale.ENGLISH, "#%-5d: sum = %5d [%s]", iteration, Arrays.stream(histogram).sum(), report.toString().replaceFirst("[\\s|]+$", "")); }