P12 { public static <T> List<T> decode(List<Object> encoded) { return encoded.stream().flatMap(e -> { if (e instanceof SimpleEntry) { SimpleEntry<Integer, T> entry = (SimpleEntry<Integer, T>) e; return Collections.nCopies(entry.getKey(), entry.getValue()).stream(); } return Stream.of((T) e); }).collect(toList()); }  static List<T> decode(List<Object> encoded);  }
@Test public void shouldDecodeEncodedList() throws Exception { List<String> encoded = P12.decode( Arrays.asList( new SimpleEntry<>(4, "a"), "b", new SimpleEntry<>(2, "c"), new SimpleEntry<>(2, "a"), "d", new SimpleEntry<>(4, "e"))); assertThat(encoded, hasSize(14)); }