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);  }
@Test public void shouldDisplayNonRangedNumbersAsSeperateEntities() throws Exception { assertEquals("1, 3, 5", prettyPrinter.format(Arrays.asList(1L, 3L, 5L))); }
@Test public void shouldDisplayARangeAsSuch() throws Exception { assertEquals("1..5", prettyPrinter.format(Arrays.asList(1L, 2L, 3L, 4L, 5L))); }
@Test public void rangesOfTwoAreNotDisplayedAsARange() throws Exception { assertEquals("1, 2", prettyPrinter.format(Arrays.asList(1L, 2L))); }
@Test public void shouldReturnNoneWithAnEmptyList() throws Exception { assertEquals("(none)", prettyPrinter.format(new ArrayList<Long>())); }
@Test public void canDealWithMixtureOfRangesAndNonRanges() throws Exception { assertEquals("1, 2, 4, 7..10, 12", prettyPrinter.format(Arrays.asList(1L, 2L, 4L, 7L, 8L, 9L, 10L, 12L))); }