@Test public void shouldDisplayNonRangedNumbersAsSeperateEntities() throws Exception { assertEquals("1, 3, 5", prettyPrinter.format(Arrays.asList(1L, 3L, 5L))); }
public String format(List<Long> appliedChanges) { if (appliedChanges.isEmpty()) { return "(none)"; } StringBuilder builder = new StringBuilder(); Long lastRangeStart = null; Long lastNumber = null; for (Long thisNumber : appliedChanges) { if (lastNumber == null) { lastNumber = thisNumber; lastRangeStart = thisNumber; } else if (thisNumber == lastNumber + 1) { lastNumber = thisNumber; } else { appendRange(builder, lastRangeStart, lastNumber); lastNumber = thisNumber; lastRangeStart = thisNumber; } } appendRange(builder, lastRangeStart, lastNumber); return builder.toString(); }
PrettyPrinter { public String format(List<Long> appliedChanges) { if (appliedChanges.isEmpty()) { return "(none)"; } StringBuilder builder = new StringBuilder(); Long lastRangeStart = null; Long lastNumber = null; for (Long thisNumber : appliedChanges) { if (lastNumber == null) { lastNumber = thisNumber; lastRangeStart = thisNumber; } else if (thisNumber == lastNumber + 1) { lastNumber = thisNumber; } else { appendRange(builder, lastRangeStart, lastNumber); lastNumber = thisNumber; lastRangeStart = thisNumber; } } appendRange(builder, lastRangeStart, lastNumber); return builder.toString(); } }
PrettyPrinter { public String format(List<Long> appliedChanges) { if (appliedChanges.isEmpty()) { return "(none)"; } StringBuilder builder = new StringBuilder(); Long lastRangeStart = null; Long lastNumber = null; for (Long thisNumber : appliedChanges) { if (lastNumber == null) { lastNumber = thisNumber; lastRangeStart = thisNumber; } else if (thisNumber == lastNumber + 1) { lastNumber = thisNumber; } else { appendRange(builder, lastRangeStart, lastNumber); lastNumber = thisNumber; lastRangeStart = thisNumber; } } appendRange(builder, lastRangeStart, lastNumber); return builder.toString(); }  }
PrettyPrinter { public String format(List<Long> appliedChanges) { if (appliedChanges.isEmpty()) { return "(none)"; } StringBuilder builder = new StringBuilder(); Long lastRangeStart = null; Long lastNumber = null; for (Long thisNumber : appliedChanges) { if (lastNumber == null) { lastNumber = thisNumber; lastRangeStart = thisNumber; } else if (thisNumber == lastNumber + 1) { lastNumber = thisNumber; } else { appendRange(builder, lastRangeStart, lastNumber); lastNumber = thisNumber; lastRangeStart = thisNumber; } } appendRange(builder, lastRangeStart, lastNumber); return builder.toString(); }  String format(List<Long> appliedChanges); String formatChangeScriptList(List<ChangeScript> changeScripts); }
PrettyPrinter { public String format(List<Long> appliedChanges) { if (appliedChanges.isEmpty()) { return "(none)"; } StringBuilder builder = new StringBuilder(); Long lastRangeStart = null; Long lastNumber = null; for (Long thisNumber : appliedChanges) { if (lastNumber == null) { lastNumber = thisNumber; lastRangeStart = thisNumber; } else if (thisNumber == lastNumber + 1) { lastNumber = thisNumber; } else { appendRange(builder, lastRangeStart, lastNumber); lastNumber = thisNumber; lastRangeStart = thisNumber; } } appendRange(builder, lastRangeStart, lastNumber); return builder.toString(); }  String format(List<Long> appliedChanges); String formatChangeScriptList(List<ChangeScript> changeScripts);  }