P11 { public static <T> List<Object> encode_modified(List<T> list) { return P09.pack(list).stream().map(l -> { if (l.size() == 1) { return l.get(0); } return new SimpleEntry<>(l.size(), l.get(0)); }).collect(toList()); }  static List<Object> encode_modified(List<T> list);  }
@Test public void shouldEncodeAList() throws Exception { List<Object> encodedList = P11.encode_modified(Arrays.asList("a", "a", "a", "a", "b", "c", "c", "a", "a", "d", "e", "e", "e", "e")); assertThat(encodedList, hasSize(6)); assertThat(encodedList.get(0), is(equalTo(new SimpleEntry<>(4, "a")))); assertThat(encodedList.get(1), is(equalTo("b"))); assertThat(encodedList.get(2), is(equalTo(new SimpleEntry<>(2, "c")))); assertThat(encodedList.get(3), is(equalTo(new SimpleEntry<>(2, "a")))); assertThat(encodedList.get(4), is(equalTo("d"))); assertThat(encodedList.get(5), is(equalTo(new SimpleEntry<>(4, "e")))); }