@Test public void summarizeLimitsLargeLists() { List<ErrorRecordBase> errs = IntStream.range(0, 100) .boxed() .map(i -> new ErrorRecordBase(String.format("error # %d", i), i, true)) .collect(Collectors.toList()); String result = ErrorRecordsException.summarize(errs); Assert.assertEquals("wrong number of summary entries", ErrorRecordsException.MAX_NUM_ERRORS_IN_SUMMARY, result.split(ErrorRecordsException.ERROR_SUMMARY_ITEM_DELIM).length); Assert.assertTrue(String.format("result had wrong ending: %s", result), result.endsWith("for brevity")); }
static String summarize(List<ErrorRecordBase> errorRecords) { List<String> lines = errorRecords .stream() .collect(Collectors.groupingBy(ErrorRecordBase::getMessage)) .entrySet() .stream() .sorted(Comparator.comparingInt(a -> -a.getValue().size())) .map(entry -> String.format("%s - %d rows", entry.getKey(), entry.getValue().size())) .collect(Collectors.toList()); if (lines.size() > MAX_NUM_ERRORS_IN_SUMMARY) { lines = lines.subList(0, MAX_NUM_ERRORS_IN_SUMMARY - 1); lines.add("... and other errors hidden for brevity"); } return String.join(ERROR_SUMMARY_ITEM_DELIM, lines); }
ErrorRecordsException extends RuntimeException { static String summarize(List<ErrorRecordBase> errorRecords) { List<String> lines = errorRecords .stream() .collect(Collectors.groupingBy(ErrorRecordBase::getMessage)) .entrySet() .stream() .sorted(Comparator.comparingInt(a -> -a.getValue().size())) .map(entry -> String.format("%s - %d rows", entry.getKey(), entry.getValue().size())) .collect(Collectors.toList()); if (lines.size() > MAX_NUM_ERRORS_IN_SUMMARY) { lines = lines.subList(0, MAX_NUM_ERRORS_IN_SUMMARY - 1); lines.add("... and other errors hidden for brevity"); } return String.join(ERROR_SUMMARY_ITEM_DELIM, lines); } }
ErrorRecordsException extends RuntimeException { static String summarize(List<ErrorRecordBase> errorRecords) { List<String> lines = errorRecords .stream() .collect(Collectors.groupingBy(ErrorRecordBase::getMessage)) .entrySet() .stream() .sorted(Comparator.comparingInt(a -> -a.getValue().size())) .map(entry -> String.format("%s - %d rows", entry.getKey(), entry.getValue().size())) .collect(Collectors.toList()); if (lines.size() > MAX_NUM_ERRORS_IN_SUMMARY) { lines = lines.subList(0, MAX_NUM_ERRORS_IN_SUMMARY - 1); lines.add("... and other errors hidden for brevity"); } return String.join(ERROR_SUMMARY_ITEM_DELIM, lines); } ErrorRecordsException(List<ErrorRecordBase> errorRecords); }
ErrorRecordsException extends RuntimeException { static String summarize(List<ErrorRecordBase> errorRecords) { List<String> lines = errorRecords .stream() .collect(Collectors.groupingBy(ErrorRecordBase::getMessage)) .entrySet() .stream() .sorted(Comparator.comparingInt(a -> -a.getValue().size())) .map(entry -> String.format("%s - %d rows", entry.getKey(), entry.getValue().size())) .collect(Collectors.toList()); if (lines.size() > MAX_NUM_ERRORS_IN_SUMMARY) { lines = lines.subList(0, MAX_NUM_ERRORS_IN_SUMMARY - 1); lines.add("... and other errors hidden for brevity"); } return String.join(ERROR_SUMMARY_ITEM_DELIM, lines); } ErrorRecordsException(List<ErrorRecordBase> errorRecords); List<ErrorRecordBase> getErrorRecords(); }
ErrorRecordsException extends RuntimeException { static String summarize(List<ErrorRecordBase> errorRecords) { List<String> lines = errorRecords .stream() .collect(Collectors.groupingBy(ErrorRecordBase::getMessage)) .entrySet() .stream() .sorted(Comparator.comparingInt(a -> -a.getValue().size())) .map(entry -> String.format("%s - %d rows", entry.getKey(), entry.getValue().size())) .collect(Collectors.toList()); if (lines.size() > MAX_NUM_ERRORS_IN_SUMMARY) { lines = lines.subList(0, MAX_NUM_ERRORS_IN_SUMMARY - 1); lines.add("... and other errors hidden for brevity"); } return String.join(ERROR_SUMMARY_ITEM_DELIM, lines); } ErrorRecordsException(List<ErrorRecordBase> errorRecords); List<ErrorRecordBase> getErrorRecords();  }